Add test to assert that warnings are deduplicated.
package com.google.javascript.jscomp;
+import static com.google.common.truth.Truth.assertThat;
+
import com.google.javascript.jscomp.BasicErrorManager.ErrorWithLevel;
import com.google.javascript.jscomp.BasicErrorManager.LeveledJSErrorComparator;
-import com.google.javascript.jscomp.CheckLevel;
-
+import java.util.ArrayList;
+import java.util.List;
import junit.framework.TestCase;
/**
@@ -102,6 +104,25 @@ public final class BasicErrorManagerTest extends TestCase {
assertSmaller(error(e1), error(e2));
}
+ public void testDeduplicatedErrors() {
+ final List<JSError> printedErrors = new ArrayList<>();
+ BasicErrorManager manager = new BasicErrorManager() {
+ @Override
+ public void println(CheckLevel level, JSError error) {
+ printedErrors.add(error);
+ }
+
+ @Override
+ protected void printSummary() { }
+ };
+ JSError e1 = JSError.make(NULL_SOURCE, -1, -1, FOO_TYPE);
+ JSError e2 = JSError.make(NULL_SOURCE, -1, -1, FOO_TYPE);
+ manager.report(CheckLevel.ERROR, e1);
+ manager.report(CheckLevel.ERROR, e2);
+ manager.generateReport();
+ assertThat(printedErrors).hasSize(1);
+ }
+
private ErrorWithLevel error(JSError e) {
return new ErrorWithLevel(e, CheckLevel.ERROR);
}
