| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package com.google.javascript.jscomp.testing; |
| 18 |
|
| 19 |
import com.google.javascript.rhino.head.ErrorReporter; |
| 20 |
import com.google.javascript.rhino.head.EvaluatorException; |
| 21 |
|
| 22 |
import junit.framework.Assert; |
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
public final class TestErrorReporter extends Assert implements ErrorReporter { |
| 38 |
private final String[] errors; |
| 39 |
private final String[] warnings; |
| 40 |
private int errorsIndex = 0; |
| 41 |
private int warningsIndex = 0; |
| 42 |
|
| 43 |
public TestErrorReporter(String[] errors, String[] warnings) { |
| 44 |
this.errors = errors; |
| 45 |
this.warnings = warnings; |
| 46 |
} |
| 47 |
|
| 48 |
@Override |
| 49 |
public void error(String message, String sourceName, int line, |
| 50 |
String lineSource, int lineOffset) { |
| 51 |
if (errors != null && errorsIndex < errors.length) { |
| 52 |
assertEquals(errors[errorsIndex++], message); |
| 53 |
} else { |
| 54 |
fail("extra error: " + message); |
| 55 |
} |
| 56 |
} |
| 57 |
|
| 58 |
@Override |
| 59 |
public void warning(String message, String sourceName, int line, |
| 60 |
String lineSource, int lineOffset) { |
| 61 |
if (warnings != null && warningsIndex < warnings.length) { |
| 62 |
assertEquals(warnings[warningsIndex++], message); |
| 63 |
} else { |
| 64 |
fail("extra warning: " + message); |
| 65 |
} |
| 66 |
} |
| 67 |
|
| 68 |
@Override |
| 69 |
public EvaluatorException runtimeError(String message, String sourceName, |
| 70 |
int line, String lineSource, int lineOffset) { |
| 71 |
return new EvaluatorException("JSCompiler test code: " + message); |
| 72 |
} |
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
public boolean hasEncounteredAllWarnings() { |
| 78 |
return (warnings == null) ? |
| 79 |
warningsIndex == 0 : |
| 80 |
warnings.length == warningsIndex; |
| 81 |
} |
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
public boolean hasEncounteredAllErrors() { |
| 87 |
return (errors == null) ? |
| 88 |
errorsIndex == 0 : |
| 89 |
errors.length == errorsIndex; |
| 90 |
} |
| 91 |
} |