@@ -38,66 +38,60 @@ public async Task WithNestedNewlineAddedByScrubber()
3838 public Task Newlines ( ) =>
3939 Verify ( "a\r \n b\n c\r d\r \n " ) ;
4040
41- #if NET9_0
4241 [ Fact ]
4342 public async Task StringWithDifferingNewline ( )
4443 {
45- var fullPath = CurrentFile . Relative ( "NewLineTests.StringWithDifferingNewline.verified.txt" ) ;
44+ // This writes verified files into the source directory and mutates them repeatedly,
45+ // so every target framework has to own a distinct set of paths. UniqueForRuntimeAndVersion
46+ // puts the runtime in the name, which is what allows this to run on all of them at once.
47+ var prefix = $ "NewLineTests.StringWithDifferingNewline.{ Namer . RuntimeAndVersion } ";
48+ var verifiedPath = CurrentFile . Relative ( $ "{ prefix } .verified.txt") ;
49+ var receivedPath = CurrentFile . Relative ( $ "{ prefix } .received.txt") ;
4650 // The suggested .gitattributes line uses the extension of the failing file,
4751 // which is not always txt
48- var jsonPath = CurrentFile . Relative ( "NewLineTests.StringWithDifferingNewline.verified.json" ) ;
49- var directory = Path . GetDirectoryName ( fullPath ) ! ;
50- // Globbed because received carries the namer uniqueness suffix, while the verified
51- // files above are the unsuffixed fallback.
52- const string receivedPattern = "NewLineTests.StringWithDifferingNewline*.received.txt" ;
53- const string receivedJsonPattern = "NewLineTests.StringWithDifferingNewline*.received.json" ;
54- File . Delete ( fullPath ) ;
55- File . Delete ( jsonPath ) ;
52+ var verifiedJsonPath = CurrentFile . Relative ( $ "{ prefix } .verified.json") ;
53+ var receivedJsonPath = CurrentFile . Relative ( $ "{ prefix } .received.json") ;
54+ File . Delete ( verifiedPath ) ;
55+ File . Delete ( verifiedJsonPath ) ;
5656 var settings = new VerifySettings ( ) ;
57+ settings . UniqueForRuntimeAndVersion ( ) ;
5758 settings . DisableRequireUniquePrefix ( ) ;
5859 // Every verify below is expected to fail, so without this the diff tool is launched
5960 settings . DisableDiff ( ) ;
6061
6162 try
6263 {
6364 // A verified file containing \r is rejected rather than silently normalized
64- await File . WriteAllTextAsync ( fullPath , "a\r \n b" ) ;
65+ await File . WriteAllTextAsync ( verifiedPath , "a\r \n b" ) ;
6566 var crlf = await Assert . ThrowsAnyAsync < Exception > ( ( ) => Verify ( "a\n b" , settings ) ) ;
6667 Assert . Contains ( "carriage return" , crlf . ToString ( ) ) ;
6768
68- await File . WriteAllTextAsync ( fullPath , "a\r b" ) ;
69+ await File . WriteAllTextAsync ( verifiedPath , "a\r b" ) ;
6970 var cr = await Assert . ThrowsAnyAsync < Exception > ( ( ) => Verify ( "a\n b" , settings ) ) ;
7071 Assert . Contains ( "carriage return" , cr . ToString ( ) ) ;
7172
7273 // The rejection writes received, so the run is not silent, and is not wrapped in a
7374 // generic "Failed to compare files" that hides the cause.
74- foreach ( var stale in Directory . EnumerateFiles ( directory , receivedPattern ) )
75- {
76- File . Delete ( stale ) ;
77- }
75+ File . Delete ( receivedPath ) ;
7876
79- await File . WriteAllTextAsync ( fullPath , "a\r \n b" ) ;
77+ await File . WriteAllTextAsync ( verifiedPath , "a\r \n b" ) ;
8078 var rejection = await Assert . ThrowsAnyAsync < Exception > ( ( ) => Verify ( "a\n b" , settings ) ) ;
8179 Assert . DoesNotContain ( "Failed to compare files" , rejection . Message ) ;
8280 Assert . Contains ( "*.verified.txt text eol=lf" , rejection . Message ) ;
83- var received = Directory . EnumerateFiles ( directory , receivedPattern ) . Single ( ) ;
84- Assert . Equal ( "a\n b" , await File . ReadAllTextAsync ( received ) ) ;
85- File . Delete ( received ) ;
81+ Assert . Equal ( "a\n b" , await File . ReadAllTextAsync ( receivedPath ) ) ;
82+ File . Delete ( receivedPath ) ;
8683
87- await File . WriteAllTextAsync ( jsonPath , "{\r \n }" ) ;
84+ await File . WriteAllTextAsync ( verifiedJsonPath , "{\r \n }" ) ;
8885 var json = await Assert . ThrowsAnyAsync < Exception > (
8986 ( ) => Verify ( "{\n }" , extension : "json" , settings : settings ) ) ;
9087 Assert . Contains ( "*.verified.json text eol=lf" , json . Message ) ;
9188 // Inline, not only in the finally, since the verifies below would otherwise treat
9289 // the json as a dangling verified file for this test and fail on it
93- File . Delete ( jsonPath ) ;
94- foreach ( var stale in Directory . EnumerateFiles ( directory , receivedJsonPattern ) )
95- {
96- File . Delete ( stale ) ;
97- }
90+ File . Delete ( verifiedJsonPath ) ;
91+ File . Delete ( receivedJsonPath ) ;
9892
9993 // A verified file using \n still matches received content normalized to \n
100- await File . WriteAllTextAsync ( fullPath , "a\n b" ) ;
94+ await File . WriteAllTextAsync ( verifiedPath , "a\n b" ) ;
10195 await Verify ( "a\r \n b" , settings ) ;
10296 await Verify ( "a\r b" , settings ) ;
10397 await Verify ( "a\n b" , settings ) ;
@@ -106,13 +100,10 @@ public async Task StringWithDifferingNewline()
106100 {
107101 // In a finally since these deliberately contain \r. A leftover verified file is
108102 // normalized to \n by .gitattributes if committed, silently voiding this test.
109- File . Delete ( fullPath ) ;
110- File . Delete ( jsonPath ) ;
111- foreach ( var stale in Directory . EnumerateFiles ( directory , receivedPattern )
112- . Concat ( Directory . EnumerateFiles ( directory , receivedJsonPattern ) ) )
113- {
114- File . Delete ( stale ) ;
115- }
103+ File . Delete ( verifiedPath ) ;
104+ File . Delete ( receivedPath ) ;
105+ File . Delete ( verifiedJsonPath ) ;
106+ File . Delete ( receivedJsonPath ) ;
116107 }
117108 }
118109
@@ -140,19 +131,16 @@ public async Task StringWithDifferingNewline()
140131 // await Verify(target, settings);
141132 // }
142133
143- #endif
144-
145- #if NET10_0
146134 [ Fact ]
147135 public async Task TrailingNewlinesRaw ( )
148136 {
149- var file = CurrentFile . Relative ( "NewLineTests.TrailingNewlinesRaw.verified.txt" ) ;
150- var directory = Path . GetDirectoryName ( file ) ! ;
151- // Globbed because received carries the namer uniqueness suffix, while the verified
152- // file above is the unsuffixed fallback.
153- const string receivedPattern = "NewLineTests.TrailingNewlinesRaw*.received.txt" ;
137+ // Per target framework paths, for the same reason as StringWithDifferingNewline above
138+ var prefix = $ "NewLineTests.TrailingNewlinesRaw.{ Namer . RuntimeAndVersion } ";
139+ var file = CurrentFile . Relative ( $ "{ prefix } .verified.txt") ;
140+ var receivedPath = CurrentFile . Relative ( $ "{ prefix } .received.txt") ;
154141 File . Delete ( file ) ;
155142 var settings = new VerifySettings ( ) ;
143+ settings . UniqueForRuntimeAndVersion ( ) ;
156144 settings . DisableRequireUniquePrefix ( ) ;
157145 // Several verifies below are expected to fail, so without this the diff tool is launched
158146 settings . DisableDiff ( ) ;
@@ -178,11 +166,7 @@ public async Task TrailingNewlinesRaw()
178166 // Deleting verified orphans received, so no subsequent run reconciles it, and
179167 // DiffEngineTray shows it as a pending change forever.
180168 File . Delete ( file ) ;
181- foreach ( var stale in Directory . EnumerateFiles ( directory , receivedPattern ) )
182- {
183- File . Delete ( stale ) ;
184- }
169+ File . Delete ( receivedPath ) ;
185170 }
186171 }
187- #endif
188172}
0 commit comments