fix #1181: clojure.test report does not respect *test-out* correctly (#1182)

This commit is contained in:
Michiel Borkent 2022-02-18 22:54:10 +01:00 committed by GitHub
parent 3c207e1a9b
commit 19e87a545d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 4 deletions

View file

@ -273,13 +273,13 @@
(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
"Runs body with *out* bound to the value of *test-out*."
{:added "1.1"}
[& body]
`(sci/binding [sci/out @test-out]
`(binding [*out* @test-out]
~@body))
(defmacro with-test-out

View file

@ -1,13 +1,17 @@
(ns babashka.test-test
(:require
[babashka.impl.clojure.test :as test-impl]
[babashka.test-utils :as tu]
[clojure.edn :as edn]
[clojure.java.io :as io]
[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]
(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
(is (str/includes?
@ -92,3 +96,15 @@
(throw (ex-info \"\" {})))))
(t/run-tests *ns*)")]
(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"))))