From ab58a9244bfccbc80fc3970329a36ce6ee3d4006 Mon Sep 17 00:00:00 2001 From: laurentlb Date: Tue, 22 Aug 2017 16:45:28 +0200 Subject: Remove dialect distinction from the parser. RELNOTES: None. PiperOrigin-RevId: 166058718 --- .../devtools/build/lib/syntax/ParserTest.java | 51 ++++------------------ .../build/lib/syntax/util/EvaluationTestCase.java | 14 ++---- 2 files changed, 12 insertions(+), 53 deletions(-) (limited to 'src/test/java/com/google/devtools/build/lib/syntax') 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 @@ -913,22 +913,6 @@ public class ParserTest extends EvaluationTestCase { assertContainsError("syntax error at ';'"); } - @Test - public void testFunctionDefinitionErrorRecovery() throws Exception { - // Parser skips over entire function definitions, and reports a meaningful - // error. - setFailFast(false); - List 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 statements = parseFileForSkylark( @@ -954,19 +938,6 @@ public class ParserTest extends EvaluationTestCase { assertThat(stmt.getStatements()).isEmpty(); } - @Test - public void testSkipIfBlockFail() throws Exception { - // Do not parse 'if' blocks, when parsePython is not set - setFailFast(false); - List 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 stmts1 = parseFile("[ i for i, j, k in [(1, 2, 3)] ]\n"); @@ -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 { -- cgit v1.2.3