aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/test/java/com/google/devtools/build/lib/syntax
diff options
context:
space:
mode:
authorGravatar Florian Weikert <fwe@google.com>2015-08-26 14:06:58 +0000
committerGravatar Philipp Wollermann <philwo@google.com>2015-08-27 14:44:19 +0000
commitc1d54ec8fabdcc6c04fc7eb77e110d29c6015acd (patch)
treebf7362065c17363b42616ea0cacd6cb52eeabad4 /src/test/java/com/google/devtools/build/lib/syntax
parent48114109eb89bed684f2085a1ec2ddc3fa9ea902 (diff)
Skylark stack traces are now displayed in Python format.
-- MOS_MIGRATED_REVID=101572295
Diffstat (limited to 'src/test/java/com/google/devtools/build/lib/syntax')
-rw-r--r--src/test/java/com/google/devtools/build/lib/syntax/MethodLibraryTest.java39
-rw-r--r--src/test/java/com/google/devtools/build/lib/syntax/SkylarkEvaluationTest.java58
2 files changed, 64 insertions, 33 deletions
diff --git a/src/test/java/com/google/devtools/build/lib/syntax/MethodLibraryTest.java b/src/test/java/com/google/devtools/build/lib/syntax/MethodLibraryTest.java
index 1a489d29e1..29a94593c6 100644
--- a/src/test/java/com/google/devtools/build/lib/syntax/MethodLibraryTest.java
+++ b/src/test/java/com/google/devtools/build/lib/syntax/MethodLibraryTest.java
@@ -42,18 +42,35 @@ public class MethodLibraryTest extends EvaluationTestCase {
}
@Test
+ public void testStackTraceSkipBuiltInOnly() throws Exception {
+ // The error message should not include the stack trace when there is
+ // only one built-in function.
+ new SkylarkTest()
+ .testIfExactError(
+ "Method string.index(sub: string, start: int, end: int or NoneType) is not applicable "
+ + "for arguments (int, int, NoneType): 'sub' is int, but should be string",
+ "'test'.index(1)");
+ }
+
+ @Test
public void testStackTrace() throws Exception {
- new SkylarkTest().testIfExactError(
- "Method string.index(sub: string, start: int, end: int or NoneType) is not "
- + "applicable for arguments (int, int, NoneType): 'sub' is int, but should be string\n"
- + "\tin string.index [Built-In]\n"
- + "\tin bar [4:4]\n"
- + "\tin foo [2:4]",
- "def foo():",
- " bar(1)",
- "def bar(x):",
- " 'test'.index(x)",
- "foo()");
+ // Unlike SkylarintegrationTests#testStackTraceErrorInFunction(), this test
+ // has neither a BUILD nor a bzl file.
+ new SkylarkTest()
+ .testIfExactError(
+ "Traceback (most recent call last):\n"
+ + "\tFile \"<unknown>\", line 2, in foo\n"
+ + "\t\tbar\n"
+ + "\tFile \"<unknown>\", line 4, in bar\n"
+ + "\t\tstring.index\n"
+ + "Method string.index(sub: string, start: int, end: int or NoneType) "
+ + "is not applicable "
+ + "for arguments (int, int, NoneType): 'sub' is int, but should be string",
+ "def foo():",
+ " bar(1)",
+ "def bar(x):",
+ " 'test'.index(x)",
+ "foo()");
}
@Test
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 22c715358e..b11866dc0b 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
@@ -283,8 +283,11 @@ public class SkylarkEvaluationTest extends EvaluationTest {
public void testForNotIterable() throws Exception {
new SkylarkTest()
.update("mock", new Mock())
- .testIfExactError("type 'int' is not iterable", "def func():",
- " for i in mock.value_of('1'): a = i", "func()\n");
+ .testIfErrorContains(
+ "type 'int' is not iterable",
+ "def func():",
+ " for i in mock.value_of('1'): a = i",
+ "func()\n");
}
@Test
@@ -777,14 +780,16 @@ public class SkylarkEvaluationTest extends EvaluationTest {
@Test
public void testListIndexAsLValueAsLValue() throws Exception {
- new SkylarkTest().testIfExactError("unsupported operand type(s) for +: 'list' and 'dict'",
- "def id(l):",
- " return l",
- "def func():",
- " l = id([1])",
- " l[0] = 2",
- " return l",
- "l = func()");
+ new SkylarkTest()
+ .testIfErrorContains(
+ "unsupported operand type(s) for +: 'list' and 'dict'",
+ "def id(l):",
+ " return l",
+ "def func():",
+ " l = id([1])",
+ " l[0] = 2",
+ " return l",
+ "l = func()");
}
@Test
@@ -987,23 +992,32 @@ public class SkylarkEvaluationTest extends EvaluationTest {
@Override
@Test
public void testListComprehensionsMultipleVariablesFail() throws Exception {
- new SkylarkTest().testIfExactError("lvalue has length 3, but rvalue has has length 2",
- "def foo (): return [x + y for x, y, z in [(1, 2), (3, 4)]]",
- "foo()");
+ new SkylarkTest()
+ .testIfErrorContains(
+ "lvalue has length 3, but rvalue has has length 2",
+ "def foo (): return [x + y for x, y, z in [(1, 2), (3, 4)]]",
+ "foo()");
- new SkylarkTest().testIfExactError("type 'int' is not a collection",
- "def bar (): return [x + y for x, y in (1, 2)]",
- "bar()");
+ new SkylarkTest()
+ .testIfErrorContains(
+ "type 'int' is not a collection",
+ "def bar (): return [x + y for x, y in (1, 2)]",
+ "bar()");
- new SkylarkTest().testIfExactError("lvalue has length 3, but rvalue has has length 2",
- "[x + y for x, y, z in [(1, 2), (3, 4)]]");
+ new SkylarkTest()
+ .testIfErrorContains(
+ "lvalue has length 3, but rvalue has has length 2",
+ "[x + y for x, y, z in [(1, 2), (3, 4)]]");
// can't reuse the same local variable twice(!)
- new SkylarkTest().testIfExactError("ERROR 2:1: Variable x is read only",
- "[x + y for x, y in (1, 2)]", "[x + y for x, y in (1, 2)]");
+ new SkylarkTest()
+ .testIfErrorContains(
+ "ERROR 2:1: Variable x is read only",
+ "[x + y for x, y in (1, 2)]",
+ "[x + y for x, y in (1, 2)]");
- new SkylarkTest().testIfExactError("type 'int' is not a collection",
- "[x2 + y2 for x2, y2 in (1, 2)]");
+ new SkylarkTest()
+ .testIfErrorContains("type 'int' is not a collection", "[x2 + y2 for x2, y2 in (1, 2)]");
}
@Override