Skip to content

Commit d423eae

Browse files
committed
implement config & cli-args to accept mute-zero-assertion?
1 parent d30b092 commit d423eae

File tree

5 files changed

+18
-3
lines changed

5 files changed

+18
-3
lines changed

doc/03_configuration.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ Here's an example test configuration with a single test suite:
2020
:kaocha/source-paths ["src"]
2121
:kaocha/test-paths ["test/unit"]}]
2222
:kaocha/fail-fast? false
23+
:kaocha/mute-zero-assertion? true
2324
:kaocha/color? true
2425
:kaocha/reporter [kaocha.report/dots]
2526
:kaocha/plugins [:kaocha.plugin/randomize

src/kaocha/api.clj

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@
9292
(let [config (plugin/run-hook :kaocha.hooks/config config)
9393
color? (:kaocha/color? config)
9494
fail-fast? (:kaocha/fail-fast? config)
95+
mute-zero-assertion? (:kaocha/mute-zero-assertion? config)
9596
history (atom [])]
9697
(binding [*active?* true
9798
testable/*fail-fast?* fail-fast?
@@ -102,6 +103,10 @@
102103
(let [config (resolve-reporter config)]
103104
(let [test-plan (test-plan config)]
104105

106+
(when mute-zero-assertion?
107+
(hierarchy/underive! :kaocha.type.var/zero-assertions :kaocha/known-key)
108+
(hierarchy/underive! :kaocha.type.var/zero-assertions :kaocha/fail-type))
109+
105110
(when-not (some #(or (hierarchy/leaf? %)
106111
(::testable/load-error %))
107112
(testable/test-seq test-plan))
@@ -112,7 +117,7 @@
112117
(count (testable/test-seq-with-skipped test-plan))))
113118
(output/warn (str "No tests were found. This may be an issue in your Kaocha test configuration."
114119
" To investigate, check the :test-paths and :ns-patterns keys in tests.edn.")))
115-
(throw+ {:kaocha/early-exit 0 }))
120+
(throw+ {:kaocha/early-exit 0}))
116121

117122
(when (find-ns 'matcher-combinators.core)
118123
(require 'kaocha.matcher-combinators))
@@ -129,7 +134,7 @@
129134
;; been interrupted, output capturing may
130135
;; still be in effect.
131136
(System/setOut
132-
orig-out)
137+
orig-out)
133138
(binding [history/*history* history]
134139
(t/do-report (history/clojure-test-summary)))
135140
(catch Throwable t

src/kaocha/config.clj

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@
7878
reporter
7979
color?
8080
fail-fast?
81+
mute-zero-assertion?
8182
diff-style
8283
randomize?
8384
capture-output?
@@ -91,11 +92,12 @@
9192
bindings (assoc :kaocha/bindings bindings)
9293
(some? color?) (assoc :kaocha/color? color?)
9394
(some? fail-fast?) (assoc :kaocha/fail-fast? fail-fast?)
95+
(some? mute-zero-assertion?) (assoc :kaocha/mute-zero-assertion? mute-zero-assertion?)
9496
(some? diff-style) (assoc :kaocha/diff-style diff-style)
9597
(some? watch?) (assoc :kaocha/watch? watch?)
9698
(some? randomize?) (assoc :kaocha.plugin.randomize/randomize? randomize?)
9799
(some? capture-output?) (assoc :kaocha.plugin.capture-output/capture-output? capture-output?)
98-
:-> (merge (dissoc config :tests :plugins :reporter :color? :fail-fast? :watch? :randomize?)))))
100+
:-> (merge (dissoc config :tests :plugins :reporter :color? :fail-fast? :mute-zero-assertion? :watch? :randomize?)))))
99101

100102
(defmethod aero/reader 'kaocha [_opts _tag value]
101103
(output/warn (format "The #kaocha reader literal is deprecated, please change it to %s." current-reader))
@@ -198,6 +200,7 @@
198200
(defn apply-cli-opts [config options]
199201
(cond-> config
200202
(some? (:fail-fast options)) (assoc :kaocha/fail-fast? (:fail-fast options))
203+
(some? (:mute-zero-assertion options)) (assoc :kaocha/mute-zero-assertion? (:mute-zero-assertion options))
201204
(:reporter options) (assoc :kaocha/reporter (:reporter options))
202205
(:watch options) (assoc :kaocha/watch? (:watch options))
203206
(some? (:color options)) (assoc :kaocha/color? (:color options))

src/kaocha/hierarchy.clj

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@
88
[tag parent]
99
(alter-var-root #'hierarchy derive tag parent))
1010

11+
(defn underive!
12+
"Add a parent/child relationship to kaocha's keyword hierarchy."
13+
[tag parent]
14+
(alter-var-root #'hierarchy underive tag parent))
15+
1116
(derive! :fail :kaocha/fail-type)
1217
(derive! :error :kaocha/fail-type)
1318

src/kaocha/runner.clj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
[nil "--print-test-plan" "Load tests, build up a test plan, then print out the test plan and exit."]
3333
[nil "--print-result" "Print the test result map as returned by the Kaocha API."]
3434
[nil "--[no-]fail-fast" "Stop testing after the first failure."]
35+
[nil "--[no-]mute-zero-assertion" "Stop raising failure when there is no assertion in test."]
3536
[nil "--[no-]color" "Enable/disable ANSI color codes in output. Defaults to true."]
3637
[nil "--[no-]watch" "Watch filesystem for changes and re-run tests."]
3738
[nil "--reporter SYMBOL" "Change the test reporter, can be specified multiple times."

0 commit comments

Comments
 (0)