From 964d8d55f26341b4e81b38bf0b652d3a8d6a0fac Mon Sep 17 00:00:00 2001 From: Laurent Le Brun Date: Mon, 13 Apr 2015 12:15:04 +0000 Subject: Skylark: Remove static type checking of variables/functions. There are still some static checks (check existence of variable/function, readonly variables, etc.). More cleanup will come later. -- MOS_MIGRATED_REVID=90979748 --- .../build/lib/syntax/SkylarkEvaluationTest.java | 2 +- .../devtools/build/lib/syntax/ValidationTests.java | 243 --------------------- 2 files changed, 1 insertion(+), 244 deletions(-) (limited to 'src/test/java/com/google/devtools/build/lib') diff --git a/src/test/java/com/google/devtools/build/lib/syntax/SkylarkEvaluationTest.java b/src/test/java/com/google/devtools/build/lib/syntax/SkylarkEvaluationTest.java index e50a4b09ab..744cbd6a21 100644 --- a/src/test/java/com/google/devtools/build/lib/syntax/SkylarkEvaluationTest.java +++ b/src/test/java/com/google/devtools/build/lib/syntax/SkylarkEvaluationTest.java @@ -869,7 +869,7 @@ public class SkylarkEvaluationTest extends EvaluationTest { public void testNotCallInt() throws Exception { eval("sum = 123456"); assertEquals(123456, lookup("sum")); - checkEvalError("ERROR 1:1: sum is not a function but a(n) int", "sum(1, 2, 3, 4, 5, 6)"); + checkEvalError("'int' object is not callable", "sum(1, 2, 3, 4, 5, 6)"); assertEquals(123456, eval("sum")); } diff --git a/src/test/java/com/google/devtools/build/lib/syntax/ValidationTests.java b/src/test/java/com/google/devtools/build/lib/syntax/ValidationTests.java index 0a60e917f7..ce36537444 100644 --- a/src/test/java/com/google/devtools/build/lib/syntax/ValidationTests.java +++ b/src/test/java/com/google/devtools/build/lib/syntax/ValidationTests.java @@ -31,71 +31,11 @@ import java.util.Arrays; @RunWith(JUnit4.class) public class ValidationTests extends EvaluationTestCase { - @Test - public void testIncompatibleLiteralTypesStringInt() { - checkError("bad variable 'a': int is incompatible with string at 3:3", - "def foo():\n", - " a = '1'", - " a = 1"); - } - - @Test - public void testIncompatibleLiteralTypesDictString() { - checkError("bad variable 'a': int is incompatible with dict of ints at 3:3", - "def foo():\n", - " a = {1 : 'x'}", - " a = 1"); - } - - @Test - public void testIncompatibleLiteralTypesInIf() { - checkError("bad variable 'a': int is incompatible with string at 4:5", - "def foo():\n", - " if 1:", - " a = 'a'", - " else:", - " a = 1"); - } - @Test public void testAssignmentNotValidLValue() { checkError("can only assign to variables and tuples, not to ''a''", "'a' = 1"); } - @Test - public void testForNotIterable() throws Exception { - checkError("type 'int' is not iterable", - "def func():\n", - " for i in 5: a = i\n"); - } - - @Test - public void testForIterableWithUknownArgument() throws Exception { - parse("def func(x=None):\n", - " for i in x: a = i\n"); - } - - @Test - public void testForNotIterableBinaryExpression() throws Exception { - checkError("type 'int' is not iterable", - "def func():\n", - " for i in 1 + 1: a = i\n"); - } - - @Test - public void testOptionalArgument() throws Exception { - checkError("type 'int' is not iterable", - "def func(x=5):", - " for i in x: a = i\n"); - } - - @Test - public void testOptionalArgumentHasError() throws Exception { - checkError("unsupported operand type(s) for +: 'int' and 'string'", - "def func(x=5+'a'):", - " return 0\n"); - } - @Test public void testTopLevelForStatement() throws Exception { checkError("'For' is not allowed as a top level statement", "for i in [1,2,3]: a = i\n"); @@ -125,14 +65,6 @@ public class ValidationTests extends EvaluationTestCase { " return 1"); } - @Test - public void testDynamicTypeCheck() throws Exception { - checkError("bad variable 'a': string is incompatible with int at 2:3", - "def foo():", - " a = 1", - " a = '1'"); - } - @Test public void testFunctionLocalVariable() throws Exception { checkError("name 'a' is not defined", @@ -171,18 +103,6 @@ public class ValidationTests extends EvaluationTestCase { " a = 'abc'\n"); } - @Test - public void testListComprehensionNotIterable() throws Exception { - checkError("type 'int' is not iterable", - "[i for i in 1 for j in [2]]"); - } - - @Test - public void testListComprehensionNotIterable2() throws Exception { - checkError("type 'int' is not iterable", - "[i for i in [1] for j in 123]"); - } - @Test public void testListIsNotComparable() { checkError("list of strings is not comparable", "['a'] > 1"); @@ -233,20 +153,6 @@ public class ValidationTests extends EvaluationTestCase { "foo(4)"); } - @Test - public void testFunctionReturnValue() { - checkError("unsupported operand type(s) for +: 'int' and 'string'", - "def foo(): return 1", - "a = foo() + 'a'\n"); - } - - @Test - public void testFunctionReturnValueInFunctionDef() { - checkError("unsupported operand type(s) for +: 'int' and 'string'", - "def foo(): return 1", - "def bar(): a = foo() + 'a'\n"); - } - @Test public void testFunctionDoesNotExistInFunctionDef() { checkError("function 'foo' does not exist", @@ -268,47 +174,6 @@ public class ValidationTests extends EvaluationTestCase { "s.x['b'] = 2\n"); } - @Test - public void testTupleAssign() throws Exception { - // TODO(bazel-team): fix our code so 'tuple' not 'list' gets printed. - checkError("unsupported operand type(s) for +: 'list' and 'dict of ints'", - "d = (1, 2)", - "d[0] = 2\n"); - } - - @Test - public void testAssignOnNonCollection() throws Exception { - checkError("unsupported operand type(s) for +: 'string' and 'dict of ints'", - "d = 'abc'", - "d[0] = 2"); - } - - @Test - public void testNsetBadRightOperand() throws Exception { - checkError("can only concatenate nested sets with other nested sets or list of items, ", - "not 'string'", "set() + 'a'"); - } - - @Test - public void testNsetBadItemType() throws Exception { - checkError("bad nested set: set of ints is incompatible with set of strings at 1:1", - "(set() + ['a']) + [1]"); - } - - @Test - public void testNsetBadNestedItemType() throws Exception { - checkError("bad nested set: set of ints is incompatible with set of strings at 1:1", - "(set() + ['b']) + (set() + [1])"); - } - - @Test - public void testTypeInferenceForMethodLibraryFunction() throws Exception { - checkError("bad variable 'l': string is incompatible with int at 2:3", - "def foo():", - " l = len('abc')", - " l = 'a'"); - } - @Test public void testListLiteralBadTypes() throws Exception { checkError("bad list literal: int is incompatible with string at 1:1", @@ -383,16 +248,6 @@ public class ValidationTests extends EvaluationTestCase { " a = None\n"); } - @Test - public void testNoneAssignmentError() throws Exception { - checkError("bad variable 'a': string is incompatible with int at 4:3", - "def func():", - " a = None", - " a = 2", - " a = None", - " a = 'b'\n"); - } - @Test public void testNoneIsAnyType() throws Exception { parse("None + None"); @@ -402,37 +257,11 @@ public class ValidationTests extends EvaluationTestCase { parse("5 * None"); } - @Test - public void testSlice() throws Exception { - parse("def f(): a = 'abc'; a = 'abcd'[2:]"); - parse("def g(): b = ['abc']; b = ['abcd'][1:]"); - parse("def h(): c = 'ab'; c = ['ab'][1:]"); - checkError("bad variable 'c': string is incompatible with list of strings", - "def i(): c = ['xy']; c = 'cx'[1:]"); - } - @Test public void testDictComprehensionNotOnList() throws Exception { checkError("Dict comprehension elements must be a list", "{k : k for k in 'abc'}"); } - @Test - public void testTypeInferenceForUserDefinedFunction() throws Exception { - checkError("bad variable 'a': string is incompatible with int at 4:3", - "def func():", - " return 'a'", - "def foo():", - " a = 1", - " a = func()\n"); - } - - @Test - public void testCallingNonFunction() { - checkError("a is not a function", - "a = '1':", - "a()\n"); - } - @Test public void testFuncallArgument() { checkError("unsupported operand type(s) for +: 'int' and 'string'", @@ -442,23 +271,6 @@ public class ValidationTests extends EvaluationTestCase { // Skylark built-in functions specific tests - @Test - public void testTypeInferenceForSkylarkBuiltinGlobalFunction() throws Exception { - checkError("bad variable 'a': string is incompatible with function at 3:3", - "def impl(ctx): return None", - "def foo():", - " a = rule(impl)", - " a = 'a'\n"); - } - - @Test - public void testTypeInferenceForSkylarkBuiltinObjectFunction() throws Exception { - checkError("bad variable 'a': string is incompatible with Attribute at 2:3", - "def foo():", - " a = attr.int()", - " a = 'a'\n"); - } - @Test public void testFuncReturningDictAssignmentAsLValue() throws Exception { checkError("can only assign to variables and tuples, not to 'dict([])['b']'", @@ -469,24 +281,6 @@ public class ValidationTests extends EvaluationTestCase { " return d\n"); } - @Test - public void testListIndexAsLValue() { - checkError("unsupported operand type(s) for +: 'list of ints' and 'dict of ints'", - "def func():", - " l = [1]", - " l[0] = 2", - " return l\n"); - } - - @Test - public void testStringIndexAsLValue() { - checkError("unsupported operand type(s) for +: 'string' and 'dict of ints'", - "def func():", - " s = 'abc'", - " s[0] = 'd'", - " return s\n"); - } - @Test public void testEmptyLiteralGenericIsSetInLaterConcatWorks() { parse("def func():", @@ -494,12 +288,6 @@ public class ValidationTests extends EvaluationTestCase { " s['a'] = 'b'\n"); } - @Test - public void testTypeIsInferredForStructs() { - checkError("unsupported operand type(s) for +: 'struct' and 'string'", - "(struct(a = 1) + struct(b = 1)) + 'x'"); - } - @Test public void testReadOnlyWorksForSimpleBranching() { parse("if 1:", @@ -522,37 +310,6 @@ public class ValidationTests extends EvaluationTestCase { " v = 'd'\n"); } - @Test - public void testTypeCheckWorksForSimpleBranching() { - checkError("bad variable 'v': int is incompatible with string at 2:3", - "if 1:", - " v = 'a'", - "else:", - " v = 1"); - } - - @Test - public void testTypeCheckWorksForNestedBranching() { - checkError("bad variable 'v': int is incompatible with string at 5:5", - "if 1:", - " v = 'a'", - "else:", - " if 0:", - " v = 'b'", - " else:", - " v = 1\n"); - } - - @Test - public void testTypeCheckWorksForDifferentLevelBranches() { - checkError("bad variable 'v': int is incompatible with string at 2:3", - "if 1:", - " v = 'a'", - "else:", - " if 0:", - " v = 1\n"); - } - @Test public void testReadOnlyWorksForDifferentLevelBranches() { checkError("Variable v is read only", -- cgit v1.2.3