Skip to content

Commit

Permalink
Move BlackHoleErrorManager out of the 'testing' package so it can be …
Browse files Browse the repository at this point in the history
…used in production code.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=177651257
  • Loading branch information
tbreisacher authored and blickly committed Dec 4, 2017
1 parent 7b7672a commit ff836ef
Show file tree
Hide file tree
Showing 6 changed files with 6 additions and 26 deletions.
Expand Up @@ -13,24 +13,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.javascript.jscomp.testing;

import com.google.javascript.jscomp.BasicErrorManager;
import com.google.javascript.jscomp.CheckLevel;
import com.google.javascript.jscomp.Compiler;
import com.google.javascript.jscomp.JSError;
package com.google.javascript.jscomp;

/** An ErrorManager that silently swallows all messages. */
public final class BlackHoleErrorManager extends BasicErrorManager {

/**
* {@link Compiler} prints to the console by default. This method silences
* it to avoid spamming the console in tests.
*/
public static void silence(Compiler compiler) {
compiler.setErrorManager(new BlackHoleErrorManager());
}

@Override
public void println(CheckLevel level, JSError error) { /* no-op */ }

Expand Down
Expand Up @@ -23,7 +23,6 @@
import com.google.javascript.jscomp.CompilerOptions.LanguageMode;
import com.google.javascript.jscomp.ConformanceRules.AbstractRule;
import com.google.javascript.jscomp.ConformanceRules.ConformanceResult;
import com.google.javascript.jscomp.testing.BlackHoleErrorManager;
import com.google.javascript.rhino.Node;
import com.google.protobuf.TextFormat;
import com.google.protobuf.TextFormat.ParseException;
Expand Down
1 change: 0 additions & 1 deletion test/com/google/javascript/jscomp/CompilerTestCase.java
Expand Up @@ -31,7 +31,6 @@
import com.google.javascript.jscomp.AbstractCompiler.MostRecentTypechecker;
import com.google.javascript.jscomp.CompilerOptions.LanguageMode;
import com.google.javascript.jscomp.deps.ModuleLoader;
import com.google.javascript.jscomp.testing.BlackHoleErrorManager;
import com.google.javascript.jscomp.type.ReverseAbstractInterpreter;
import com.google.javascript.jscomp.type.SemanticReverseAbstractInterpreter;
import com.google.javascript.rhino.Node;
Expand Down
3 changes: 1 addition & 2 deletions test/com/google/javascript/jscomp/IntegrationTestCase.java
Expand Up @@ -21,7 +21,6 @@
import com.google.common.base.Joiner;
import com.google.common.collect.ImmutableList;
import com.google.javascript.jscomp.CompilerTestCase.NoninjectingCompiler;
import com.google.javascript.jscomp.testing.BlackHoleErrorManager;
import com.google.javascript.rhino.Node;
import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -412,7 +411,7 @@ protected Compiler compile(CompilerOptions options, String[] original) {
Compiler compiler = useNoninjectingCompiler ? new NoninjectingCompiler() : new Compiler();

lastCompiler = compiler;
BlackHoleErrorManager.silence(compiler);
options.setErrorHandler(new BlackHoleErrorManager());
compiler.compileModules(
externs,
ImmutableList.copyOf(
Expand Down
7 changes: 2 additions & 5 deletions test/com/google/javascript/jscomp/SymbolTableTest.java
Expand Up @@ -13,7 +13,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.google.javascript.jscomp;

import static com.google.common.truth.Truth.assertThat;
Expand All @@ -27,7 +26,6 @@
import com.google.javascript.jscomp.SymbolTable.Reference;
import com.google.javascript.jscomp.SymbolTable.Symbol;
import com.google.javascript.jscomp.SymbolTable.SymbolScope;
import com.google.javascript.jscomp.testing.BlackHoleErrorManager;
import com.google.javascript.rhino.JSDocInfo;
import com.google.javascript.rhino.JSDocInfo.Visibility;
import com.google.javascript.rhino.Token;
Expand All @@ -54,11 +52,11 @@ protected void setUp() throws Exception {
super.setUp();

options = new CompilerOptions();
options.setErrorHandler(new BlackHoleErrorManager());
options.setLanguageIn(LanguageMode.ECMASCRIPT_2017);
options.setLanguageOut(LanguageMode.ECMASCRIPT5);
options.setCodingConvention(new ClosureCodingConvention());
CompilationLevel.SIMPLE_OPTIMIZATIONS.setOptionsForCompilationLevel(
options);
CompilationLevel.SIMPLE_OPTIMIZATIONS.setOptionsForCompilationLevel(options);
WarningLevel.VERBOSE.setOptionsForWarningLevel(options);
options.setChecksOnly(true);
options.setPreserveDetailedSourceInfo(true);
Expand Down Expand Up @@ -1174,7 +1172,6 @@ private SymbolTable createSymbolTable(String input) {
SourceFile.fromCode("externs1", EXTERNS));

Compiler compiler = new Compiler();
BlackHoleErrorManager.silence(compiler);
compiler.compile(externs, inputs, options);
return assertSymbolTableValid(compiler.buildKnownSymbolTable());
}
Expand Down
4 changes: 2 additions & 2 deletions test/com/google/javascript/refactoring/MatchersTest.java
Expand Up @@ -20,10 +20,10 @@
import static org.junit.Assert.assertTrue;

import com.google.common.collect.ImmutableList;
import com.google.javascript.jscomp.BlackHoleErrorManager;
import com.google.javascript.jscomp.Compiler;
import com.google.javascript.jscomp.CompilerOptions;
import com.google.javascript.jscomp.SourceFile;
import com.google.javascript.jscomp.testing.BlackHoleErrorManager;
import com.google.javascript.rhino.Node;
import org.junit.Test;
import org.junit.runner.RunWith;
Expand Down Expand Up @@ -421,9 +421,9 @@ private static Compiler getCompiler(String jsInput) {

private static Compiler getCompiler(String externs, String jsInput) {
Compiler compiler = new Compiler();
BlackHoleErrorManager.silence(compiler);
compiler.disableThreads();
CompilerOptions options = RefactoringDriver.getCompilerOptions();
options.setErrorHandler(new BlackHoleErrorManager());
compiler.compile(
ImmutableList.of(SourceFile.fromCode("externs", externs)),
ImmutableList.of(SourceFile.fromCode("test", jsInput)),
Expand Down

0 comments on commit ff836ef

Please sign in to comment.