Skip to content

Commit

Permalink
Refactor CompilerTypeTestCase to fix a problem with TypeCheckTest
Browse files Browse the repository at this point in the history
1. Disconnect CompilerTypeTestCase from BaseJSTypeTestCase and add methods for
   getting the correct native types in tests.

BaseJSTypeTestCase artificially constructs native types in a way that
conflicts with using externs in the normal fashion.
This leads to confusing unit test behavior, causing incorrect behavior for
one test case in TypeCheckTest and correct behavior for the wrong reason in others.

2. Also create TestExternsBuilder class.

This class provides a way to build exactly the externs definitions needed for a test
case rather than continually adding definitions to one or more "default" externs
variables that grow ever larger creating a performance drain on test cases that don't
need most of the definitions they contain.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=193379201
  • Loading branch information
brad4d authored and blickly committed Apr 19, 2018
1 parent b364e72 commit 8ceea0f
Show file tree
Hide file tree
Showing 8 changed files with 1,813 additions and 1,103 deletions.
14 changes: 0 additions & 14 deletions src/com/google/javascript/rhino/testing/BaseJSTypeTestCase.java
Expand Up @@ -81,18 +81,15 @@ public abstract class BaseJSTypeTestCase extends TestCase {
protected ObjectType FUNCTION_PROTOTYPE;
protected JSType GREATEST_FUNCTION_TYPE;
protected JSType LEAST_FUNCTION_TYPE;
protected JSType MATH_TYPE;
protected JSType NULL_TYPE;
protected JSType NUMBER_OBJECT_FUNCTION_TYPE;
protected ObjectType NUMBER_OBJECT_TYPE;
protected JSType NUMBER_STRING_BOOLEAN;
protected JSType NUMBER_STRING_BOOLEAN_SYMBOL;
protected JSType NUMBER_TYPE;
protected FunctionType OBJECT_FUNCTION_TYPE;
protected JSType NULL_VOID;
protected JSType OBJECT_NUMBER_STRING;
protected JSType OBJECT_NUMBER_STRING_BOOLEAN;
protected JSType OBJECT_NUMBER_STRING_BOOLEAN_SYMBOL;
protected JSType OBJECT_PROTOTYPE;
protected ObjectType OBJECT_TYPE;
protected JSType RANGE_ERROR_FUNCTION_TYPE;
Expand All @@ -104,7 +101,6 @@ public abstract class BaseJSTypeTestCase extends TestCase {
protected JSType STRING_OBJECT_FUNCTION_TYPE;
protected ObjectType STRING_OBJECT_TYPE;
protected JSType STRING_TYPE;
protected JSType SYMBOL_OBJECT_FUNCTION_TYPE;
protected ObjectType SYMBOL_OBJECT_TYPE;
protected JSType SYMBOL_TYPE;
protected JSType SYNTAX_ERROR_FUNCTION_TYPE;
Expand Down Expand Up @@ -179,8 +175,6 @@ protected void initTypes() {
registry.getNativeObjectType(JSTypeNative.NUMBER_OBJECT_TYPE);
NUMBER_STRING_BOOLEAN =
registry.getNativeType(JSTypeNative.NUMBER_STRING_BOOLEAN);
NUMBER_STRING_BOOLEAN_SYMBOL =
registry.getNativeType(JSTypeNative.NUMBER_STRING_BOOLEAN_SYMBOL);
NUMBER_TYPE =
registry.getNativeType(JSTypeNative.NUMBER_TYPE);
OBJECT_FUNCTION_TYPE =
Expand All @@ -191,8 +185,6 @@ protected void initTypes() {
registry.getNativeType(JSTypeNative.OBJECT_NUMBER_STRING);
OBJECT_NUMBER_STRING_BOOLEAN =
registry.getNativeType(JSTypeNative.OBJECT_NUMBER_STRING_BOOLEAN);
OBJECT_NUMBER_STRING_BOOLEAN_SYMBOL =
registry.getNativeType(JSTypeNative.OBJECT_NUMBER_STRING_BOOLEAN_SYMBOL);
OBJECT_PROTOTYPE =
registry.getNativeType(JSTypeNative.OBJECT_PROTOTYPE);
OBJECT_TYPE =
Expand All @@ -215,8 +207,6 @@ protected void initTypes() {
registry.getNativeObjectType(JSTypeNative.STRING_OBJECT_TYPE);
STRING_TYPE =
registry.getNativeType(JSTypeNative.STRING_TYPE);
SYMBOL_OBJECT_FUNCTION_TYPE =
registry.getNativeType(JSTypeNative.SYMBOL_OBJECT_FUNCTION_TYPE);
SYMBOL_OBJECT_TYPE =
registry.getNativeObjectType(JSTypeNative.SYMBOL_OBJECT_TYPE);
SYMBOL_TYPE =
Expand Down Expand Up @@ -622,10 +612,6 @@ protected final void assertTypeNotEquals(JSType a, JSType b) {
Asserts.assertTypeNotEquals(a, b);
}

protected final void assertTypeNotEquals(String msg, JSType a, JSType b) {
Asserts.assertTypeNotEquals(msg, a, b);
}

protected static String lines(String line) {
return line;
}
Expand Down

0 comments on commit 8ceea0f

Please sign in to comment.