I’d like to modify cake test so that it operates with a different value for *stack-trace-depth*.
The built-in definition is simply:
(deftask test #{compile}
"Run project tests."
"Specify which tests to run as arguments like: namespace, namespace/function, or :tag"
(run-project-tests))
Ideally I’d like to specify the value with the command-line argument --depth=n, something to this effect:
(binding [*stack-trace-depth* (if (*opts* :depth)
(read-string (*opts* :depth)))]
(run-project-tests))
What code do I need to make this work?
Based on responses: Putting the following in tasks.clj
(undeftask test)
(deftask test #{compile}
(.bindRoot #'*stack-trace-depth* 5)
(println "Defining task: *stack-trace-depth* is" *stack-trace-depth* "in" (Thread/currentThread))
(run-project-tests))
produces the following output:
Loading
test/cake_test/core.clj:Loading tests: *stack-trace-depth* is nil in #<Thread[thread-13,5,main]>
$ cake testDefining task: *stack-trace-depth* is 5 in #<Thread[Thread-18,5,main]> In test: *stack-trace-depth* is nil in #<Thread[Thread-16,5,main]> Testing cake-testing.core FAIL in (test-stack-trace-depth) (core.clj:8) expected: (= *stack-trace-depth* 5) actual: (not (= nil 5)) Ran 1 tests containing 1 assertions. 1 failures, 0 errors. ---- Finished in 0.011865 seconds.
(Tested code is on Gist.)
(Update: threw out the original answer, here’s what seems to be a working solution.)
I took the sample project from your Gist and made the following changes:
rm tasks.cljAdded the following code to
project.cljbelow thedefprojectform:Created a new file,
test/cake_testing/core_test.cljwith the following contents:At this point, everything seems to work —
cake testoutputsAlso, adding in a “test” which deliberately throws an exception results in a nice, short stack trace being printed.