Skip to content

Commit

Permalink
Remove NTI support from TypeICompilerTestCase
Browse files Browse the repository at this point in the history
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=194319639
  • Loading branch information
concavelenz authored and brad4d committed Apr 26, 2018
1 parent 5f359c3 commit e6ad97f
Show file tree
Hide file tree
Showing 37 changed files with 200 additions and 437 deletions.
Expand Up @@ -49,7 +49,6 @@ protected void setUp() throws Exception {
enableNormalize(); enableNormalize();
enableClosurePass(); enableClosurePass();
enableGatherExternProperties(); enableGatherExternProperties();
this.mode = TypeInferenceMode.BOTH;
ignoreWarnings( ignoreWarnings(
NewTypeInference.GLOBAL_THIS, NewTypeInference.GLOBAL_THIS,
NewTypeInference.PROPERTY_ACCESS_ON_NONOBJECT); NewTypeInference.PROPERTY_ACCESS_ON_NONOBJECT);
Expand Down Expand Up @@ -1123,8 +1122,6 @@ public void testDontRenamePrototypeWithoutExterns() {
"/** @return {!Foo} */", "/** @return {!Foo} */",
"Foo.prototype.a = function() {};"); "Foo.prototype.a = function() {};");


// NTI reqires at least the MINIMAL_EXTERNS.
this.mode = TypeInferenceMode.OTI_ONLY;
test(externs(""), srcs(js), expected(output)); test(externs(""), srcs(js), expected(output));
} }
} }
23 changes: 0 additions & 23 deletions test/com/google/javascript/jscomp/CheckAccessControlsTest.java
Expand Up @@ -329,10 +329,6 @@ public void testWarningForSuperclassMethod2() {
} }


public void testWarningForBind() { public void testWarningForBind() {
// NTI reports NTI_REDCLARED_PROPERTY here, which is as intended. If this were a new
// property and not the existing `bind`, then we'd report the deprecation warning as expected
// (see testAutoboxedDeprecatedProperty and testAutoboxedPrivateProperty).
this.mode = TypeInferenceMode.OTI_ONLY;
testDepProp( testDepProp(
"/** @deprecated I'm bound to this method... */ Function.prototype.bind = function() {};" "/** @deprecated I'm bound to this method... */ Function.prototype.bind = function() {};"
+ "(function() {}).bind();", + "(function() {}).bind();",
Expand Down Expand Up @@ -467,19 +463,10 @@ public void testPrivateAccess_googModule() {
"(new One()).m();"), "(new One()).m();"),
}; };


this.mode = TypeInferenceMode.OTI_ONLY;
testError( testError(
srcs(js), srcs(js),
error(BAD_PRIVATE_PROPERTY_ACCESS) error(BAD_PRIVATE_PROPERTY_ACCESS)
.withMessage("Access to private property m of One not allowed here.")); .withMessage("Access to private property m of One not allowed here."));

/*
this.mode = TypeInferenceMode.NTI_ONLY;
testError(
srcs(js),
error(BAD_PRIVATE_PROPERTY_ACCESS).withMessage(
"Access to private property m of module$exports$example$One not allowed here."));
*/
} }


