Skip to content

Commit 2e43d27

Browse files
12wrigjacopybara-github
authored andcommitted
Improve SourceMapTestCase to report errors found during the compilation.
PiperOrigin-RevId: 698864161
1 parent 6935ae4 commit 2e43d27

File tree

2 files changed

+28
-3
lines changed

2 files changed

+28
-3
lines changed

test/com/google/debugging/sourcemap/SourceMapTestCase.java

+23-1
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,16 @@
2626
import com.google.common.reflect.TypeToken;
2727
import com.google.debugging.sourcemap.proto.Mapping.OriginalMapping;
2828
import com.google.gson.Gson;
29+
import com.google.javascript.jscomp.CheckLevel;
2930
import com.google.javascript.jscomp.Compiler;
3031
import com.google.javascript.jscomp.CompilerOptions;
32+
import com.google.javascript.jscomp.DiagnosticGroups;
33+
import com.google.javascript.jscomp.JSError;
3134
import com.google.javascript.jscomp.Result;
3235
import com.google.javascript.jscomp.SourceFile;
3336
import com.google.javascript.jscomp.SourceMap;
3437
import com.google.javascript.jscomp.SourceMap.DetailLevel;
38+
import com.google.javascript.jscomp.WarningsGuard;
3539
import java.io.IOException;
3640
import java.lang.reflect.Type;
3741
import java.util.LinkedHashMap;
@@ -299,7 +303,14 @@ protected RunResult compile(String js1, String fileName1, String js2, String fil
299303

300304
Result result = compiler.compile(EXTERNS, inputs, options);
301305

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();
303314
String source = compiler.toSource();
304315

305316
StringBuilder sb = new StringBuilder();
@@ -323,6 +334,17 @@ protected CompilerOptions getCompilerOptions() {
323334
options.setSourceMapFormat(getSourceMapFormat());
324335
options.setSourceMapDetailLevel(detailLevel);
325336
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+
});
326348
return options;
327349
}
328350
}

test/com/google/javascript/jscomp/testdata/SourceMapJsLangTest/closureunawarecode.jsdata

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1-
/** @closureUnaware */
1+
/**
2+
* @fileoverview
3+
* @closureUnaware
4+
*/
25
goog.module('a.b.c');
36

4-
(function() {
7+
(/** @closureUnaware */ function() {
58
class ClazzWithStatic {
69
constructor() {}
710

0 commit comments

Comments
 (0)