aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'src/test')
-rw-r--r--src/test/java/com/google/devtools/build/lib/syntax/ExceptionTest.java5
-rw-r--r--src/test/java/com/google/devtools/build/lib/syntax/MethodLibraryTest.java46
2 files changed, 44 insertions, 7 deletions
diff --git a/src/test/java/com/google/devtools/build/lib/syntax/ExceptionTest.java b/src/test/java/com/google/devtools/build/lib/syntax/ExceptionTest.java
index dd2e83156a..4e71d61ce4 100644
--- a/src/test/java/com/google/devtools/build/lib/syntax/ExceptionTest.java
+++ b/src/test/java/com/google/devtools/build/lib/syntax/ExceptionTest.java
@@ -26,11 +26,12 @@ import org.junit.runners.JUnit4;
*/
@RunWith(JUnit4.class)
public class ExceptionTest {
+ private static final ASTNode DUMMY_NODE = new Identifier("DUMMY");
@Test
public void testEmptyMessage() throws Exception {
EvalExceptionWithStackTrace ex =
- new EvalExceptionWithStackTrace(new NullPointerException(), Location.BUILTIN);
+ new EvalExceptionWithStackTrace(new NullPointerException(), DUMMY_NODE);
assertThat(ex.getMessage())
.contains("Null Pointer: ExceptionTest.testEmptyMessage() in ExceptionTest.java:");
}
@@ -45,7 +46,7 @@ public class ExceptionTest {
}
private void runExceptionTest(Exception toThrow, Exception expectedCause) {
- EvalExceptionWithStackTrace ex = new EvalExceptionWithStackTrace(toThrow, Location.BUILTIN);
+ EvalExceptionWithStackTrace ex = new EvalExceptionWithStackTrace(toThrow, DUMMY_NODE);
assertThat(ex.getCause()).isEqualTo(expectedCause);
}
}
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 60536e36f5..c7ab9da7cc 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,6 +42,39 @@ public class MethodLibraryTest extends EvaluationTestCase {
}
@Test
+ public void testStackTraceLocation() throws Exception {
+ new SkylarkTest().testIfErrorContains(
+ "Traceback (most recent call last):\n\t"
+ + "File \"<unknown>\", line 8\n\t\t"
+ + "foo()\n\t"
+ + "File \"<unknown>\", line 2, in foo\n\t\t"
+ + "bar(1)\n\t"
+ + "File \"<unknown>\", line 7, in bar\n\t\t"
+ + "'test'.index(x)",
+ "def foo():",
+ " bar(1)",
+ "def bar(x):",
+ " if x == 1:",
+ " a = x",
+ " b = 2",
+ " 'test'.index(x)",
+ "foo()");
+ }
+
+ @Test
+ public void testStackTraceWithIf() throws Exception {
+ new SkylarkTest().testIfErrorContains(
+ "File \"<unknown>\", line 5\n\t\t"
+ + "foo()\n\t"
+ + "File \"<unknown>\", line 3, in foo\n\t\ts[0]",
+ "def foo():",
+ " s = set()",
+ " if s[0] == 1:",
+ " x = 1",
+ "foo()");
+ }
+
+ @Test
public void testStackTraceSkipBuiltInOnly() throws Exception {
// The error message should not include the stack trace when there is
// only one built-in function.
@@ -59,17 +92,20 @@ public class MethodLibraryTest extends EvaluationTestCase {
new SkylarkTest()
.testIfExactError(
"Traceback (most recent call last):\n"
+ + "\tFile \"<unknown>\", line 6\n"
+ + "\t\tfoo()\n"
+ "\tFile \"<unknown>\", line 2, in foo\n"
- + "\t\tbar\n"
- + "\tFile \"<unknown>\", line 4, in bar\n"
- + "\t\tstring.index\n"
+ + "\t\tbar(1)\n"
+ + "\tFile \"<unknown>\", line 5, in bar\n"
+ + "\t\t'test'.index(x)\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)",
+ " bar(1)",
"def bar(x):",
- " 'test'.index(x)",
+ " if 1 == 1:",
+ " 'test'.index(x)",
"foo()");
}