26
26
import com .google .common .reflect .TypeToken ;
27
27
import com .google .debugging .sourcemap .proto .Mapping .OriginalMapping ;
28
28
import com .google .gson .Gson ;
29
+ import com .google .javascript .jscomp .CheckLevel ;
29
30
import com .google .javascript .jscomp .Compiler ;
30
31
import com .google .javascript .jscomp .CompilerOptions ;
32
+ import com .google .javascript .jscomp .DiagnosticGroups ;
33
+ import com .google .javascript .jscomp .JSError ;
31
34
import com .google .javascript .jscomp .Result ;
32
35
import com .google .javascript .jscomp .SourceFile ;
33
36
import com .google .javascript .jscomp .SourceMap ;
34
37
import com .google .javascript .jscomp .SourceMap .DetailLevel ;
38
+ import com .google .javascript .jscomp .WarningsGuard ;
35
39
import java .io .IOException ;
36
40
import java .lang .reflect .Type ;
37
41
import java .util .LinkedHashMap ;
@@ -299,7 +303,14 @@ protected RunResult compile(String js1, String fileName1, String js2, String fil
299
303
300
304
Result result = compiler .compile (EXTERNS , inputs , options );
301
305
302
- assertWithMessage ("compilation failed" ).that (result .success ).isTrue ();
306
+ assertWithMessage ("compilation failed with errors" )
307
+ .that (result .errors )
308
+ .isEqualTo (ImmutableList .of ());
309
+ assertWithMessage ("compilation failed with warnings" )
310
+ .that (result .warnings )
311
+ .isEqualTo (ImmutableList .of ());
312
+
313
+ assertWithMessage ("compilation failed (other reason)" ).that (result .success ).isTrue ();
303
314
String source = compiler .toSource ();
304
315
305
316
StringBuilder sb = new StringBuilder ();
@@ -323,6 +334,17 @@ protected CompilerOptions getCompilerOptions() {
323
334
options .setSourceMapFormat (getSourceMapFormat ());
324
335
options .setSourceMapDetailLevel (detailLevel );
325
336
options .setSourceMapIncludeSourcesContent (sourceMapIncludeSourcesContent );
337
+ options .addWarningsGuard (
338
+ new WarningsGuard () {
339
+
340
+ @ Override
341
+ public CheckLevel level (JSError error ) {
342
+ if (DiagnosticGroups .CHECK_USELESS_CODE .matches (error )) {
343
+ return CheckLevel .OFF ;
344
+ }
345
+ return null ;
346
+ }
347
+ });
326
348
return options ;
327
349
}
328
350
}
0 commit comments