[CLJ-1856] Direct-linking breaks clojure.test do-report stack-depth assumptions for failure reporting. Created: 24/Nov/15 Updated: 25/Nov/15
|Affects Version/s:||Release 1.8|
|Fix Version/s:||Release 1.8|
Test failure locations are being mis-reported (wrong class/line number).
Given a test ns:
The results with 1.8-RC2 (with
Cause: The location of the error is calculated in test.clj by constructing a Throwable in do-report and then dropping the top 1 frame (which is do-report itself) to find the user frame where the assertion failed. However, with direct linking there are now 2 frames on top of of the failure in user code, so the same (incorrect) location in test.clj is reported every time.
Approach: Change to a different strategy to filter the top frames based on content, not hard-coded depth. This strategy will work regardless of whether direct linking is involved or not.
1. Instead of constructing an exception and using it's stack trace, instead call Thread.getStackTrace() on the current thread. Create a new function that works on stack traces rather than exceptions and no longer needs a depth check.
|Comment by Gary Trakhman [ 24/Nov/15 4:35 PM ]|
'2' works in the standard case of direct-linked clojure with non-direct-linked app code. I'm exploring if there's a way to get the line info via macro-expansion of 'try-expr' and passing the line value into do-report for those cases.
|Comment by Gary Trakhman [ 24/Nov/15 4:54 PM ]|
I altered a local clojure build to print the stacktrace of the Throwable created by do-report, showing the additional invokeStatic frames during a repl session, showing the first user function frame is at offset 2.
This is also with the patch from http://dev.clojure.org/jira/browse/CLJ-1854 applied
|Comment by Alex Miller [ 25/Nov/15 1:26 PM ]|
If I lein test (or run from repl), I see: