|
1 | 1 | (ns io.julienvincent.clojure-test.runner
|
2 | 2 | (:require
|
3 |
| - [clj-commons.format.exceptions :as pretty.exceptions] |
4 |
| - [clojure.pprint :as pprint] |
5 |
| - [clojure.test :as test])) |
| 3 | + [clojure.test :as test] |
| 4 | + [io.julienvincent.clojure-test.serialization :as serialization])) |
6 | 5 |
|
7 | 6 | (def ^:dynamic ^:private *report* nil)
|
8 | 7 |
|
9 |
| -(defn- remove-commas |
10 |
| - "Clojures pprint function adds commas in whitespace. This removes them while maintaining |
11 |
| - any commas that are within strings" |
12 |
| - [s] |
13 |
| - (let [pattern #"(?<=^|[^\\])(\"(?:[^\"\\]|\\.)*\"|[^,\"]+)|(,)" |
14 |
| - matches (re-seq pattern s)] |
15 |
| - (apply str (map |
16 |
| - (fn [[_ group1]] |
17 |
| - (or group1 "")) |
18 |
| - matches)))) |
19 |
| - |
20 |
| -(defn pretty-print [data] |
21 |
| - (-> (with-out-str |
22 |
| - (pprint/pprint data)) |
23 |
| - remove-commas)) |
24 |
| - |
25 |
| -(defn- parse-diff [diff] |
26 |
| - (when-let [mc (try (requiring-resolve 'matcher-combinators.config/disable-ansi-color!) |
27 |
| - (catch Exception _))] |
28 |
| - (mc)) |
29 |
| - |
30 |
| - (cond |
31 |
| - (= :matcher-combinators.clj-test/mismatch (:type (meta diff))) |
32 |
| - (-> diff pr-str remove-commas) |
33 |
| - |
34 |
| - :else |
35 |
| - (pretty-print diff))) |
36 |
| - |
37 |
| -(defn- parse-exception [exception] |
38 |
| - (mapv |
39 |
| - (fn [{:keys [properties] :as ex}] |
40 |
| - (let [props (when properties |
41 |
| - (pretty-print properties))] |
42 |
| - (if props |
43 |
| - (assoc ex :properties props) |
44 |
| - ex))) |
45 |
| - (pretty.exceptions/analyze-exception exception {}))) |
46 |
| - |
47 | 8 | (defn- parse-report [report]
|
48 | 9 | (let [exceptions (when (instance? Throwable (:actual report))
|
49 |
| - (parse-exception (:actual report))) |
| 10 | + (serialization/analyze-exception (:actual report))) |
50 | 11 |
|
51 | 12 | report (cond-> (select-keys report [:type])
|
52 | 13 | (:expected report)
|
53 |
| - (assoc :expected (parse-diff (:expected report))) |
| 14 | + (assoc :expected (serialization/parse-diff (:expected report))) |
54 | 15 |
|
55 | 16 | (and (:actual report)
|
56 | 17 | (not exceptions))
|
57 |
| - (assoc :actual (parse-diff (:actual report))) |
| 18 | + (assoc :actual (serialization/parse-diff (:actual report))) |
58 | 19 |
|
59 | 20 | exceptions (assoc :exceptions exceptions))]
|
60 | 21 |
|
|
0 commit comments