This commit is contained in:
parent
3c207e1a9b
commit
19e87a545d
2 changed files with 20 additions and 4 deletions
|
|
@ -273,13 +273,13 @@
|
||||||
|
|
||||||
(def testing-contexts (sci/new-dynamic-var '*testing-contexts* (list) {:ns tns})) ; bound to hierarchy of "testing" strings
|
(def testing-contexts (sci/new-dynamic-var '*testing-contexts* (list) {:ns tns})) ; bound to hierarchy of "testing" strings
|
||||||
|
|
||||||
(def test-out (sci/new-dynamic-var '*test-out* sci/out {:ns tns})) ; PrintWriter for test reporting output
|
(def test-out (sci/new-dynamic-var '*test-out* *out* {:ns tns})) ; PrintWriter for test reporting output
|
||||||
|
|
||||||
(defmacro with-test-out-internal
|
(defmacro with-test-out-internal
|
||||||
"Runs body with *out* bound to the value of *test-out*."
|
"Runs body with *out* bound to the value of *test-out*."
|
||||||
{:added "1.1"}
|
{:added "1.1"}
|
||||||
[& body]
|
[& body]
|
||||||
`(sci/binding [sci/out @test-out]
|
`(binding [*out* @test-out]
|
||||||
~@body))
|
~@body))
|
||||||
|
|
||||||
(defmacro with-test-out
|
(defmacro with-test-out
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,17 @@
|
||||||
(ns babashka.test-test
|
(ns babashka.test-test
|
||||||
(:require
|
(:require
|
||||||
|
[babashka.impl.clojure.test :as test-impl]
|
||||||
[babashka.test-utils :as tu]
|
[babashka.test-utils :as tu]
|
||||||
[clojure.edn :as edn]
|
[clojure.edn :as edn]
|
||||||
[clojure.java.io :as io]
|
[clojure.java.io :as io]
|
||||||
[clojure.string :as str]
|
[clojure.string :as str]
|
||||||
[clojure.test :as t :refer [deftest is]]))
|
[clojure.test :as t :refer [deftest is]]
|
||||||
|
[sci.core :as sci]))
|
||||||
|
|
||||||
(defn bb [& args]
|
(defn bb [& args]
|
||||||
(apply tu/bb nil (map str args)))
|
(let [sw (java.io.StringWriter.)]
|
||||||
|
(sci/binding [test-impl/test-out sw]
|
||||||
|
(str sw (apply tu/bb nil (map str args))))))
|
||||||
|
|
||||||
(deftest deftest-test
|
(deftest deftest-test
|
||||||
(is (str/includes?
|
(is (str/includes?
|
||||||
|
|
@ -92,3 +96,15 @@
|
||||||
(throw (ex-info \"\" {})))))
|
(throw (ex-info \"\" {})))))
|
||||||
(t/run-tests *ns*)")]
|
(t/run-tests *ns*)")]
|
||||||
(is (str/includes? output "Ran 1 tests containing 2 assertions."))))
|
(is (str/includes? output "Ran 1 tests containing 2 assertions."))))
|
||||||
|
|
||||||
|
(deftest test-out-test
|
||||||
|
(let [output (bb "
|
||||||
|
(do (require '[clojure.test :as t])
|
||||||
|
(t/deftest foo (t/are [x]
|
||||||
|
(t/is (thrown-with-msg? Exception #\"\" x))
|
||||||
|
(throw (ex-info \"\" {})))))
|
||||||
|
(let [sw (java.io.StringWriter.)]
|
||||||
|
(binding [t/*test-out* sw]
|
||||||
|
(t/with-test-out (t/run-tests *ns*)))
|
||||||
|
(str/includes? (str sw) \"Ran 1 tests containing 2 assertions.\"))")]
|
||||||
|
(is (str/includes? output "true"))))
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue