aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/test/java/com/google
diff options
context:
space:
mode:
authorGravatar Laurent Le Brun <laurentlb@google.com>2015-04-15 09:06:46 +0000
committerGravatar Han-Wen Nienhuys <hanwen@google.com>2015-04-15 16:21:30 +0000
commit2e78d6108289de09fb68d3ebb0adfd7f7f372bb6 (patch)
treef032cf38337e321a5891f507a18033bee6e07863 /src/test/java/com/google
parentcf04883e391c9c87379264006090f9d7ac345b7d (diff)
Skylark: Remove static type checks
-- MOS_MIGRATED_REVID=91175430
Diffstat (limited to 'src/test/java/com/google')
-rw-r--r--src/test/java/com/google/devtools/build/lib/syntax/EvaluationTest.java63
-rw-r--r--src/test/java/com/google/devtools/build/lib/syntax/SkylarkEvaluationTest.java14
-rw-r--r--src/test/java/com/google/devtools/build/lib/syntax/ValidationTests.java105
3 files changed, 27 insertions, 155 deletions
diff --git a/src/test/java/com/google/devtools/build/lib/syntax/EvaluationTest.java b/src/test/java/com/google/devtools/build/lib/syntax/EvaluationTest.java
index 9192eaac6d..dc43088330 100644
--- a/src/test/java/com/google/devtools/build/lib/syntax/EvaluationTest.java
+++ b/src/test/java/com/google/devtools/build/lib/syntax/EvaluationTest.java
@@ -86,19 +86,15 @@ public class EvaluationTest extends EvaluationTestCase {
assertEquals(1, eval("1 or 0 and 3"));
assertEquals(Environment.NONE, eval("None and 1"));
+ assertEquals(9, eval("\"\" or 9"));
+ assertEquals("abc", eval("\"abc\" or 9"));
if (isSkylark()) {
checkEvalError("ERROR 1:6: name 'foo' is not defined", "8 or foo");
checkEvalError("ERROR 1:7: name 'foo' is not defined", "0 and foo");
- checkEvalError("ERROR 1:7: bad or operator: int is incompatible with string at 1:1",
- "\"\" or 9");
- checkEvalError("ERROR 1:10: bad or operator: int is incompatible with string at 1:1",
- "\"abc\" or 9");
} else {
assertEquals(8, eval("8 or foo")); // check that 'foo' is not evaluated
assertEquals(0, eval("0 and foo")); // check that 'foo' is not evaluated
- assertEquals(9, eval("\"\" or 9"));
- assertEquals("abc", eval("\"abc\" or 9"));
}
}
@@ -113,12 +109,6 @@ public class EvaluationTest extends EvaluationTestCase {
assertEquals(true, eval("not (0 and 0)"));
assertEquals(false, eval("not (1 or 0)"));
- if (isSkylark()) {
- checkEvalError(
- "ERROR 1:7: bad and operator: bool is incompatible with int at 1:1", "0 and not 0");
- return;
- }
-
assertEquals(0, eval("0 and not 0"));
assertEquals(0, eval("not 0 and 0"));
@@ -148,14 +138,8 @@ public class EvaluationTest extends EvaluationTestCase {
assertEquals(true, eval("'hello' == 'hel' + 'lo'"));
assertEquals(false, eval("'hello' == 'bye'"));
assertEquals(true, eval("None == None"));
-
- if (isSkylark()) {
- checkEvalError("ERROR 1:1: list of ints is not comparable", "[1, 2] == [1, 2]");
- checkEvalError("ERROR 1:1: list of ints is not comparable", "[1, 2] == [2, 1]");
- } else {
- assertEquals(true, eval("[1, 2] == [1, 2]"));
- assertEquals(false, eval("[1, 2] == [2, 1]"));
- }
+ assertEquals(true, eval("[1, 2] == [1, 2]"));
+ assertEquals(false, eval("[1, 2] == [2, 1]"));
}
@Test
@@ -164,13 +148,8 @@ public class EvaluationTest extends EvaluationTestCase {
assertEquals(true, eval("1 != 2"));
assertEquals(false, eval("'hello' != 'hel' + 'lo'"));
assertEquals(true, eval("'hello' != 'bye'"));
- if (isSkylark()) {
- checkEvalError("ERROR 1:1: list of ints is not comparable", "[1, 2] != [1, 2]");
- checkEvalError("ERROR 1:1: list of ints is not comparable", "[1, 2] != [2, 1]");
- } else {
- assertEquals(false, eval("[1, 2] != [1, 2]"));
- assertEquals(true, eval("[1, 2] != [2, 1]"));
- }
+ assertEquals(false, eval("[1, 2] != [1, 2]"));
+ assertEquals(true, eval("[1, 2] != [2, 1]"));
}
@Test
@@ -178,15 +157,8 @@ public class EvaluationTest extends EvaluationTestCase {
assertEquals(true, eval("1 + 3 == 2 + 2"));
assertEquals(true, eval("not 1 == 2"));
assertEquals(false, eval("not 1 != 2"));
- if (isSkylark()) {
- checkEvalError("ERROR 1:7: bad and operator: bool is incompatible with int at 1:1",
- "2 and 3 == 3 or 1");
- checkEvalError("ERROR 1:17: bad and operator: int is incompatible with bool at 1:6",
- "2 or 3 == 3 and 1");
- } else {
- assertEquals(true, eval("2 and 3 == 3 or 1"));
- assertEquals(2, eval("2 or 3 == 3 and 1"));
- }
+ assertEquals(true, eval("2 and 3 == 3 or 1"));
+ assertEquals(2, eval("2 or 3 == 3 and 1"));
}
@Test
@@ -368,6 +340,15 @@ public class EvaluationTest extends EvaluationTestCase {
}
@Test
+ public void testHeterogeneousDict() throws Exception {
+ eval("d = {'str': 1, 2: 3}\n"
+ + "a = d['str']\n"
+ + "b = d[2]");
+ assertThat(lookup("a")).isEqualTo(1);
+ assertThat(lookup("b")).isEqualTo(3);
+ }
+
+ @Test
public void testRecursiveTupleDestructuring() throws Exception {
eval("((a, b), (c, d)) = [(1, 2), (3, 4)]");
assertThat(lookup("a")).isEqualTo(1);
@@ -403,6 +384,13 @@ public class EvaluationTest extends EvaluationTestCase {
}
@Test
+ public void testDictComprehensionOnNonIterable() throws Exception {
+ checkEvalError(
+ "type 'int' is not iterable",
+ "{k : k for k in 3}");
+ }
+
+ @Test
public void testDictComprehensions_MultipleKey() throws Exception {
assertEquals(ImmutableMap.of(1, 1, 2, 2), eval("{x : x for x in [1, 2, 1]}"));
assertEquals(ImmutableMap.of("ab", "ab", "c", "c"),
@@ -481,9 +469,6 @@ public class EvaluationTest extends EvaluationTestCase {
@Test
public void testInCompositeForPrecedence() throws Exception {
- if (isSkylark()) {
- return;
- }
assertEquals(0, eval("not 'a' in ['a'] or 0"));
}
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 744cbd6a21..904eb70bae 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
@@ -827,21 +827,20 @@ public class SkylarkEvaluationTest extends EvaluationTest {
public void testInFail() throws Exception {
checkEvalError("in operator only works on strings if the left operand is also a string",
"1 in '123'");
- checkEvalError("ERROR 1:1: operand 'in' only works on "
- + "strings, dictionaries, lists, sets or tuples, not on a(n) int",
+ checkEvalError("in operator only works on lists, tuples, sets, dicts and strings",
"'a' in 1");
}
@Override
@Test
public void testCompareStringInt() throws Exception {
- checkEvalError("ERROR 1:1: bad comparison: int is incompatible with string at 1:8", "'a' >= 1");
+ checkEvalError("Cannot compare string with int", "'a' >= 1");
}
@Override
@Test
public void testNotComparable() throws Exception {
- checkEvalError("ERROR 1:1: list of ints is not comparable", "[1, 2] < [1, 3]");
+ checkEvalError("[1, 2] is not comparable", "[1, 2] < [1, 3]");
}
@Override
@@ -884,11 +883,4 @@ public class SkylarkEvaluationTest extends EvaluationTest {
eval("def foo(a, b, c): return a+b if c else a-b\n");
assertEquals(18, eval("foo(23, 5, 0)"));
}
-
- @Test
- public void testBadConditionalExpressionInFunction() throws Exception {
- setFailFast(false);
- parseFile("def foo(a): return [] if a else 0\n");
- assertContainsEvent("bad else case: int is incompatible with list at 1:33");
- }
}
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 ce36537444..874c31b2a3 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
@@ -47,16 +47,6 @@ public class ValidationTests extends EvaluationTestCase {
}
@Test
- public void testTwoReturnTypes() throws Exception {
- checkError("bad return type of foo: string is incompatible with int at 3:5",
- "def foo(x):",
- " if x:",
- " return 1",
- " else:",
- " return 'a'");
- }
-
- @Test
public void testTwoFunctionsWithTheSameName() throws Exception {
checkError("function foo already exists",
"def foo():",
@@ -104,27 +94,6 @@ public class ValidationTests extends EvaluationTestCase {
}
@Test
- public void testListIsNotComparable() {
- checkError("list of strings is not comparable", "['a'] > 1");
- }
-
- @Test
- public void testStringCompareToInt() {
- checkError("bad comparison: int is incompatible with string", "'a' > 1");
- }
-
- @Test
- public void testInOnInt() {
- checkError("operand 'in' only works on strings, dictionaries, "
- + "lists, sets or tuples, not on a(n) int", "1 in 2");
- }
-
- @Test
- public void testUnsupportedOperator() {
- checkError("unsupported operand type(s) for -: 'string' and 'int'", "'a' - 1");
- }
-
- @Test
public void testBuiltinSymbolsAreReadOnly() throws Exception {
checkError("Variable rule is read only", "rule = 1");
}
@@ -175,72 +144,16 @@ public class ValidationTests extends EvaluationTestCase {
}
@Test
- public void testListLiteralBadTypes() throws Exception {
- checkError("bad list literal: int is incompatible with string at 1:1",
- "['a', 1]");
- }
-
- @Test
public void testTupleLiteralWorksForDifferentTypes() throws Exception {
parse("('a', 1)");
}
@Test
- public void testDictLiteralBadKeyTypes() throws Exception {
- checkError("bad dict literal: int is incompatible with string at 1:1",
- "{'a': 1, 1: 2}");
- }
-
- @Test
public void testDictLiteralDifferentValueTypeWorks() throws Exception {
parse("{'a': 1, 'b': 'c'}");
}
@Test
- public void testListConcatBadTypes() throws Exception {
- checkError("bad list concatenation: list of ints is incompatible with list of strings at 1:1",
- "['a'] + [1]");
- }
-
- @Test
- public void testDictConcatBadKeyTypes() throws Exception {
- checkError("bad dict concatenation: dict of ints is incompatible with dict of strings at 1:1",
- "{'a': 1} + {1: 2}");
- }
-
- @Test
- public void testDictLiteralBadKeyType() throws Exception {
- checkError("Dict cannot contain composite type 'list of strings' as key", "{['a']: 1}");
- }
-
- @Test
- public void testAndTypeInfer() throws Exception {
- checkError("unsupported operand type(s) for +: 'string' and 'int'", "('a' and 'b') + 1");
- }
-
- @Test
- public void testOrTypeInfer() throws Exception {
- checkError("unsupported operand type(s) for +: 'string' and 'int'", "('' or 'b') + 1");
- }
-
- @Test
- public void testAndDifferentTypes() throws Exception {
- checkError("bad and operator: int is incompatible with string at 1:1",
- "'ab' and 3");
- }
-
- @Test
- public void testOrDifferentTypes() throws Exception {
- checkError("bad or operator: int is incompatible with string at 1:1",
- "'ab' or 3");
- }
-
- @Test
- public void testOrNone() throws Exception {
- parse("a = None or 3");
- }
-
- @Test
public void testNoneAssignment() throws Exception {
parse("def func():",
" a = None",
@@ -257,18 +170,6 @@ public class ValidationTests extends EvaluationTestCase {
parse("5 * None");
}
- @Test
- public void testDictComprehensionNotOnList() throws Exception {
- checkError("Dict comprehension elements must be a list", "{k : k for k in 'abc'}");
- }
-
- @Test
- public void testFuncallArgument() {
- checkError("unsupported operand type(s) for +: 'int' and 'string'",
- "def foo(x): return x",
- "a = foo(1 + 'a')");
- }
-
// Skylark built-in functions specific tests
@Test
@@ -391,12 +292,6 @@ public class ValidationTests extends EvaluationTestCase {
}
@Test
- public void testFilesModulePlusStringErrorMessage() throws Exception {
- checkError("unsupported operand type(s) for +: 'cmd_helper (a language module)' and 'string'",
- "cmd_helper += 'a'");
- }
-
- @Test
public void testFunctionReturnsFunction() {
parse(
"def impl(ctx):",