testing

Jacob Emcken 2023-04-09T20:57:04.495249Z

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?

Jacob Emcken 2023-04-10T18:10:40.998039Z

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.

Jacob Emcken 2023-04-10T18:17:59.271139Z

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:humane

👍🏻 1
seancorfield 2023-04-09T20:58:46.276639Z

What exactly do you have in your :test alias?

mpenet 2023-04-09T21:00:57.579789Z

Eftest returns similar output by default , I suspect kaocha also has options for this. But these are full runners, not just a reporter

mpenet 2023-04-09T21:01:19.796089Z

That said both are great options

seancorfield 2023-04-09T21:04:06.408689Z

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.

Jacob Emcken 2023-04-09T21:04:06.523679Z

: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}

seancorfield 2023-04-09T21:06:24.951199Z

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.

seancorfield 2023-04-09T21:07:29.211639Z

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.

seancorfield 2023-04-09T21:08:17.209539Z

(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)

Jacob Emcken 2023-04-09T21:11:07.786169Z

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!)]}}

Jacob Emcken 2023-04-09T21:12:39.341439Z

> (BTW, you don't need both ... both were added with clj -M:neil add test

seancorfield 2023-04-09T21:28:35.591389Z

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.

seancorfield 2023-04-09T21:28:46.425839Z

(let me just set that up and report back)

seancorfield 2023-04-09T21:34:26.250119Z

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"]}

seancorfield 2023-04-09T21:34:44.888439Z

(assuming you're on Clojure 1.10 or later)

seancorfield 2023-04-09T21:35:28.218519Z

Ah, you have :extra-paths ["test/unit"] in yours... but it's close. And then clojure -M:test

seancorfield 2023-04-09T21:36:44.204689Z

Since -X invokes just a single function, you'd need a wrapper function, but with -M you can have multiple main options chained together.