I've been very happy with pjstadig/humane-test-output for projects using lein, by adding it to my :user profile (`.lein/profiles.clj`).
I would like a similar setup for projects using deps.edn (`clj -X:test`), but I cannot see a good way forward. Any pointers on if and how this could be possible?
Thanks for the explanation and example @seancorfield
I have never seen requiring-resolve before, so I would probably have stumbled for a long while before, figuring that one out.
I ended up with the following in my "user" deps.edn :
:humane {:extra-deps {pjstadig/humane-test-output {:mvn/version "0.11.0"}
io.github.cognitect-labs/test-runner {:git/tag "v0.5.1" :git/sha "dfb30dd"}}
:main-opts ["-e" "((requiring-resolve 'pjstadig.humane-test-output/activate!))"
"-m" "cognitect.test-runner"]}
Assuming :test alias will be used for tests in the various projects, I hope I will be able to pop "humane test output" on top using: clj -M:test:humaneWhat exactly do you have in your :test alias?
Eftest returns similar output by default , I suspect kaocha also has options for this. But these are full runners, not just a reporter
That said both are great options
I use HTO with deps.edn in my Expectations library, but I have a piece of code that attempts to resolve and call pjstadig.humane-test-output/activate! explicitly in Expectations -- so if it's on the classpath (via an alias), it gets activated automatically.
:test {:extra-paths ["test/unit"]
:extra-deps {io.github.cognitect-labs/test-runner {:git/tag "v0.5.1" :git/sha "dfb30dd"}}
:main-opts ["-m" "cognitect.test-runner"]
:exec-fn cognitect.test-runner.api/test}If you want to stick with the Cognitect test runner for simplicity, you could have a small wrapper for cognitect.test-runner.api/test that activates HTO and then calls that test function.
Or you could look at other test runners. Or look at Expectations which is fully compatible with the regular clojure.test stuff, including the Cognitect test runner, but it auto-activates HTO if it's on the classpath.
(BTW, you don't need both :main-opts and :exec-fn -- unless you want to be able to use both -M:test and -X:test)
I had hoped I could leave all the projects as is, and just add something in ~/.clojure/deps.ednkinda like what I did with lein:
{:user {:dependencies [[pjstadig/humane-test-output "0.11.0"]]
:injections [(require 'pjstadig.humane-test-output)
(pjstadig.humane-test-output/activate!)]}}
> (BTW, you don't need both ...
both were added with clj -M:neil add test
Yeah, it's just giving you options without needing configuration.
What you can do with :main-opts is to require/resolve/call that activate! function and then invoke the Cognitect test-runner main.
(let me just set that up and report back)
Yup, here we go:
{:test
{:extra-paths ["test"]
:extra-deps {pjstadig/humane-test-output
{:mvn/version "0.11.0"}
io.github.cognitect-labs/test-runner
{:git/tag "v0.5.1" :git/sha "dfb30dd"}}
:main-opts ["-e" "((requiring-resolve 'pjstadig.humane-test-output/activate!))"
"-m" "cognitect.test-runner"]}(assuming you're on Clojure 1.10 or later)
Ah, you have :extra-paths ["test/unit"] in yours... but it's close. And then clojure -M:test
Since -X invokes just a single function, you'd need a wrapper function, but with -M you can have multiple main options chained together.