diff options
author | Florian Weikert <fwe@google.com> | 2015-09-11 13:43:10 +0000 |
---|---|---|
committer | Damien Martin-Guillerez <dmarting@google.com> | 2015-09-11 14:22:37 +0000 |
commit | 90a159670963ff30eda0c05af565ebee3812de60 (patch) | |
tree | 45929142c20660bf0967af9f050438cc26370a09 /src/test/java/com/google/devtools | |
parent | 6a832d042d53a448bf7e7c89a72a01b66d7aac6a (diff) |
Fixed Skylark stack trace:
- Moved registration mechanism from BaseFunction into ASTNode / Statement / Expression
- Added more details about statements/expressions to the output trace (including if's)
- Fixed wrong locations
--
MOS_MIGRATED_REVID=102841164
Diffstat (limited to 'src/test/java/com/google/devtools')
-rw-r--r-- | src/test/java/com/google/devtools/build/lib/syntax/ExceptionTest.java | 5 | ||||
-rw-r--r-- | src/test/java/com/google/devtools/build/lib/syntax/MethodLibraryTest.java | 46 |
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()"); } |