aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/test/java/com
diff options
context:
space:
mode:
authorGravatar Laurent Le Brun <laurentlb@google.com>2015-04-13 12:15:04 +0000
committerGravatar Lukacs Berki <lberki@google.com>2015-04-13 12:42:44 +0000
commit964d8d55f26341b4e81b38bf0b652d3a8d6a0fac (patch)
tree506023d056ca5dbc64af5cb7f1da806a2133f53b /src/test/java/com
parentc07d9e462a0be4215582eeb95134e0b38b416736 (diff)
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
Diffstat (limited to 'src/test/java/com')
-rw-r--r--src/test/java/com/google/devtools/build/lib/syntax/SkylarkEvaluationTest.java2
-rw-r--r--src/test/java/com/google/devtools/build/lib/syntax/ValidationTests.java243
2 files changed, 1 insertions, 244 deletions
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
@@ -32,71 +32,11 @@ import java.util.Arrays;
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");
}
@@ -126,14 +66,6 @@ public class ValidationTests extends EvaluationTestCase {
}
@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",
"def func2(b):",
@@ -172,18 +104,6 @@ public class ValidationTests extends EvaluationTestCase {
}
@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");
}
@@ -234,20 +154,6 @@ public class ValidationTests extends EvaluationTestCase {
}
@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",
"def bar(): a = foo() + 'a'",
@@ -269,47 +175,6 @@ public class ValidationTests extends EvaluationTestCase {
}
@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",
"['a', 1]");
@@ -384,16 +249,6 @@ public class ValidationTests extends EvaluationTestCase {
}
@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");
parse("2 == None");
@@ -403,37 +258,11 @@ public class ValidationTests extends EvaluationTestCase {
}
@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'",
"def foo(x): return x",
@@ -443,23 +272,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']'",
"def dict():",
@@ -470,24 +282,6 @@ public class ValidationTests extends EvaluationTestCase {
}
@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():",
" s = {}",
@@ -495,12 +289,6 @@ public class ValidationTests extends EvaluationTestCase {
}
@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:",
" v = 'a'",
@@ -523,37 +311,6 @@ public class ValidationTests extends EvaluationTestCase {
}
@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",
"if 1:",