We're updating the issue view to help you get more done. 

Direct-linking breaks clojure.test do-report stack-depth assumptions for failure reporting.


Test failure locations are being mis-reported (wrong class/line number).

Given a test ns:

1 2 3 4 5 6 7 8 (ns test1856.core-test (:require [clojure.test :refer :all] [test1856.core :refer :all])) (deftest fail-test ;; 6 ;; 7 (is (= nil true))) ;; 8

The results with 1.8-RC2 (with CLJ-1854 patch included) are:

1 2 3 FAIL in (fail-test) (test.clj:342) ;; WRONG, expected: (core_test.clj:8) expected: (= nil true) actual: (not (= nil true))

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.
2. Drop top frames while their class name starts with java.lang (this filters the call to java.lang.Thread.getStackTrace()) or clojure.test. The top frame will then be in the user's code.
3. Deprecated old file-and-line function (not sure if other clojure test reporting frameworks use this, despite it being private).
4. Updated tests that check that these functions work with an empty stack trace, as the JVM may elide it.

Patch: clj-1856.patch







Gary Trakhman






Fix versions

Affects versions

Release 1.8