Skip to content

Commit

Permalink
Improve SourceMapTestCase to report errors found during the compilation.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 698864161
  • Loading branch information
12wrigja authored and copybara-github committed Nov 21, 2024
1 parent 6935ae4 commit 2e43d27
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
24 changes: 23 additions & 1 deletion test/com/google/debugging/sourcemap/SourceMapTestCase.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,16 @@
import com.google.common.reflect.TypeToken;
import com.google.debugging.sourcemap.proto.Mapping.OriginalMapping;
import com.google.gson.Gson;
import com.google.javascript.jscomp.CheckLevel;
import com.google.javascript.jscomp.Compiler;
import com.google.javascript.jscomp.CompilerOptions;
import com.google.javascript.jscomp.DiagnosticGroups;
import com.google.javascript.jscomp.JSError;
import com.google.javascript.jscomp.Result;
import com.google.javascript.jscomp.SourceFile;
import com.google.javascript.jscomp.SourceMap;
import com.google.javascript.jscomp.SourceMap.DetailLevel;
import com.google.javascript.jscomp.WarningsGuard;
import java.io.IOException;
import java.lang.reflect.Type;
import java.util.LinkedHashMap;
Expand Down Expand Up @@ -299,7 +303,14 @@ protected RunResult compile(String js1, String fileName1, String js2, String fil

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

assertWithMessage("compilation failed").that(result.success).isTrue();
assertWithMessage("compilation failed with errors")
.that(result.errors)
.isEqualTo(ImmutableList.of());
assertWithMessage("compilation failed with warnings")
.that(result.warnings)
.isEqualTo(ImmutableList.of());

assertWithMessage("compilation failed (other reason)").that(result.success).isTrue();
String source = compiler.toSource();

StringBuilder sb = new StringBuilder();
Expand All @@ -323,6 +334,17 @@ protected CompilerOptions getCompilerOptions() {
options.setSourceMapFormat(getSourceMapFormat());
options.setSourceMapDetailLevel(detailLevel);
options.setSourceMapIncludeSourcesContent(sourceMapIncludeSourcesContent);
options.addWarningsGuard(
new WarningsGuard() {

@Override
public CheckLevel level(JSError error) {
if (DiagnosticGroups.CHECK_USELESS_CODE.matches(error)) {
return CheckLevel.OFF;
}
return null;
}
});
return options;
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
/** @closureUnaware */
/**
* @fileoverview
* @closureUnaware
*/
goog.module('a.b.c');

(function() {
(/** @closureUnaware */ function() {
class ClazzWithStatic {
constructor() {}

Expand Down

0 comments on commit 2e43d27

Please sign in to comment.