aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/test
diff options
context:
space:
mode:
authorGravatar brandjon <brandjon@google.com>2018-01-17 10:40:38 -0800
committerGravatar Copybara-Service <copybara-piper@google.com>2018-01-17 10:42:33 -0800
commitaadf6600faa099726b2e1c00e75b0edc9d95bfb8 (patch)
tree2aa172c99124ff5ac04c6af9acd3e28d3bef0336 /src/test
parent70ec04ad08b250c34b1ce455b1faa25228ef8a2f (diff)
Fix forbidding of If statements in BUILD files
The bug also permitted For statements in BUILD files so long as they were contained within an If statement (i.e. not at the top level). Also add minor guidance to error messages. RELNOTES: None PiperOrigin-RevId: 182236172
Diffstat (limited to 'src/test')
-rw-r--r--src/test/java/com/google/devtools/build/lib/syntax/ParserTest.java56
1 files changed, 34 insertions, 22 deletions
diff --git a/src/test/java/com/google/devtools/build/lib/syntax/ParserTest.java b/src/test/java/com/google/devtools/build/lib/syntax/ParserTest.java
index c618d6f65e..f3fbe1e63f 100644
--- a/src/test/java/com/google/devtools/build/lib/syntax/ParserTest.java
+++ b/src/test/java/com/google/devtools/build/lib/syntax/ParserTest.java
@@ -76,13 +76,13 @@ public class ParserTest extends EvaluationTestCase {
}
// helper func for testListLiterals:
- private static DictionaryEntryLiteral getElem(DictionaryLiteral list, int index) {
- return list.getEntries().get(index);
+ private static int getIntElem(ListLiteral list, int index) {
+ return ((IntegerLiteral) list.getElements().get(index)).getValue();
}
// helper func for testListLiterals:
- private static int getIntElem(ListLiteral list, int index) {
- return ((IntegerLiteral) list.getElements().get(index)).getValue();
+ private static DictionaryEntryLiteral getElem(DictionaryLiteral list, int index) {
+ return list.getEntries().get(index);
}
// helper func for testListLiterals:
@@ -1347,20 +1347,6 @@ public class ParserTest extends EvaluationTestCase {
}
@Test
- public void testKwargsForbidden() throws Exception {
- setFailFast(false);
- parseFile("func(**dict)");
- assertContainsError("**kwargs arguments are not allowed in BUILD files");
- }
-
- @Test
- public void testArgsForbidden() throws Exception {
- setFailFast(false);
- parseFile("func(*array)");
- assertContainsError("*args arguments are not allowed in BUILD files");
- }
-
- @Test
public void testOptionalArgBeforeMandatoryArgInFuncDef() throws Exception {
setFailFast(false);
parseFileForSkylark("def func(a, b = 'a', c):\n return 0\n");
@@ -1470,9 +1456,35 @@ public class ParserTest extends EvaluationTestCase {
@Test
public void testDefInBuild() throws Exception {
setFailFast(false);
- BuildFileAST result = parseFileWithComments("def func(): pass");
- assertContainsError("syntax error at 'def': This is not supported in BUILD files. "
- + "Move the block to a .bzl file and load it");
- assertThat(result.containsErrors()).isTrue();
+ parseFile("def func(): pass");
+ assertContainsError("function definitions are not allowed in BUILD files");
+ }
+
+ @Test
+ public void testForStatementForbiddenInBuild() throws Exception {
+ setFailFast(false);
+ parseFile("for _ in []: pass");
+ assertContainsError("for statements are not allowed in BUILD files");
+ }
+
+ @Test
+ public void testIfStatementForbiddenInBuild() throws Exception {
+ setFailFast(false);
+ parseFile("if False: pass");
+ assertContainsError("if statements are not allowed in BUILD files");
+ }
+
+ @Test
+ public void testKwargsForbiddenInBuild() throws Exception {
+ setFailFast(false);
+ parseFile("func(**dict)");
+ assertContainsError("**kwargs arguments are not allowed in BUILD files");
+ }
+
+ @Test
+ public void testArgsForbiddenInBuild() throws Exception {
+ setFailFast(false);
+ parseFile("func(*array)");
+ assertContainsError("*args arguments are not allowed in BUILD files");
}
}