public void testNoPrivateAccessForProperties1() { public void testNoPrivateAccessForProperties1() {
Expand Down Expand Up @@ -1698,9 +1685,6 @@ public void testNamespaceConstantProperty1() {
} }


public void testNamespaceConstantProperty2() { public void testNamespaceConstantProperty2() {
// NTI requires an @const annotation on namespaces, as in testNamespaceConstantProperty1.
// This is the only difference between the two tests.
this.mode = TypeInferenceMode.OTI_ONLY;
testError( testError(
"var o = {};\n" "var o = {};\n"
+ "/** @const */ o.x = 1;\n" + "/** @const */ o.x = 1;\n"
Expand Down Expand Up @@ -1742,8 +1726,6 @@ public void testConstantProperty3b1() {
} }


public void testConstantProperty3b2() { public void testConstantProperty3b2() {
// NTI reports NTI_REDECLARED_PROPERTY
this.mode = TypeInferenceMode.OTI_ONLY;
// The old type checker should report this but it doesn't. // The old type checker should report this but it doesn't.
testSame("/** @const */ var o = { XYZ: 1 };" testSame("/** @const */ var o = { XYZ: 1 };"
+ "o.XYZ = 2;"); + "o.XYZ = 2;");
Expand Down Expand Up @@ -1807,8 +1789,6 @@ public void testConstantProperty10a() {
} }


public void testConstantProperty10b() { public void testConstantProperty10b() {
// NTI reports NTI_REDECLARED_PROPERTY
this.mode = TypeInferenceMode.OTI_ONLY;
testSame("/** @constructor */ function Foo() { this.PROP = 1;}" testSame("/** @constructor */ function Foo() { this.PROP = 1;}"
+ "Foo.prototype.PROP;"); + "Foo.prototype.PROP;");
} }
Expand All @@ -1825,9 +1805,6 @@ public void testConstantProperty11() {
} }


public void testConstantProperty12() { public void testConstantProperty12() {
// NTI deliberately disallows this pattern (separate declaration and initialization
// of const properties). (b/30205953)
this.mode = TypeInferenceMode.OTI_ONLY;
testSame("/** @constructor */ function Foo() {}" testSame("/** @constructor */ function Foo() {}"
+ "/** @const */ Foo.prototype.bar;" + "/** @const */ Foo.prototype.bar;"
+ "/**\n" + "/**\n"
Expand Down
10 changes: 0 additions & 10 deletions test/com/google/javascript/jscomp/CheckConformanceTest.java
Expand Up @@ -1400,7 +1400,6 @@ public void testCustomBanUnknownInterfaceProp1() {
" a.gak();", " a.gak();",
"}"); "}");


this.mode = TypeInferenceMode.OTI_ONLY;
testWarning( testWarning(
js, js,
CheckConformance.CONFORMANCE_VIOLATION, CheckConformance.CONFORMANCE_VIOLATION,
Expand Down Expand Up @@ -1524,17 +1523,11 @@ public void testCustomBanUnresolvedType() {
+ " error_message: 'BanUnresolvedType Message'\n" + " error_message: 'BanUnresolvedType Message'\n"
+ "}"; + "}";


// NOTE(aravindpg): In NTI we annotate the node `a` with its inferred type instead of Unknown,
// and so this test doesn't recognize `a` as unresolved. Fixing this is undesirable.
// However, we do intend to add warnings for unfulfilled forward declares, which essentially
// addresses this use case.
this.mode = TypeInferenceMode.OTI_ONLY;
testWarning( testWarning(
"goog.forwardDeclare('Foo'); /** @param {Foo} a */ function f(a) {a.foo()};", "goog.forwardDeclare('Foo'); /** @param {Foo} a */ function f(a) {a.foo()};",
CheckConformance.CONFORMANCE_VIOLATION, CheckConformance.CONFORMANCE_VIOLATION,
"Violation: BanUnresolvedType Message\nReference to type 'Foo' never resolved."); "Violation: BanUnresolvedType Message\nReference to type 'Foo' never resolved.");


this.mode = TypeInferenceMode.BOTH;
testNoWarning(lines( testNoWarning(lines(
"/** @suppress {newCheckTypes}", "/** @suppress {newCheckTypes}",
" * @param {!Object<string, ?>} data", " * @param {!Object<string, ?>} data",
Expand All @@ -1552,9 +1545,6 @@ public void testCustomStrictBanUnresolvedType() {
+ " error_message: 'StrictBanUnresolvedType Message'\n" + " error_message: 'StrictBanUnresolvedType Message'\n"
+ "}"; + "}";


// NTI doesn't model unresolved types separately from unknown, so this check always results
// in conformance.
this.mode = TypeInferenceMode.OTI_ONLY;
testWarning( testWarning(
"goog.forwardDeclare('Foo'); /** @param {Foo} a */ var f = function(a) {}", "goog.forwardDeclare('Foo'); /** @param {Foo} a */ var f = function(a) {}",
CheckConformance.CONFORMANCE_VIOLATION, CheckConformance.CONFORMANCE_VIOLATION,
Expand Down
15 changes: 4 additions & 11 deletions test/com/google/javascript/jscomp/CheckTemplateParamsTest.java
Expand Up @@ -17,20 +17,13 @@
package com.google.javascript.jscomp; package com.google.javascript.jscomp;


import static com.google.javascript.jscomp.RhinoErrorReporter.TOO_MANY_TEMPLATE_PARAMS; import static com.google.javascript.jscomp.RhinoErrorReporter.TOO_MANY_TEMPLATE_PARAMS;
import static com.google.javascript.jscomp.newtypes.JSTypeCreatorFromJSDoc.INVALID_GENERICS_INSTANTIATION;


/** /**
* Tests for the "Too many template parameters" warning. Ideally this would be part of * Tests for the "Too many template parameters" warning. Ideally this would be part of
* JSDocInfoParserTest but that test is set up to handle warnings reported from JSDocInfoParser, * JSDocInfoParserTest but that test is set up to handle warnings reported from JSDocInfoParser,
* (as strings) not ones from JSTypeRegistry (as DiagnosticTypes). * (as strings) not ones from JSTypeRegistry (as DiagnosticTypes).
*/ */
public final class CheckTemplateParamsTest extends TypeICompilerTestCase { public final class CheckTemplateParamsTest extends TypeICompilerTestCase {
@Override
protected void setUp() throws Exception {
super.setUp();
this.mode = TypeInferenceMode.BOTH;
}

@Override @Override
protected int getNumRepetitions() { protected int getNumRepetitions() {
return 1; return 1;
Expand All @@ -54,7 +47,7 @@ public void testArray() {
testSame("/** @type {!Array<string>} */ var x;"); testSame("/** @type {!Array<string>} */ var x;");
test( test(
srcs("/** @type {!Array<string, number>} */ var x;"), srcs("/** @type {!Array<string, number>} */ var x;"),
warningOtiNti(TOO_MANY_TEMPLATE_PARAMS, INVALID_GENERICS_INSTANTIATION)); warning(TOO_MANY_TEMPLATE_PARAMS));
} }


public void testObject() { public void testObject() {
Expand All @@ -63,7 +56,7 @@ public void testObject() {
testSame("/** @type {!Object<string, number>} */ var x;"); testSame("/** @type {!Object<string, number>} */ var x;");
test( test(
srcs("/** @type {!Object<string, number, boolean>} */ var x;"), srcs("/** @type {!Object<string, number, boolean>} */ var x;"),
warningOtiNti(TOO_MANY_TEMPLATE_PARAMS, INVALID_GENERICS_INSTANTIATION)); warning(TOO_MANY_TEMPLATE_PARAMS));
} }


public void testClass() { public void testClass() {
Expand All @@ -72,7 +65,7 @@ public void testClass() {
srcs(lines( srcs(lines(
"/** @constructor */ function SomeClass() {};", "/** @constructor */ function SomeClass() {};",
"/** @type {!SomeClass<string>} */ var x;")), "/** @type {!SomeClass<string>} */ var x;")),
warningOtiNti(TOO_MANY_TEMPLATE_PARAMS, INVALID_GENERICS_INSTANTIATION)); warning(TOO_MANY_TEMPLATE_PARAMS));


testSame(lines( testSame(lines(
"/** @constructor @template T */ function SomeClass() {};", "/** @constructor @template T */ function SomeClass() {};",
Expand All @@ -82,7 +75,7 @@ public void testClass() {
srcs(lines( srcs(lines(
"/** @constructor @template T */ function SomeClass() {};", "/** @constructor @template T */ function SomeClass() {};",
"/** @type {!SomeClass<number, string>} */ var x;")), "/** @type {!SomeClass<number, string>} */ var x;")),
warningOtiNti(TOO_MANY_TEMPLATE_PARAMS, INVALID_GENERICS_INSTANTIATION)); warning(TOO_MANY_TEMPLATE_PARAMS));
} }


} }
Expand Up @@ -82,7 +82,7 @@ public void testConstructorPropertyUsed1() {
} }


public void testClassPropUnused1() { public void testClassPropUnused1() {
this.mode = TypeInferenceMode.NEITHER; this.mode = TypeInferenceMode.DISABLED;


// A property defined on "this" can be removed // A property defined on "this" can be removed
unused("class C { constructor() { /** @private */ this.a = 2 } }"); unused("class C { constructor() { /** @private */ this.a = 2 } }");
Expand All @@ -94,15 +94,15 @@ public void testClassPropUnused2() {
} }


public void testClassMethodUnused1() { public void testClassMethodUnused1() {
this.mode = TypeInferenceMode.NEITHER; this.mode = TypeInferenceMode.DISABLED;


unused("class C { constructor() {} /** @private */ method() {} }"); unused("class C { constructor() {} /** @private */ method() {} }");
used("class C { constructor() {} /** @private */ method() {} }\n new C().method();"); used("class C { constructor() {} /** @private */ method() {} }\n new C().method();");
} }


// The JSDoc seems to be missing here, reenable this test when it is fixed. // The JSDoc seems to be missing here, reenable this test when it is fixed.
public void disable_testClassMethodUnused2() { public void disable_testClassMethodUnused2() {
this.mode = TypeInferenceMode.NEITHER; this.mode = TypeInferenceMode.DISABLED;


unused("class C { constructor() {}\n /** @private */ ['method']() {} }"); unused("class C { constructor() {}\n /** @private */ ['method']() {} }");
used("class C { constructor() {}\n /** @private */ ['method']() {} }\n new C()['method']();"); used("class C { constructor() {}\n /** @private */ ['method']() {} }\n new C()['method']();");
Expand Down
36 changes: 15 additions & 21 deletions test/com/google/javascript/jscomp/ClosureRewriteClassTest.java
Expand Up @@ -41,17 +41,12 @@ public final class ClosureRewriteClassTest extends TypeICompilerTestCase {
"goog.defineClass = function(a,b) {};", "goog.defineClass = function(a,b) {};",
"var use;"); "var use;");


private static final Diagnostic INSTANTIATE_ABSTRACT_CLASS = warningOtiNti( private static final Diagnostic INSTANTIATE_ABSTRACT_CLASS =
TypeCheck.INSTANTIATE_ABSTRACT_CLASS, warning(TypeCheck.INSTANTIATE_ABSTRACT_CLASS);
NewTypeInference.CANNOT_INSTANTIATE_ABSTRACT_CLASS);


private static final Diagnostic NOT_A_CONSTRUCTOR = warningOtiNti( private static final Diagnostic NOT_A_CONSTRUCTOR = warning(TypeCheck.NOT_A_CONSTRUCTOR);
TypeCheck.NOT_A_CONSTRUCTOR,
NewTypeInference.NOT_A_CONSTRUCTOR);


private static final Diagnostic INEXISTENT_PROPERTY = warningOtiNti( private static final Diagnostic INEXISTENT_PROPERTY = warning(TypeCheck.INEXISTENT_PROPERTY);
TypeCheck.INEXISTENT_PROPERTY,
NewTypeInference.INEXISTENT_PROPERTY);


public ClosureRewriteClassTest() { public ClosureRewriteClassTest() {
super(EXTERNS); super(EXTERNS);
Expand All @@ -65,7 +60,7 @@ protected CompilerPass getProcessor(Compiler compiler) {
@Override @Override
protected void setUp() throws Exception { protected void setUp() throws Exception {
super.setUp(); super.setUp();
this.mode = TypeInferenceMode.NEITHER; this.mode = TypeInferenceMode.DISABLED;
enableRunTypeCheckAfterProcessing(); enableRunTypeCheckAfterProcessing();
} }


Expand Down Expand Up @@ -154,7 +149,7 @@ public void testConst() {


public void testAnnotations1() { public void testAnnotations1() {
// verify goog.defineClass values are constructible, by default // verify goog.defineClass values are constructible, by default
this.mode = TypeInferenceMode.BOTH; this.mode = TypeInferenceMode.CHECKED;
testRewrite( testRewrite(
"var x = goog.defineClass(Object, {\n" "var x = goog.defineClass(Object, {\n"
+ " constructor: function(){}\n" + " constructor: function(){}\n"
Expand All @@ -168,7 +163,7 @@ public void testAnnotations1() {


public void testAnnotations2a() { public void testAnnotations2a() {
// @interface is preserved // @interface is preserved
this.mode = TypeInferenceMode.BOTH; this.mode = TypeInferenceMode.CHECKED;
testRewriteWarning( testRewriteWarning(
lines( lines(
"var x = goog.defineClass(null, {", "var x = goog.defineClass(null, {",
Expand All @@ -185,7 +180,7 @@ public void testAnnotations2a() {


public void testAnnotations2b() { public void testAnnotations2b() {
// @interface is preserved, at the class level too // @interface is preserved, at the class level too
this.mode = TypeInferenceMode.BOTH; this.mode = TypeInferenceMode.CHECKED;
testRewriteWarning( testRewriteWarning(
lines( lines(
"/** @interface */", "/** @interface */",
Expand All @@ -200,7 +195,7 @@ public void testAnnotations2b() {


public void testAnnotations3a() { public void testAnnotations3a() {
// verify goog.defineClass is a @struct by default // verify goog.defineClass is a @struct by default
this.mode = TypeInferenceMode.BOTH; this.mode = TypeInferenceMode.CHECKED;
testRewriteWarning( testRewriteWarning(
lines( lines(
"var y = goog.defineClass(null, {", "var y = goog.defineClass(null, {",
Expand All @@ -222,8 +217,8 @@ public void testAnnotations3a() {


public void testAnnotations3b() { public void testAnnotations3b() {
// verify goog.defineClass is a @struct by default, but can be overridden (only in OTI) // verify goog.defineClass is a @struct by default, but can be overridden (only in OTI)
this.mode = TypeInferenceMode.BOTH; this.mode = TypeInferenceMode.CHECKED;
testRewriteWarning( testRewrite(
lines( lines(
"/** @unrestricted */", "/** @unrestricted */",
"var y = goog.defineClass(null, {", "var y = goog.defineClass(null, {",
Expand All @@ -239,8 +234,7 @@ public void testAnnotations3b() {
"/** @constructor @struct @extends {y} */", "/** @constructor @struct @extends {y} */",
"var x = function() {this.a = 1};", "var x = function() {this.a = 1};",
"goog.inherits(x,y);", "goog.inherits(x,y);",
"use(new y().a);"), "use(new y().a);"));
warningOtiNti(null, NewTypeInference.INEXISTENT_PROPERTY));
} }


public void testRecordAnnotations() { public void testRecordAnnotations() {
Expand All @@ -255,7 +249,7 @@ public void testRecordAnnotations() {
} }


public void testRecordAnnotations2() { public void testRecordAnnotations2() {
this.mode = TypeInferenceMode.BOTH; this.mode = TypeInferenceMode.CHECKED;
testRewrite( testRewrite(
"/** @record */\n" "/** @record */\n"
+ "var Rec = goog.defineClass(null, {f : function() {}});\n" + "var Rec = goog.defineClass(null, {f : function() {}});\n"
Expand All @@ -269,7 +263,7 @@ public void testRecordAnnotations2() {


public void testAbstract1() { public void testAbstract1() {
// @abstract is preserved // @abstract is preserved
this.mode = TypeInferenceMode.BOTH; this.mode = TypeInferenceMode.CHECKED;
testRewriteWarning( testRewriteWarning(
lines( lines(
"var x = goog.defineClass(null, {", "var x = goog.defineClass(null, {",
Expand All @@ -286,7 +280,7 @@ public void testAbstract1() {


public void testAbstract2() { public void testAbstract2() {
// @abstract is preserved, at the class level too // @abstract is preserved, at the class level too
this.mode = TypeInferenceMode.BOTH; this.mode = TypeInferenceMode.CHECKED;
testRewriteWarning( testRewriteWarning(
lines( lines(
"/** @abstract */", "/** @abstract */",
Expand Down
10 changes: 5 additions & 5 deletions test/com/google/javascript/jscomp/CodePrinterTest.java
Expand Up @@ -1543,7 +1543,7 @@ void setOptions(CompilerOptions options) {
private void assertTypeAnnotations(String js, String expected) { private void assertTypeAnnotations(String js, String expected) {
assertEquals( assertEquals(
expected, expected,
new CodePrinter.Builder(parse(js, TypeInferenceMode.OTI_ONLY)) new CodePrinter.Builder(parse(js, TypeInferenceMode.CHECKED))
.setCompilerOptions(newCompilerOptions(new CompilerOptionBuilder() { .setCompilerOptions(newCompilerOptions(new CompilerOptionBuilder() {
@Override @Override
void setOptions(CompilerOptions options) { void setOptions(CompilerOptions options) {
Expand Down Expand Up @@ -1994,13 +1994,13 @@ void setOptions(CompilerOptions options) {


public void testStrict() { public void testStrict() {
String result = String result =
defaultBuilder(parse("var x", TypeInferenceMode.OTI_ONLY)).setTagAsStrict(true).build(); defaultBuilder(parse("var x", TypeInferenceMode.CHECKED)).setTagAsStrict(true).build();
assertEquals("'use strict';var x", result); assertEquals("'use strict';var x", result);
} }


public void testStrictPretty() { public void testStrictPretty() {
String result = String result =
defaultBuilder(parse("var x", TypeInferenceMode.OTI_ONLY)) defaultBuilder(parse("var x", TypeInferenceMode.CHECKED))
.setTagAsStrict(true) .setTagAsStrict(true)
.setPrettyPrint(true) .setPrettyPrint(true)
.build(); .build();
Expand All @@ -2009,13 +2009,13 @@ public void testStrictPretty() {


public void testExterns() { public void testExterns() {
String result = String result =
defaultBuilder(parse("var x", TypeInferenceMode.OTI_ONLY)).setTagAsExterns(true).build(); defaultBuilder(parse("var x", TypeInferenceMode.CHECKED)).setTagAsExterns(true).build();
assertEquals("/** @externs */\nvar x", result); assertEquals("/** @externs */\nvar x", result);
} }


public void testIjs() { public void testIjs() {
String result = String result =
defaultBuilder(parse("var x", TypeInferenceMode.OTI_ONLY)) defaultBuilder(parse("var x", TypeInferenceMode.CHECKED))
.setTagAsTypeSummary(true) .setTagAsTypeSummary(true)
.build(); .build();
assertEquals("/** @fileoverview @typeSummary */\nvar x", result); assertEquals("/** @fileoverview @typeSummary */\nvar x", result);
Expand Down
7 changes: 2 additions & 5 deletions test/com/google/javascript/jscomp/CodePrinterTestBase.java
Expand Up @@ -15,8 +15,6 @@
*/ */
package com.google.javascript.jscomp; package com.google.javascript.jscomp;


import static com.google.common.base.Preconditions.checkArgument;

import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.javascript.jscomp.CompilerOptions.LanguageMode; import com.google.javascript.jscomp.CompilerOptions.LanguageMode;
import com.google.javascript.jscomp.TypeICompilerTestCase.TypeInferenceMode; import com.google.javascript.jscomp.TypeICompilerTestCase.TypeInferenceMode;
Expand Down Expand Up @@ -44,11 +42,10 @@ protected void setUp() throws Exception {
} }


Node parse(String js) { Node parse(String js) {
return parse(js, TypeInferenceMode.NEITHER); return parse(js, TypeInferenceMode.DISABLED);
} }


Node parse(String js, TypeInferenceMode mode) { Node parse(String js, TypeInferenceMode mode) {
checkArgument(mode != TypeInferenceMode.BOTH);
Compiler compiler = new Compiler(); Compiler compiler = new Compiler();
lastCompiler = compiler; lastCompiler = compiler;
CompilerOptions options = new CompilerOptions(); CompilerOptions options = new CompilerOptions();
Expand All @@ -67,7 +64,7 @@ Node parse(String js, TypeInferenceMode mode) {
Node root = externsAndJs.getLastChild(); Node root = externsAndJs.getLastChild();
Node externs = externsAndJs.getFirstChild(); Node externs = externsAndJs.getFirstChild();


if (mode.runsOTI()) { if (mode.runsTypeCheck()) {
DefaultPassConfig passConfig = new DefaultPassConfig(null); DefaultPassConfig passConfig = new DefaultPassConfig(null);
CompilerPass typeResolver = passConfig.resolveTypes.create(compiler); CompilerPass typeResolver = passConfig.resolveTypes.create(compiler);
typeResolver.process(externs, root); typeResolver.process(externs, root);
Expand Down

0 comments on commit e6ad97f

Please sign in to comment.