Last active
November 4, 2019 18:43
-
-
Save borkdude/c43d5b8548d9185f8454bcced3861064 to your computer and use it in GitHub Desktop.
Report missing test assertion in clojure.test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns missing-test-assertion.core | |
(:require [clojure.test :refer [report *report-counters*]])) | |
(def state (atom 0)) | |
(defn assertion-count [] | |
(let [rc @*report-counters*] | |
(+ (get rc :pass 0) | |
(get rc :fail 0) | |
(get rc :error 0)))) | |
(let [old-method (get-method report :begin-test-var)] | |
(defmethod report :begin-test-var [m] | |
(when old-method (old-method m)) | |
(reset! state (assertion-count)))) | |
(let [old-method (get-method report :end-test-var)] | |
(defmethod report :end-test-var [m] | |
(when old-method (old-method m)) | |
(let [ac (assertion-count)] | |
(when (= ac @state) | |
(binding [*out* *err*] | |
(println "WARNING: no assertions made in test" (-> m :var meta :name))))))) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment