Add run-test and run-test-var to clojure.test
This commit is contained in:
parent
36d2ec2d87
commit
ee5f2a7a2e
3 changed files with 39 additions and 1 deletions
|
|
@ -7,7 +7,7 @@ A preview of the next release can be installed from
|
||||||
|
|
||||||
## Unreleased
|
## Unreleased
|
||||||
|
|
||||||
...
|
- Add `run-test` and `run-test-var` to `clojure.test`
|
||||||
|
|
||||||
## 1.0.165 (2022-11-01)
|
## 1.0.165 (2022-11-01)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -804,3 +804,39 @@
|
||||||
[summary]
|
[summary]
|
||||||
(and (zero? (:fail summary 0))
|
(and (zero? (:fail summary 0))
|
||||||
(zero? (:error summary 0))))
|
(zero? (:error summary 0))))
|
||||||
|
|
||||||
|
(defn run-test-var
|
||||||
|
"Runs the tests for a single Var, with fixtures executed around the test, and summary output after."
|
||||||
|
{:added "1.11"}
|
||||||
|
[v]
|
||||||
|
(sci/binding [report-counters (atom @initial-report-counters)]
|
||||||
|
(let [ns-obj (-> v meta :ns)
|
||||||
|
summary (do
|
||||||
|
(do-report {:type :begin-test-ns
|
||||||
|
:ns ns-obj})
|
||||||
|
(test-vars [v])
|
||||||
|
(do-report {:type :end-test-ns
|
||||||
|
:ns ns-obj})
|
||||||
|
(assoc @@report-counters :type :summary))]
|
||||||
|
(do-report summary)
|
||||||
|
summary)))
|
||||||
|
|
||||||
|
(defmacro run-test
|
||||||
|
"Runs a single test.
|
||||||
|
Because the intent is to run a single test, there is no check for the namespace test-ns-hook."
|
||||||
|
{:added "1.11"}
|
||||||
|
[test-symbol]
|
||||||
|
(let [test-var (sci/resolve @ctx test-symbol)]
|
||||||
|
(cond
|
||||||
|
(nil? test-var)
|
||||||
|
(sci/binding [sci/out sci/err]
|
||||||
|
(binding [*out* sci/out]
|
||||||
|
(println "Unable to resolve" test-symbol "to a test function.")))
|
||||||
|
|
||||||
|
(not (-> test-var meta :test))
|
||||||
|
(sci/binding [sci/out sci/err]
|
||||||
|
(binding [*out* sci/out]
|
||||||
|
(println test-symbol "is not a test.")))
|
||||||
|
|
||||||
|
:else
|
||||||
|
`(run-test-var ~test-var))))
|
||||||
|
|
|
||||||
|
|
@ -55,6 +55,8 @@
|
||||||
'test-ns (new-var 'test-ns (contextualize t/test-ns))
|
'test-ns (new-var 'test-ns (contextualize t/test-ns))
|
||||||
;; running tests: high level
|
;; running tests: high level
|
||||||
'run-tests (new-var 'run-tests (contextualize t/run-tests))
|
'run-tests (new-var 'run-tests (contextualize t/run-tests))
|
||||||
|
'run-test-var (sci/copy-var t/run-test-var tns)
|
||||||
|
'run-test (sci/copy-var t/run-test tns)
|
||||||
'run-all-tests (new-var 'run-all-tests (contextualize t/run-all-tests))
|
'run-all-tests (new-var 'run-all-tests (contextualize t/run-all-tests))
|
||||||
'successful? (sci/copy-var t/successful? tns)
|
'successful? (sci/copy-var t/successful? tns)
|
||||||
'with-test-out (sci/copy-var t/with-test-out tns)})
|
'with-test-out (sci/copy-var t/with-test-out tns)})
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue