From d3a039b1b755110c3bb8cb249bac4a417a0c693b Mon Sep 17 00:00:00 2001 From: laurentlb Date: Mon, 19 Jun 2017 12:34:12 -0400 Subject: Move some Skylark tests out of Java. RELNOTES: None. PiperOrigin-RevId: 159436969 --- .../java/com/google/devtools/skylark/Skylark.java | 11 +- .../devtools/build/lib/syntax/EvaluationTest.java | 120 --------------------- 2 files changed, 10 insertions(+), 121 deletions(-) (limited to 'src') diff --git a/src/main/java/com/google/devtools/skylark/Skylark.java b/src/main/java/com/google/devtools/skylark/Skylark.java index 1a0f9c9deb..9f1181eb20 100644 --- a/src/main/java/com/google/devtools/skylark/Skylark.java +++ b/src/main/java/com/google/devtools/skylark/Skylark.java @@ -15,8 +15,10 @@ package com.google.devtools.skylark; import com.google.devtools.build.lib.events.Event; import com.google.devtools.build.lib.events.EventHandler; +import com.google.devtools.build.lib.events.EventKind; import com.google.devtools.build.lib.syntax.BuildFileAST; import com.google.devtools.build.lib.syntax.Environment; +import com.google.devtools.build.lib.syntax.EvalException; import com.google.devtools.build.lib.syntax.Mutability; import com.google.devtools.build.lib.syntax.Printer; import java.io.BufferedReader; @@ -39,7 +41,11 @@ class Skylark { new EventHandler() { @Override public void handle(Event event) { - System.out.println(event.getMessage()); + if (event.getKind() == EventKind.ERROR) { + System.err.println(event.getMessage()); + } else { + System.out.println(event.getMessage()); + } } }; @@ -95,6 +101,9 @@ class Skylark { content = new String(Files.readAllBytes(Paths.get(path)), StandardCharsets.UTF_8); BuildFileAST.eval(env, content); return 0; + } catch (EvalException e) { + System.err.println(e.print()); + return 1; } catch (Exception e) { System.err.println(e); return 1; 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 dc2d021bdb..a3251da4f3 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 @@ -71,126 +71,6 @@ public class EvaluationTest extends EvaluationTestCase { newTest().testStatement("'%sY%s' % ('X', 'Z')", "XYZ"); } - @Test - public void testAndOr() throws Exception { - new BuildTest() - .testStatement("8 or 9", 8) - .testStatement("0 or 9", 9) - .testStatement("8 and 9", 9) - .testStatement("0 and 9", 0) - - .testStatement("1 and 2 or 3", 2) - .testStatement("0 and 2 or 3", 3) - .testStatement("1 and 0 or 3", 3) - - .testStatement("1 or 2 and 3", 1) - .testStatement("0 or 2 and 3", 3) - .testStatement("0 or 0 and 3", 0) - .testStatement("1 or 0 and 3", 1) - - .testStatement("None and 1", Runtime.NONE) - .testStatement("\"\" or 9", 9) - .testStatement("\"abc\" or 9", "abc") - - // check that 'foo' is not evaluated - .testStatement("8 or foo", 8) - .testStatement("0 and foo", 0); - - new SkylarkTest() - .testIfErrorContains("name 'google' is not defined", "0 and google") - .testIfErrorContains("name 'google' is not defined", "8 or google"); - } - - @Test - public void testNot() throws Exception { - newTest().testStatement("not 1", false).testStatement("not ''", true); - } - - @Test - public void testNotWithLogicOperators() throws Exception { - newTest() - .testStatement("not (0 and 0)", true) - .testStatement("not (1 or 0)", false) - - .testStatement("0 and not 0", 0) - .testStatement("not 0 and 0", 0) - - .testStatement("1 and not 0", true) - .testStatement("not 0 or 0", true) - - .testStatement("not 1 or 0", 0) - .testStatement("not 1 or 1", 1); - } - - @Test - public void testNotWithArithmeticOperators() throws Exception { - newTest().testStatement("not 0 + 0", true).testStatement("not 2 - 1", false); - } - - @Test - public void testNotWithCollections() throws Exception { - newTest().testStatement("not []", true).testStatement("not {'a' : 1}", false); - } - - @Test - public void testEquality() throws Exception { - newTest() - .testStatement("1 == 1", true) - .testStatement("1 == 2", false) - .testStatement("'hello' == 'hel' + 'lo'", true) - .testStatement("'hello' == 'bye'", false) - .testStatement("None == None", true) - .testStatement("[1, 2] == [1, 2]", true) - .testStatement("[1, 2] == [2, 1]", false) - .testStatement("{'a': 1, 'b': 2} == {'b': 2, 'a': 1}", true) - .testStatement("{'a': 1, 'b': 2} == {'a': 1}", false) - .testStatement("{'a': 1, 'b': 2} == {'a': 1, 'b': 2, 'c': 3}", false) - .testStatement("{'a': 1, 'b': 2} == {'a': 1, 'b': 3}", false); - } - - @Test - public void testInequality() throws Exception { - newTest() - .testStatement("1 != 1", false) - .testStatement("1 != 2", true) - .testStatement("'hello' != 'hel' + 'lo'", false) - .testStatement("'hello' != 'bye'", true) - .testStatement("[1, 2] != [1, 2]", false) - .testStatement("[1, 2] != [2, 1]", true) - .testStatement("{'a': 1, 'b': 2} != {'b': 2, 'a': 1}", false) - .testStatement("{'a': 1, 'b': 2} != {'a': 1}", true) - .testStatement("{'a': 1, 'b': 2} != {'a': 1, 'b': 2, 'c': 3}", true) - .testStatement("{'a': 1, 'b': 2} != {'a': 1, 'b': 3}", true); - } - - @Test - public void testEqualityPrecedence() throws Exception { - newTest() - .testStatement("1 + 3 == 2 + 2", true) - .testStatement("not 1 == 2", true) - .testStatement("not 1 != 2", false) - .testStatement("2 and 3 == 3 or 1", true) - .testStatement("2 or 3 == 3 and 1", 2); - } - - @Test - public void testLessThan() throws Exception { - newTest() - .testStatement("1 <= 1", true) - .testStatement("1 < 1", false) - .testStatement("'a' <= 'b'", true) - .testStatement("'c' < 'a'", false); - } - - @Test - public void testGreaterThan() throws Exception { - newTest() - .testStatement("1 >= 1", true) - .testStatement("1 > 1", false) - .testStatement("'a' >= 'b'", false) - .testStatement("'c' > 'a'", true); - } - @Test public void testConditionalExpressions() throws Exception { newTest() -- cgit v1.2.3