diff options
author | laurentlb <laurentlb@google.com> | 2017-08-22 16:45:28 +0200 |
---|---|---|
committer | Damien Martin-Guillerez <dmarting@google.com> | 2017-08-22 17:45:44 +0200 |
commit | ab58a9244bfccbc80fc3970329a36ce6ee3d4006 (patch) | |
tree | 2ab8d4d3ab947467e27b3cd55bf787a94e25bb48 /src/test/java/com/google/devtools/build/lib/syntax | |
parent | f129657059d79fc0d4363244d698f295866d91f6 (diff) |
Remove dialect distinction from the parser.
RELNOTES: None.
PiperOrigin-RevId: 166058718
Diffstat (limited to 'src/test/java/com/google/devtools/build/lib/syntax')
-rw-r--r-- | src/test/java/com/google/devtools/build/lib/syntax/ParserTest.java | 51 | ||||
-rw-r--r-- | src/test/java/com/google/devtools/build/lib/syntax/util/EvaluationTestCase.java | 14 |
2 files changed, 12 insertions, 53 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 784b0a7926..94cdb30105 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 @@ -914,22 +914,6 @@ public class ParserTest extends EvaluationTestCase { } @Test - public void testFunctionDefinitionErrorRecovery() throws Exception { - // Parser skips over entire function definitions, and reports a meaningful - // error. - setFailFast(false); - List<Statement> stmts = parseFile( - "x = 1;\n" - + "def foo(x, y, **z):\n" - + " # a comment\n" - + " x = 2\n" - + " foo(bar)\n" - + " return z\n" - + "x = 3"); - assertThat(stmts).hasSize(2); - } - - @Test public void testDefSingleLine() throws Exception { List<Statement> statements = parseFileForSkylark( "def foo(): x = 1; y = 2\n"); @@ -955,19 +939,6 @@ public class ParserTest extends EvaluationTestCase { } @Test - public void testSkipIfBlockFail() throws Exception { - // Do not parse 'if' blocks, when parsePython is not set - setFailFast(false); - List<Statement> stmts = parseFile( - "x = 1;", - "if x == 1:", - " x = 2", - "x = 3;\n"); - assertThat(stmts).hasSize(2); - assertContainsError("This is not supported in BUILD files"); - } - - @Test public void testForLoopMultipleVariables() throws Exception { List<Statement> stmts1 = parseFile("[ i for i, j, k in [(1, 2, 3)] ]\n"); assertThat(stmts1).hasSize(1); @@ -1402,7 +1373,7 @@ public class ParserTest extends EvaluationTestCase { "def func(a):", // no if " else: return a"); - assertContainsError("syntax error at 'else': not allowed here."); + assertContainsError("syntax error at 'else': expected expression"); } @Test @@ -1413,42 +1384,36 @@ public class ParserTest extends EvaluationTestCase { " for i in range(a):", " print(i)", " else: return a"); - assertContainsError("syntax error at 'else': not allowed here."); + assertContainsError("syntax error at 'else': expected expression"); } @Test public void testTryStatementInBuild() throws Exception { setFailFast(false); parseFile("try: pass"); - assertContainsError("syntax error at 'try': Try statements are not supported."); - } - - @Test - public void testTryStatementInSkylark() throws Exception { - setFailFast(false); - parseFileForSkylark("try: pass"); - assertContainsError("syntax error at 'try': Try statements are not supported."); + assertContainsError("'try' not supported, all exceptions are fatal"); } @Test public void testClassDefinitionInBuild() throws Exception { setFailFast(false); - parseFile("class test(object): pass"); - assertContainsError("syntax error at 'class': Class definitions are not supported."); + parseFileWithComments("class test(object): pass"); + assertContainsError("keyword 'class' not supported"); } @Test public void testClassDefinitionInSkylark() throws Exception { setFailFast(false); parseFileForSkylark("class test(object): pass"); - assertContainsError("syntax error at 'class': Class definitions are not supported."); + assertContainsError("keyword 'class' not supported"); } @Test public void testDefInBuild() throws Exception { setFailFast(false); - parseFile("def func(): pass"); + 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(); } } diff --git a/src/test/java/com/google/devtools/build/lib/syntax/util/EvaluationTestCase.java b/src/test/java/com/google/devtools/build/lib/syntax/util/EvaluationTestCase.java index ceeffe74eb..4d52f6f51c 100644 --- a/src/test/java/com/google/devtools/build/lib/syntax/util/EvaluationTestCase.java +++ b/src/test/java/com/google/devtools/build/lib/syntax/util/EvaluationTestCase.java @@ -159,30 +159,24 @@ public class EvaluationTestCase { /** Parses a statement, possibly followed by newlines. */ protected Statement parseStatement(Parser.ParsingLevel parsingLevel, String... input) { - return Parser.parseStatement( - makeParserInputSource(input), getEventHandler(), - parsingLevel, Parser.Dialect.SKYLARK); + return Parser.parseStatement(makeParserInputSource(input), getEventHandler(), parsingLevel); } /** Parses a top-level statement, possibly followed by newlines. */ protected Statement parseTopLevelStatement(String... input) { return Parser.parseStatement( - makeParserInputSource(input), getEventHandler(), - Parser.ParsingLevel.TOP_LEVEL, Parser.Dialect.SKYLARK); + makeParserInputSource(input), getEventHandler(), Parser.ParsingLevel.TOP_LEVEL); } /** Parses a local statement, possibly followed by newlines. */ protected Statement parseLocalLevelStatement(String... input) { return Parser.parseStatement( - makeParserInputSource(input), getEventHandler(), - Parser.ParsingLevel.LOCAL_LEVEL, Parser.Dialect.SKYLARK); + makeParserInputSource(input), getEventHandler(), Parser.ParsingLevel.LOCAL_LEVEL); } /** Parses an expression, possibly followed by newlines. */ protected Expression parseExpression(String... input) { - return Parser.parseExpression( - makeParserInputSource(input), getEventHandler(), - Parser.Dialect.SKYLARK); + return Parser.parseExpression(makeParserInputSource(input), getEventHandler()); } public EvaluationTestCase update(String varname, Object value) throws Exception { |