weavejester / eftest

Fast and pretty Clojure test runner
425 stars 40 forks source link

Change run-tests to return a summary map #4

Closed jcf closed 7 years ago

jcf commented 7 years ago

Hey James,

Hope this finds you well.

I was hoping to add some tests but it's tricky testing the tests, as I'm sure you're aware. I thought about adding a nested Leiningen project and shelling out to make sure we do the right thing, but with the progress bar and additional complexity…

This PR returns the hash-map of test summary info so we can programmatically do things. The commit below describes what's going on. Oh, and I snuck a small documentation fix in that I thought you'd be cool with. If you'd prefer it in a separate PR please cherry pick it out.

All the best old friend,

Other James


Previously running tests via eftest.runner/run-tests would return nil making it impossible to know if we have a green/red build. This change returns a map of information similar to that of clojure.test itself (with an additional :duration key-value pair that describes how long our tests took to run).

This change makes it possible to use eftest's run-tests programmatically, which allows us to use eftest in CI and other systems where we may need to forward the success or failure of a given test run to some external system.

The return value of a test run now looks something like this:

{:duration 12, :error 0, :fail 1, :pass 0, :test 1, :type :summary}

This new return value means you can something like this:

(let [{:keys [error fail]} (-> "test"
                                eftest.runner/find-tests
                                eftest.runner/run-tests)]
  (when-not (and (zero? error) (zero? fail))
    (System/exit (Math/max 255 (+ (:error m) (:fail m)))))

Note the use of Math/max. You can't use a status code larger than 255!

Fixes #3.

weavejester commented 7 years ago

Thanks! It looks good. I think we can shorten the commit message on the third commit, however. Something like:

Change run-tests to return a summary map

The summary map contains keys for :duration, :error, :fail, :pass and
:test. This makes it possible to programmatically determine whether a
test run succeeded or failed.
jcf commented 7 years ago

I've changed the commit message to your terser version.