From 19e87a545d0b8b5df00409a4c9779c12e11bd09b Mon Sep 17 00:00:00 2001 From: Michiel Borkent Date: Fri, 18 Feb 2022 22:54:10 +0100 Subject: [PATCH] fix #1181: clojure.test report does not respect *test-out* correctly (#1182) --- src/babashka/impl/clojure/test.clj | 4 ++-- test/babashka/test_test.clj | 20 ++++++++++++++++++-- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/babashka/impl/clojure/test.clj b/src/babashka/impl/clojure/test.clj index 4d757773..0053e289 100644 --- a/src/babashka/impl/clojure/test.clj +++ b/src/babashka/impl/clojure/test.clj @@ -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 diff --git a/test/babashka/test_test.clj b/test/babashka/test_test.clj index e3b9a736..d88c3fd5 100644 --- a/test/babashka/test_test.clj +++ b/test/babashka/test_test.clj @@ -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"))))