diff --git a/doc/clojure_test/assertions.md b/doc/clojure_test/assertions.md index 4d9e90d7..cf7f8027 100644 --- a/doc/clojure_test/assertions.md +++ b/doc/clojure_test/assertions.md @@ -32,7 +32,12 @@ FAIL in sample-test/my-test (sample_test.clj:4) Test ran without assertions. Did you forget an (is ...)? ``` +### Missing assertions are configurable +There are two ways to disable this detection: + +* Add `:kaocha/warnings {:zero-assertions :silent}` into `tests.edn`. +* Add `:kaocha/warnings {:zero-tests :error}` into `tests.edn`. ## Detecting single argument `=` diff --git a/src/kaocha/api.clj b/src/kaocha/api.clj index 6421832c..f6b96003 100644 --- a/src/kaocha/api.clj +++ b/src/kaocha/api.clj @@ -92,6 +92,7 @@ (let [config (plugin/run-hook :kaocha.hooks/config config) color? (:kaocha/color? config) fail-fast? (:kaocha/fail-fast? config) + warnings (:kaocha/warnings config) history (atom [])] (binding [*active?* true testable/*fail-fast?* fail-fast? @@ -102,6 +103,10 @@ (let [config (resolve-reporter config)] (let [test-plan (test-plan config)] + (when (= (:zero-assertions warnings) :silent) + (hierarchy/underive! :kaocha.type.var/zero-assertions :kaocha/known-key) + (hierarchy/underive! :kaocha.type.var/zero-assertions :kaocha/fail-type)) + (when-not (some #(or (hierarchy/leaf? %) (::testable/load-error %)) (testable/test-seq test-plan)) @@ -110,9 +115,14 @@ " Check for misspelled settings in your Kaocha test configuration" " or incorrect focus or skip filters.") (count (testable/test-seq-with-skipped test-plan)))) - (output/warn (str "No tests were found. This may be an issue in your Kaocha test configuration." - " To investigate, check the :test-paths and :ns-patterns keys in tests.edn."))) - (throw+ {:kaocha/early-exit 0 })) + (if (= (:zero-tests warnings) :error) + (do + (output/error (str "No tests were found. This may be an issue in your Kaocha test configuration." + " To investigate, check the :test-paths and :ns-patterns keys in tests.edn.")) + (throw+ {:kaocha/early-exit 253})) + (output/warn (str "No tests were found. This may be an issue in your Kaocha test configuration." + " To investigate, check the :test-paths and :ns-patterns keys in tests.edn.")))) + (throw+ {:kaocha/early-exit 0})) (when (find-ns 'matcher-combinators.core) (require 'kaocha.matcher-combinators)) diff --git a/src/kaocha/config.clj b/src/kaocha/config.clj index 05775a93..f55490c7 100644 --- a/src/kaocha/config.clj +++ b/src/kaocha/config.clj @@ -78,6 +78,7 @@ reporter color? fail-fast? + warnings diff-style randomize? capture-output? @@ -88,6 +89,7 @@ tests (assoc :kaocha/tests (vary-meta tests assoc :replace true)) plugins (assoc :kaocha/plugins plugins) reporter (assoc :kaocha/reporter (vary-meta reporter assoc :replace true)) + warnings (assoc :kaocha/warnings warnings) bindings (assoc :kaocha/bindings bindings) (some? color?) (assoc :kaocha/color? color?) (some? fail-fast?) (assoc :kaocha/fail-fast? fail-fast?) @@ -95,7 +97,7 @@ (some? watch?) (assoc :kaocha/watch? watch?) (some? randomize?) (assoc :kaocha.plugin.randomize/randomize? randomize?) (some? capture-output?) (assoc :kaocha.plugin.capture-output/capture-output? capture-output?) - :-> (merge (dissoc config :tests :plugins :reporter :color? :fail-fast? :watch? :randomize?))))) + :-> (merge (dissoc config :tests :plugins :reporter :warnings :color? :fail-fast? :watch? :randomize?))))) (defmethod aero/reader 'kaocha [_opts _tag value] (output/warn (format "The #kaocha reader literal is deprecated, please change it to %s." current-reader)) @@ -195,7 +197,6 @@ config (read-config nil opts)))) - (defn apply-cli-opts [config options] (cond-> config (some? (:fail-fast options)) (assoc :kaocha/fail-fast? (:fail-fast options)) @@ -224,10 +225,10 @@ "Applies command-line options and arguments to the configuration." [config cli-opts cli-args] (cond-> config - cli-opts (apply-cli-opts cli-opts) - cli-args (apply-cli-args cli-args))) + cli-opts (apply-cli-opts cli-opts) + cli-args (apply-cli-args cli-args))) -(defn find-config-and-warn +(defn find-config-and-warn [config-file] (let [final-config-file (or config-file "tests.edn")] (when (not (.exists (io/file (or config-file "tests.edn")))) @@ -241,13 +242,13 @@ (defn validate! "Validates the configuration, printing any warnings and errors and possibly throwing." [config] - (try - (specs/assert-spec :kaocha/config config) - config - (catch AssertionError e - (output/error "Invalid configuration file:\n" - (.getMessage e)) - (throw+ {:kaocha/early-exit 252})))) + (try + (specs/assert-spec :kaocha/config config) + config + (catch AssertionError e + (output/error "Invalid configuration file:\n" + (.getMessage e)) + (throw+ {:kaocha/early-exit 252})))) (defn load-config-for-cli-and-validate "Loads config from config-file, factoring in profile specified using profile, diff --git a/src/kaocha/hierarchy.clj b/src/kaocha/hierarchy.clj index 544a27a0..018981a3 100644 --- a/src/kaocha/hierarchy.clj +++ b/src/kaocha/hierarchy.clj @@ -8,6 +8,11 @@ [tag parent] (alter-var-root #'hierarchy derive tag parent)) +(defn underive! + "Add a parent/child relationship to kaocha's keyword hierarchy." + [tag parent] + (alter-var-root #'hierarchy underive tag parent)) + (derive! :fail :kaocha/fail-type) (derive! :error :kaocha/fail-type) diff --git a/src/kaocha/report.clj b/src/kaocha/report.clj index dad7540d..2463e832 100644 --- a/src/kaocha/report.clj +++ b/src/kaocha/report.clj @@ -99,7 +99,6 @@ [kaocha.plugin.capture-output :as capture] [kaocha.stacktrace :as stacktrace] [kaocha.testable :as testable] - [kaocha.testable :as testable] [kaocha.util :as util] [slingshot.slingshot :refer [throw+]])) @@ -425,6 +424,7 @@ ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + (def dots "Reporter that prints progress as a sequence of dots and letters." [dots* result]) diff --git a/src/kaocha/runner.clj b/src/kaocha/runner.clj index cb2139b6..f172ee4c 100644 --- a/src/kaocha/runner.clj +++ b/src/kaocha/runner.clj @@ -42,8 +42,7 @@ (symbol "kaocha.report" s)))) :assoc-fn accumulate] [nil "--diff-style STYLE" "The style of diff to print on failing tests, either :none or :deep" - :parse-fn parse-kw - ] + :parse-fn parse-kw] [nil "--plugin KEYWORD" "Load the given plugin." :parse-fn (fn [s] (let [kw (parse-kw s)] @@ -151,8 +150,8 @@ config-file (config/find-config-and-warn config-file) ;; Initial configuration load to determine plugins. config (-> (config/load-config config-file (if profile {:profile profile} {})) - (config/apply-cli {} (map parse-kw arguments)) - (config/validate!)) + (config/apply-cli {} (map parse-kw arguments)) + (config/validate!)) plugin-chain (plugin/load-all (concat (:kaocha/plugins config) plugin)) cli-options (plugin/run-hook* plugin-chain :kaocha.hooks/cli-options cli-options) diff --git a/src/kaocha/specs.clj b/src/kaocha/specs.clj index 6f495182..e1c26e24 100644 --- a/src/kaocha/specs.clj +++ b/src/kaocha/specs.clj @@ -22,33 +22,36 @@ (spec/def :kaocha/fail-fast? boolean?) +(spec/def :kaocha/warnings (spec/map-of #{:zero-assertions :zero-tests} #{:silent :error})) + (spec/def :kaocha/watch? boolean?) (spec/def :kaocha/plugins (spec/coll-of keyword?)) (spec/def :kaocha/reporter (spec/or :fn (s-fspec :args (spec/cat :m map?)) - :symbol symbol? - :symbols (spec/coll-of symbol? :kind vector?))) + :symbol symbol? + :symbols (spec/coll-of symbol? :kind vector?))) (spec/def :kaocha/global-opts (spec/keys :opt [:kaocha/reporter - :kaocha/color? - :kaocha/fail-fast? - :kaocha/watch? - :kaocha/plugins])) + :kaocha/color? + :kaocha/fail-fast? + :kaocha/warnings + :kaocha/watch? + :kaocha/plugins])) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; config (spec/def :kaocha/config (spec/merge :kaocha/global-opts - (spec/keys :opt [:kaocha/tests]))) + (spec/keys :opt [:kaocha/tests]))) (spec/def :kaocha/tests (spec/coll-of :kaocha/testable)) (spec/def :kaocha/testable (spec/keys :req [:kaocha.testable/type - :kaocha.testable/id] - :opt [:kaocha.testable/meta - :kaocha.testable/wrap])) + :kaocha.testable/id] + :opt [:kaocha.testable/meta + :kaocha.testable/wrap])) (spec/def :kaocha/source-paths (spec/coll-of string?)) @@ -77,43 +80,43 @@ (spec/def :kaocha/test-plan (spec/merge :kaocha/global-opts - (spec/keys :opt [:kaocha.test-plan/tests]))) + (spec/keys :opt [:kaocha.test-plan/tests]))) (spec/def :kaocha.test-plan/tests (spec/coll-of :kaocha.test-plan/testable)) (spec/def :kaocha.test-plan/testable (spec/merge :kaocha/testable - (spec/keys :req [] - :opt [:kaocha.testable/desc - :kaocha.test-plan/tests - :kaocha.testable/load-error]))) + (spec/keys :req [] + :opt [:kaocha.testable/desc + :kaocha.test-plan/tests + :kaocha.testable/load-error]))) (spec/def :kaocha.testable/load-error (s-with-gen - #(instance? Throwable %) - #(s-gen #{(ex-info "load error" {:oops "not good"})}))) + #(instance? Throwable %) + #(s-gen #{(ex-info "load error" {:oops "not good"})}))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; result (spec/def :kaocha/result (spec/merge :kaocha/global-opts - (spec/keys :opt [:kaocha.result/tests]))) + (spec/keys :opt [:kaocha.result/tests]))) (spec/def :kaocha.result/tests (spec/coll-of :kaocha.result/testable)) (spec/def :kaocha.result/testable (spec/merge :kaocha.test-plan/testable - (spec/keys :opt [:kaocha.result/count - :kaocha.result/tests - :kaocha.result/pass - :kaocha.result/error - :kaocha.result/fail - :kaocha.result/out - :kaocha.result/err - :kaocha.result/time]))) + (spec/keys :opt [:kaocha.result/count + :kaocha.result/tests + :kaocha.result/pass + :kaocha.result/error + :kaocha.result/fail + :kaocha.result/out + :kaocha.result/err + :kaocha.result/time]))) (spec/def ::small-int (s-with-gen - nat-int? - (constantly (or (some-> (resolve `clojure.test.check.generatorspec/small-integer) deref) - (s-gen nat-int?))))) + nat-int? + (constantly (or (some-> (resolve `clojure.test.check.generatorspec/small-integer) deref) + (s-gen nat-int?))))) (spec/def :kaocha.result/count ::small-int) (spec/def :kaocha.result/pass ::small-int) @@ -145,7 +148,7 @@ (spec/def ::stc/num-tests (spec/nilable nat-int?)) (spec/def ::stc/max-size (spec/nilable nat-int?)) (spec/def ::stc/opts (spec/nilable (spec/keys :opt-un [::stc/num-tests - ::stc/max-size])))) + ::stc/max-size])))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; helpers