@@ -24,10 +24,28 @@ public void Format_Writes_Failed_To_Compile()
2424
2525 var result = this . Format ( context ) ;
2626
27+ result
28+ . ErrorOutputLines . First ( )
29+ . Should ( )
30+ . Be ( "Error ./Invalid.cs - Failed to compile so was not formatted." ) ;
31+
32+ result . ExitCode . Should ( ) . Be ( 1 ) ;
33+ }
34+
35+ [ Test ]
36+ public void Format_Writes_Failed_To_Compile_As_Warning ( )
37+ {
38+ var context = new TestContext ( ) ;
39+ context . WhenAFileExists ( "Invalid.cs" , "asdfasfasdf" ) ;
40+
41+ var result = this . Format ( context , compilationErrorsAsWarnings : true ) ;
42+
2743 result
2844 . OutputLines . First ( )
2945 . Should ( )
3046 . Be ( "Warning ./Invalid.cs - Failed to compile so was not formatted." ) ;
47+
48+ result . ExitCode . Should ( ) . Be ( 0 ) ;
3149 }
3250
3351 [ Test ]
@@ -39,9 +57,9 @@ public void Format_Writes_Failed_To_Compile_For_Subdirectory()
3957 var result = this . Format ( context , directoryOrFilePaths : "Subdirectory" ) ;
4058
4159 result
42- . OutputLines . First ( )
60+ . ErrorOutputLines . First ( )
4361 . Should ( )
44- . Be ( "Warning ./Subdirectory/Invalid.cs - Failed to compile so was not formatted." ) ;
62+ . Be ( "Error ./Subdirectory/Invalid.cs - Failed to compile so was not formatted." ) ;
4563 }
4664
4765 [ Test ]
@@ -56,10 +74,10 @@ public void Format_Writes_Failed_To_Compile_For_FullPath()
5674 ) ;
5775
5876 result
59- . OutputLines . First ( )
77+ . ErrorOutputLines . First ( )
6078 . Should ( )
6179 . Be (
62- $ "Warning { context . GetRootPath ( ) . Replace ( '\\ ' , '/' ) } /Subdirectory/Invalid.cs - Failed to compile so was not formatted."
80+ $ "Error { context . GetRootPath ( ) . Replace ( '\\ ' , '/' ) } /Subdirectory/Invalid.cs - Failed to compile so was not formatted."
6381 ) ;
6482 }
6583
@@ -72,9 +90,9 @@ public void Format_Writes_Failed_To_Compile_With_Directory()
7290 var result = this . Format ( context ) ;
7391
7492 result
75- . OutputLines . First ( )
93+ . ErrorOutputLines . First ( )
7694 . Should ( )
77- . Be ( "Warning ./Directory/Invalid.cs - Failed to compile so was not formatted." ) ;
95+ . Be ( "Error ./Directory/Invalid.cs - Failed to compile so was not formatted." ) ;
7896 }
7997
8098 [ Test ]
@@ -91,6 +109,7 @@ public void Format_Writes_Unsupported()
91109 . Be ( @"Warning ./Unsupported.js - Is an unsupported file type." ) ;
92110 }
93111
112+ [ Test ]
94113 public void Format_Writes_File_With_Directory_Path ( )
95114 {
96115 var context = new TestContext ( ) ;
@@ -583,9 +602,9 @@ public void File_With_Compilation_Error_Should_Not_Lose_Code()
583602
584603 context . GetFileContent ( "Invalid.cs" ) . Should ( ) . Be ( contents ) ;
585604 result
586- . OutputLines . First ( )
605+ . ErrorOutputLines . First ( )
587606 . Should ( )
588- . Be ( "Warning ./Invalid.cs - Failed to compile so was not formatted." ) ;
607+ . Be ( "Error ./Invalid.cs - Failed to compile so was not formatted." ) ;
589608 }
590609
591610 [ TestCase (
@@ -652,6 +671,7 @@ private FormatResult Format(
652671 bool check = false ,
653672 bool writeStdout = false ,
654673 bool includeGenerated = false ,
674+ bool compilationErrorsAsWarnings = false ,
655675 string ? standardInFileContents = null ,
656676 params string [ ] directoryOrFilePaths
657677 )
@@ -681,7 +701,8 @@ params string[] directoryOrFilePaths
681701 Check = check ,
682702 WriteStdout = writeStdout || standardInFileContents != null ,
683703 StandardInFileContents = standardInFileContents ,
684- IncludeGenerated = includeGenerated
704+ IncludeGenerated = includeGenerated ,
705+ CompilationErrorsAsWarnings = compilationErrorsAsWarnings ,
685706 } ,
686707 context . FileSystem ,
687708 fakeConsole ,
0 commit comments