@@ -100,7 +100,8 @@ public void hello() throws IOException {
100100 null ,
101101 fileManager ,
102102 diagnosticCollector ,
103- ImmutableList .of ("-Xplugin:ErrorProne" , "-XDcompilePolicy=byfile" ),
103+ ImmutableList .of (
104+ "-Xplugin:ErrorProne" , "-XDcompilePolicy=byfile" , "--should-stop=ifError=FLOW" ),
104105 ImmutableList .of (),
105106 fileManager .getJavaFileObjects (source ));
106107 assertThat (task .call ()).isFalse ();
@@ -144,7 +145,8 @@ public void applyFixes() throws IOException {
144145 ImmutableList .of (
145146 "-Xplugin:ErrorProne"
146147 + " -XepPatchChecks:MissingOverride -XepPatchLocation:IN_PLACE" ,
147- "-XDcompilePolicy=byfile" ),
148+ "-XDcompilePolicy=byfile" ,
149+ "--should-stop=ifError=FLOW" ),
148150 ImmutableList .of (),
149151 fileManager .getJavaFileObjects (fileA , fileB ));
150152 assertWithMessage (Joiner .on ('\n' ).join (diagnosticCollector .getDiagnostics ()))
@@ -203,7 +205,8 @@ public void applyToPatchFile() throws IOException {
203205 "-Xplugin:ErrorProne"
204206 + " -XepPatchChecks:MissingOverride -XepPatchLocation:"
205207 + patchDir ,
206- "-XDcompilePolicy=byfile" ),
208+ "-XDcompilePolicy=byfile" ,
209+ "--should-stop=ifError=FLOW" ),
207210 ImmutableList .of (),
208211 fileManager .getJavaFileObjects (fileA , fileB ));
209212 assertWithMessage (Joiner .on ('\n' ).join (diagnosticCollector .getDiagnostics ()))
@@ -254,7 +257,8 @@ public void explicitBadPolicyGiven() throws IOException {
254257 new PrintWriter (sw , true ),
255258 fileManager ,
256259 diagnosticCollector ,
257- ImmutableList .of ("-XDcompilePolicy=bytodo" , "-Xplugin:ErrorProne" ),
260+ ImmutableList .of (
261+ "-XDcompilePolicy=bytodo" , "--should-stop=ifError=FLOW" , "-Xplugin:ErrorProne" ),
258262 ImmutableList .of (),
259263 fileManager .getJavaFileObjects (source ));
260264 RuntimeException expected = assertThrows (RuntimeException .class , () -> task .call ());
@@ -375,7 +379,8 @@ public void compilesWithFix() throws IOException {
375379 diagnosticCollector ,
376380 ImmutableList .of (
377381 "-Xplugin:ErrorProne -XepDisableAllChecks -Xep:TestCompilesWithFix:ERROR" ,
378- "-XDcompilePolicy=byfile" ),
382+ "-XDcompilePolicy=byfile" ,
383+ "--should-stop=ifError=FLOW" ),
379384 ImmutableList .of (),
380385 fileManager .getJavaFileObjects (source ));
381386 assertThat (task .call ()).isFalse ();
@@ -385,4 +390,49 @@ public void compilesWithFix() throws IOException {
385390 .collect (onlyElement ());
386391 assertThat (diagnostic .getMessage (ENGLISH )).contains ("[TestCompilesWithFix]" );
387392 }
393+
394+ @ Test
395+ public void noShouldStopIfErrorPolicy () throws IOException {
396+ FileSystem fileSystem = Jimfs .newFileSystem (Configuration .unix ());
397+ Path source = fileSystem .getPath ("Test.java" );
398+ Files .writeString (source , "class Test {}" );
399+ JavacFileManager fileManager = new JavacFileManager (new Context (), false , UTF_8 );
400+ DiagnosticCollector <JavaFileObject > diagnosticCollector = new DiagnosticCollector <>();
401+ StringWriter sw = new StringWriter ();
402+ JavacTask task =
403+ JavacTool .create ()
404+ .getTask (
405+ new PrintWriter (sw , true ),
406+ fileManager ,
407+ diagnosticCollector ,
408+ ImmutableList .of ("-Xplugin:ErrorProne" , "-XDcompilePolicy=byfile" ),
409+ ImmutableList .of (),
410+ fileManager .getJavaFileObjects (source ));
411+ RuntimeException expected = assertThrows (RuntimeException .class , task ::call );
412+ assertThat (expected )
413+ .hasMessageThat ()
414+ .contains ("The default --should-stop=ifError policy (INIT) is not supported" );
415+ }
416+
417+ @ Test
418+ public void shouldStopIfErrorPolicyInit () throws IOException {
419+ FileSystem fileSystem = Jimfs .newFileSystem (Configuration .unix ());
420+ Path source = fileSystem .getPath ("Test.java" );
421+ Files .writeString (source , "class Test {}" );
422+ JavacFileManager fileManager = new JavacFileManager (new Context (), false , UTF_8 );
423+ DiagnosticCollector <JavaFileObject > diagnosticCollector = new DiagnosticCollector <>();
424+ StringWriter sw = new StringWriter ();
425+ JavacTask task =
426+ JavacTool .create ()
427+ .getTask (
428+ new PrintWriter (sw , true ),
429+ fileManager ,
430+ diagnosticCollector ,
431+ ImmutableList .of (
432+ "-Xplugin:ErrorProne" , "-XDcompilePolicy=byfile" , "--should-stop=ifError=INIT" ),
433+ ImmutableList .of (),
434+ fileManager .getJavaFileObjects (source ));
435+ RuntimeException expected = assertThrows (RuntimeException .class , task ::call );
436+ assertThat (expected ).hasMessageThat ().contains ("--should-stop=ifError=INIT is not supported" );
437+ }
388438}
0 commit comments