@@ -50,7 +50,7 @@ void DeleteDirectory()
5050
5151 [ TestCase ( "\n " ) ]
5252 [ TestCase ( "\r \n " ) ]
53- public async Task Should_Format_Basic_File ( string lineEnding )
53+ public async Task Format_Should_Format_Basic_File ( string lineEnding )
5454 {
5555 var formattedContent = "public class ClassName { }" + lineEnding ;
5656 var unformattedContent = $ "public class ClassName {{{lineEnding}{ lineEnding } }}";
@@ -69,7 +69,7 @@ public async Task Should_Format_Basic_File(string lineEnding)
6969
7070 [ TestCase ( "Subdirectory" ) ]
7171 [ TestCase ( "./Subdirectory" ) ]
72- public async Task Should_Format_Subdirectory ( string subdirectory )
72+ public async Task Format_Should_Format_Subdirectory ( string subdirectory )
7373 {
7474 var formattedContent = "public class ClassName { }\n " ;
7575 var unformattedContent = "public class ClassName {\n \n }" ;
@@ -86,7 +86,7 @@ public async Task Should_Format_Subdirectory(string subdirectory)
8686 }
8787
8888 [ Test ]
89- public async Task Should_Respect_Ignore_File_With_Subdirectory_When_DirectorOrFile_Is_Dot ( )
89+ public async Task Format_Should_Respect_Ignore_File_With_Subdirectory_When_DirectorOrFile_Is_Dot ( )
9090 {
9191 var unformattedContent = "public class Unformatted { }" ;
9292 var filePath = "Subdirectory/IgnoredFile.cs" ;
@@ -120,7 +120,7 @@ public async Task Should_Ignore_Special_Case_Files(string path)
120120 }
121121
122122 [ Test ]
123- public async Task Should_Support_Config_Path ( )
123+ public async Task Format_Should_Support_Config_Path ( )
124124 {
125125 const string fileContent = "var myVariable = someLongValue;" ;
126126 var fileName = "TooWide.cs" ;
@@ -137,7 +137,23 @@ public async Task Should_Support_Config_Path()
137137 }
138138
139139 [ Test ]
140- public async Task Should_Return_Error_When_No_DirectoryOrFile_And_Not_Piping_StdIn ( )
140+ public async Task Check_Should_Support_Config_Path ( )
141+ {
142+ const string fileContent = "var myVariable = someLongValue;\n " ;
143+ var fileName = "TooWide.cs" ;
144+ await this . WriteFileAsync ( fileName , fileContent ) ;
145+ await this . WriteFileAsync ( "config/.csharpierrc" , "printWidth: 10" ) ;
146+
147+ var result = await new CsharpierProcess ( )
148+ . WithArguments ( "check --config-path config/.csharpierrc . " )
149+ . ExecuteAsync ( ) ;
150+
151+ result . ExitCode . Should ( ) . Be ( 1 ) ;
152+ result . ErrorOutput . Should ( ) . StartWith ( "Error ./TooWide.cs - Was not formatted." ) ;
153+ }
154+
155+ [ Test ]
156+ public async Task Format_Should_Return_Error_When_No_DirectoryOrFile_And_Not_Piping_StdIn ( )
141157 {
142158 if ( CannotRunTestWithRedirectedInput ( ) )
143159 {
@@ -154,7 +170,7 @@ public async Task Should_Return_Error_When_No_DirectoryOrFile_And_Not_Piping_Std
154170
155171 [ TestCase ( "\n " ) ]
156172 [ TestCase ( "\r \n " ) ]
157- public async Task Should_Format_Piped_File ( string lineEnding )
173+ public async Task Format_Should_Format_Piped_File ( string lineEnding )
158174 {
159175 var formattedContent1 = "public class ClassName1 { }" + lineEnding ;
160176 var unformattedContent1 = $ "public class ClassName1 {{{lineEnding}{ lineEnding } }}";
@@ -169,7 +185,7 @@ public async Task Should_Format_Piped_File(string lineEnding)
169185 }
170186
171187 [ Test ]
172- public async Task Should_Format_Piped_File_With_Config ( )
188+ public async Task Format_Should_Format_Piped_File_With_Config ( )
173189 {
174190 await this . WriteFileAsync ( ".csharpierrc" , "printWidth: 10" ) ;
175191
@@ -186,7 +202,7 @@ public async Task Should_Format_Piped_File_With_Config()
186202 }
187203
188204 [ Test ]
189- public async Task Should_Format_Piped_File_With_EditorConfig ( )
205+ public async Task Format_Should_Format_Piped_File_With_EditorConfig ( )
190206 {
191207 await this . WriteFileAsync (
192208 ".editorconfig" ,
@@ -207,7 +223,7 @@ await this.WriteFileAsync(
207223 }
208224
209225 [ Test ]
210- public async Task Should_Format_Unicode ( )
226+ public async Task Format_Should_Handle_Unicode ( )
211227 {
212228 // use the \u so that we don't accidentally reformat this to be '?'
213229 var unicodeContent = $ "var test = '{ '\u3002 ' } ';\n ";
@@ -225,7 +241,7 @@ public async Task Should_Format_Unicode()
225241 [ TestCase ( "BasicFile.cs" ) ]
226242 [ TestCase ( "./BasicFile.cs" ) ]
227243 [ TestCase ( "/BasicFile.cs" ) ]
228- public async Task Should_Print_NotFound ( string path )
244+ public async Task Format_Should_Print_NotFound ( string path )
229245 {
230246 var result = await new CsharpierProcess ( ) . WithArguments ( $ "format { path } ") . ExecuteAsync ( ) ;
231247
@@ -234,8 +250,20 @@ public async Task Should_Print_NotFound(string path)
234250 result . ExitCode . Should ( ) . Be ( 1 ) ;
235251 }
236252
253+ [ TestCase ( "BasicFile.cs" ) ]
254+ [ TestCase ( "./BasicFile.cs" ) ]
255+ [ TestCase ( "/BasicFile.cs" ) ]
256+ public async Task Check_Should_Print_NotFound ( string path )
257+ {
258+ var result = await new CsharpierProcess ( ) . WithArguments ( $ "check { path } ") . ExecuteAsync ( ) ;
259+
260+ result . Output . Should ( ) . BeEmpty ( ) ;
261+ result . ErrorOutput . Should ( ) . StartWith ( "There was no file or directory found at " + path ) ;
262+ result . ExitCode . Should ( ) . Be ( 1 ) ;
263+ }
264+
237265 [ Test ]
238- public async Task Should_Write_To_StdError_For_Piped_Invalid_File ( )
266+ public async Task Format_Should_Write_To_StdError_For_Piped_Invalid_File ( )
239267 {
240268 const string invalidFile = "public class ClassName { " ;
241269
@@ -250,7 +278,22 @@ public async Task Should_Write_To_StdError_For_Piped_Invalid_File()
250278 }
251279
252280 [ Test ]
253- public async Task With_Check_Should_Write_Unformatted_File ( )
281+ public async Task Check_Should_Write_To_StdError_For_Piped_Invalid_File ( )
282+ {
283+ const string invalidFile = "public class ClassName { " ;
284+
285+ var result = await new CsharpierProcess ( )
286+ . WithArguments ( "check" )
287+ . WithPipedInput ( invalidFile )
288+ . ExecuteAsync ( ) ;
289+
290+ result . Output . Should ( ) . BeEmpty ( ) ;
291+ result . ExitCode . Should ( ) . Be ( 1 ) ;
292+ result . ErrorOutput . Should ( ) . Contain ( "Failed to compile so was not formatted" ) ;
293+ }
294+
295+ [ Test ]
296+ public async Task Check_Should_Write_Unformatted_File ( )
254297 {
255298 var unformattedContent = "public class ClassName1 {\n \n }" ;
256299
@@ -270,7 +313,7 @@ public async Task With_Check_Should_Write_Unformatted_File()
270313 // TODO overrides tests for piping files
271314 [ TestCase ( "\n " ) ]
272315 [ TestCase ( "\r \n " ) ]
273- public async Task Should_Format_Multiple_Piped_Files ( string lineEnding )
316+ public async Task PipeFiles_Should_Format_Multiple_Piped_Files ( string lineEnding )
274317 {
275318 var formattedContent1 = "public class ClassName1 { }" + lineEnding ;
276319 var formattedContent2 = "public class ClassName2 { }" + lineEnding ;
@@ -295,7 +338,10 @@ public async Task Should_Format_Multiple_Piped_Files(string lineEnding)
295338
296339 [ TestCase ( "InvalidFile.cs" , "./InvalidFile.cs" ) ]
297340 [ TestCase ( "./InvalidFile.cs" , "./InvalidFile.cs" ) ]
298- public async Task Should_Write_Error_With_Multiple_Piped_Files ( string input , string output )
341+ public async Task PipeFiles_Should_Write_Error_With_Multiple_Piped_Files (
342+ string input ,
343+ string output
344+ )
299345 {
300346 const string invalidFile = "public class ClassName { " ;
301347
@@ -313,7 +359,7 @@ public async Task Should_Write_Error_With_Multiple_Piped_Files(string input, str
313359 }
314360
315361 [ Test ]
316- public async Task Should_Ignore_Piped_File_With_Multiple_Piped_Files ( )
362+ public async Task PipeFiles_Should_Ignore_Piped_File_With_Multiple_Piped_Files ( )
317363 {
318364 const string ignoredFile = "public class ClassName { }" ;
319365 var fileName = Path . Combine ( testFileDirectory , "Ignored.cs" ) ;
@@ -329,7 +375,7 @@ public async Task Should_Ignore_Piped_File_With_Multiple_Piped_Files()
329375 }
330376
331377 [ Test ]
332- public async Task Should_Support_Config_With_Multiple_Piped_Files ( )
378+ public async Task PipeFiles_Should_Support_Config_With_Multiple_Piped_Files ( )
333379 {
334380 const string fileContent = "var myVariable = someLongValue;" ;
335381 var fileName = Path . Combine ( testFileDirectory , "TooWide.cs" ) ;
@@ -345,7 +391,7 @@ public async Task Should_Support_Config_With_Multiple_Piped_Files()
345391 }
346392
347393 [ Test ]
348- public async Task Should_Support_Override_Config_With_Multiple_Piped_Files ( )
394+ public async Task PipeFiles_Should_Support_Override_Config_With_Multiple_Piped_Files ( )
349395 {
350396 const string fileContent = "var myVariable = someLongValue;" ;
351397 var fileName = Path . Combine ( testFileDirectory , "TooWide.cst" ) ;
@@ -369,7 +415,7 @@ await this.WriteFileAsync(
369415 }
370416
371417 [ Test ]
372- public async Task Should_Not_Fail_On_Empty_File ( )
418+ public async Task Format_Should_Not_Fail_On_Empty_File ( )
373419 {
374420 await this . WriteFileAsync ( "BasicFile.cs" , "" ) ;
375421
@@ -381,7 +427,7 @@ public async Task Should_Not_Fail_On_Empty_File()
381427 }
382428
383429 [ Test ]
384- public async Task Should_Not_Fail_On_Bad_Csproj ( )
430+ public async Task Format_Should_Not_Fail_On_Bad_Csproj ( )
385431 {
386432 await this . WriteFileAsync ( "Empty.csproj" , "" ) ;
387433
@@ -393,7 +439,7 @@ public async Task Should_Not_Fail_On_Bad_Csproj()
393439 }
394440
395441 [ Test ]
396- public async Task Should_Not_Fail_On_Mismatched_MSBuild_With_No_Check ( )
442+ public async Task Format_Should_Not_Fail_On_Mismatched_MSBuild_With_No_Check ( )
397443 {
398444 await this . WriteFileAsync (
399445 "Test.csproj" ,
@@ -414,7 +460,31 @@ await this.WriteFileAsync(
414460 }
415461
416462 [ Test ]
417- public async Task Should_Fail_On_Mismatched_MSBuild ( )
463+ public async Task Check_Should_Not_Fail_On_Mismatched_MSBuild_With_No_Check ( )
464+ {
465+ await this . WriteFileAsync (
466+ "Test.csproj" ,
467+ """
468+ <Project Sdk="Microsoft.NET.Sdk">
469+ <ItemGroup>
470+ <PackageReference Include="CSharpier.MsBuild" Version="99" />
471+ </ItemGroup>
472+ </Project>
473+
474+ """
475+ ) ;
476+
477+ var result = await new CsharpierProcess ( )
478+ . WithArguments ( "check --no-msbuild-check ." )
479+ . ExecuteAsync ( ) ;
480+
481+ result . ErrorOutput . Should ( ) . BeEmpty ( ) ;
482+ result . ExitCode . Should ( ) . Be ( 0 ) ;
483+ result . Output . Should ( ) . StartWith ( "Formatted 1 files in " ) ;
484+ }
485+
486+ [ Test ]
487+ public async Task Format_Should_Fail_On_Mismatched_MSBuild ( )
418488 {
419489 await this . WriteFileAsync (
420490 "Test.csproj" ,
@@ -434,7 +504,27 @@ await this.WriteFileAsync(
434504 }
435505
436506 [ Test ]
437- public async Task Should_Cache_And_Validate_Too_Many_Things ( )
507+ public async Task Check_Should_Fail_On_Mismatched_MSBuild ( )
508+ {
509+ await this . WriteFileAsync (
510+ "Test.csproj" ,
511+ @"<Project Sdk=""Microsoft.NET.Sdk"">
512+ <ItemGroup>
513+ <PackageReference Include=""CSharpier.MsBuild"" Version=""99"" />
514+ </ItemGroup>
515+ </Project>"
516+ ) ;
517+
518+ var result = await new CsharpierProcess ( ) . WithArguments ( "check ." ) . ExecuteAsync ( ) ;
519+
520+ result
521+ . ErrorOutput . Should ( )
522+ . Contain ( "uses version 99 of CSharpier.MsBuild which is a mismatch with version" ) ;
523+ result . ExitCode . Should ( ) . Be ( 1 ) ;
524+ }
525+
526+ [ Test ]
527+ public async Task Format_Should_Cache_And_Validate_Too_Many_Things ( )
438528 {
439529 var unformattedContent = "public class ClassName { }\n " ;
440530 var formattedContent = "public class ClassName { }\n " ;
@@ -457,7 +547,7 @@ public async Task Should_Cache_And_Validate_Too_Many_Things()
457547 }
458548
459549 [ Test ]
460- public async Task Should_Reformat_When_Options_Change_With_Cache ( )
550+ public async Task Format_Should_Reformat_When_Options_Change_With_Cache ( )
461551 {
462552 var unformattedContent = "public class ClassName { \n // break\n }\n " ;
463553
@@ -471,7 +561,7 @@ public async Task Should_Reformat_When_Options_Change_With_Cache()
471561 }
472562
473563 [ Test ]
474- public void Should_Handle_Concurrent_Processes ( )
564+ public void Format_Should_Handle_Concurrent_Processes ( )
475565 {
476566 var unformattedContent = "public class ClassName { }\n " ;
477567 var totalFolders = 10 ;
@@ -509,7 +599,7 @@ async Task FormatFolder(string folder)
509599 [ Ignore (
510600 "This is somewhat useful for testing locally, but doesn't reliably reproduce a problem and takes a while to run. Commenting out the delete cache file line helps to reproduce problems"
511601 ) ]
512- public async Task Should_Handle_Concurrent_Processes_2 ( )
602+ public async Task Format_Should_Handle_Concurrent_Processes_2 ( )
513603 {
514604 var unformattedContent = "public class ClassName { }\n " ;
515605 var filesPerFolder = 1000 ;
0 commit comments