Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Catch early-exit errors in Kaocha.repl #265

Merged
merged 1 commit into from
Jan 12, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 22 additions & 8 deletions src/kaocha/repl.clj
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,14 @@ out what's going on. The [[config]] and [[test-plan]] functions provide this
kind of debugging information.

These will particularly come in handy when developing plugins."}
kaocha.repl
kaocha.repl
(:require [kaocha.config :as config]
[kaocha.plugin :as plugin]
[kaocha.api :as api]
[kaocha.result :as result]
[clojure.java.io :as io]))
[kaocha.output :as output]
[clojure.java.io :as io]
[slingshot.slingshot :refer [throw+ try+]]))

(defn config
"Load the Kaocha configuration
Expand Down Expand Up @@ -151,11 +153,17 @@ These will particularly come in handy when developing plugins."}
[{} args])
config (-> (config config-opts)
(update :kaocha.filter/focus into (map testable-id) tests))]
(->> config
api/run
(plugin/run-hook :kaocha.hooks/post-summary)
:kaocha.result/tests
result/totals))))
(try+
(->> config
api/run
(plugin/run-hook :kaocha.hooks/post-summary)
:kaocha.result/tests
result/totals)
(catch :kaocha/early-exit {exit-code :kaocha/early-exit}
(if (not= exit-code 0)
(output/error "Test run exited with code " exit-code)
(output/warn "Test run exited with code " exit-code))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we ever :early-exit with code 0? Seems contradictory.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, probably. We do if no tests are found (its own issue #211) and in the kaocha.plugin.alpha.info plugin.

exit-code)))))

(defn run-all
"Do a full Kaocha test run
Expand All @@ -165,4 +173,10 @@ These will particularly come in handy when developing plugins."}
([]
(run-all {}))
([extra-opts]
(result/totals (:kaocha.result/tests (api/run (config extra-opts))))))
(try+
(result/totals (:kaocha.result/tests (api/run (config extra-opts))))
(catch :kaocha/early-exit {exit-code :kaocha/early-exit}
(if (not= exit-code 0)
(output/error "Test run exited with code " exit-code)
(output/warn "Test run exited with code " exit-code))
exit-code))))