1

I am attempting to replace the stacktrace-file-and-line (private) function in clojure.test, but using with-redefs-fn when running tests seems to have no effect. When I execute the following code the original stacktrace-file-and-line is called instead of my anonymous function.

(with-redefs-fn 
 {#'clojure.test/stacktrace-file-and-line (fn [stacktrace] {:file "foo.clj" :line 1})}
 #(clojure.test/run-tests 'repl-test.core-test))

Does with-redefs-fn not work with private function or is there something about the clojure.test namespace that is preventing this from working?

James
  • 475
  • 4
  • 12

1 Answers1

2

I suspect that clojure.test is compiled with direct linking and thus causing that with-redefs-fn and with-redefs won't work.

Piotrek Bzdyl
  • 12,965
  • 1
  • 31
  • 49
  • Based on this "As of Clojure 1.8, the Clojure core library itself is compiled with direct linking." I think you are correct. – James Mar 27 '17 at 19:55
  • I've checked the Clojure code build files (e.g. ant build.xml or maven pom.xml) and they have direct-linking property set to true but I didn't analysed if they are used for the jars published in maven central. – Piotrek Bzdyl Mar 27 '17 at 19:57