|
3 | 3 | (:require [clojure.java.io :as io] |
4 | 4 | [clojure.stacktrace :as stack] |
5 | 5 | [clojure.test :as test] |
6 | | - [eftest.report :refer [*context*]])) |
| 6 | + [eftest.report :refer [*context*]] |
| 7 | + [eftest.report :as report])) |
7 | 8 |
|
8 | 9 | ;; XML generation based on junit.clj |
9 | 10 |
|
| 11 | +(defn- combine [f g] |
| 12 | + (fn [] (g) (f))) |
| 13 | + |
| 14 | +(def ^:private flush-lock (Object.)) |
| 15 | + |
10 | 16 | (def ^:private escape-xml-map |
11 | 17 | (zipmap "'<>\"&" (map #(str \& % \;) '[apos lt gt quot amp]))) |
12 | 18 |
|
|
93 | 99 | (println "</testsuites>"))) |
94 | 100 |
|
95 | 101 | (defmethod report :begin-test-ns [m] |
96 | | - (test/with-test-out |
97 | | - (start-suite (name (ns-name (:ns m)))))) |
| 102 | + (let [ns (name (ns-name (:ns m))) |
| 103 | + f #(test/with-test-out (start-suite ns))] |
| 104 | + (swap! *context* assoc-in [::deferred-report ns] f))) |
98 | 105 |
|
99 | 106 | (defmethod report :end-test-ns [m] |
100 | | - (test/with-test-out |
101 | | - (finish-suite))) |
| 107 | + (let [ns (name (ns-name (:ns m))) |
| 108 | + g (get-in @*context* [::deferred-report ns]) |
| 109 | + f #(test/with-test-out (finish-suite))] |
| 110 | + (locking flush-lock (g) (f)) |
| 111 | + (swap! *context* update ::deferred-report dissoc ns))) |
102 | 112 |
|
103 | 113 | (defmethod report :end-test-var [m] |
104 | | - (test/with-test-out |
105 | | - (let [test-var (:var m) |
106 | | - results (get-in @*context* [::test-results test-var])] |
107 | | - (start-case (test-name test/*testing-vars*) |
108 | | - (name (ns-name (:ns (meta test-var))))) |
109 | | - (doseq [result results] |
110 | | - (if (= :fail (:type result)) |
111 | | - (failure-el result) |
112 | | - (error-el result))) |
113 | | - (finish-case) |
114 | | - (swap! *context* update ::test-results dissoc test-var)))) |
| 114 | + (let [ns (-> (:var m) meta :ns ns-name name) |
| 115 | + testing-vars test/*testing-vars* |
| 116 | + f #(test/with-test-out |
| 117 | + (let [test-var (:var m) |
| 118 | + results (get-in @*context* [::test-results test-var])] |
| 119 | + (start-case (test-name testing-vars) ns) |
| 120 | + (doseq [result results] |
| 121 | + (if (= :fail (:type result)) |
| 122 | + (failure-el result) |
| 123 | + (error-el result))) |
| 124 | + (finish-case) |
| 125 | + (swap! *context* update ::test-results dissoc test-var)))] |
| 126 | + (swap! *context* update-in [::deferred-report ns] (partial combine f)))) |
115 | 127 |
|
116 | 128 | (defn- push-result [result] |
117 | 129 | (let [test-var (first test/*testing-vars*)] |
|
0 commit comments