|
1 | 1 | (ns orchard.inspect-test
|
2 | 2 | (:require
|
3 |
| - [clojure.data :as data] |
4 |
| - [clojure.edn :as edn] |
5 |
| - [clojure.java.io :as io] |
6 |
| - [clojure.java.shell :as shell] |
7 |
| - [clojure.pprint :as pprint] |
8 | 3 | [clojure.string :as string]
|
9 |
| - [clojure.test :as t :refer [are deftest is testing]] |
| 4 | + [clojure.test :refer [deftest is testing]] |
10 | 5 | [clojure.walk :as walk]
|
11 | 6 | [matcher-combinators.matchers :as matchers]
|
12 | 7 | [orchard.inspect :as inspect]
|
13 |
| - [orchard.meta :as m] |
14 |
| - [orchard.misc :refer [java-api-version]] |
15 |
| - [orchard.misc :as misc]) |
| 8 | + [orchard.misc :as misc :refer [java-api-version]]) |
16 | 9 | (:import
|
17 |
| - (java.io File) |
18 | 10 | (orchard.java PrivateFieldClass)))
|
19 | 11 |
|
20 |
| -;; for `match?` |
21 |
| -(require 'matcher-combinators.test) |
| 12 | +(require 'matcher-combinators.test) ;; for `match?` |
22 | 13 |
|
23 | 14 | (defn- demunge-str [s]
|
24 | 15 | (-> s
|
|
35 | 26 | form))
|
36 | 27 | rendered)))
|
37 | 28 |
|
38 |
| -(defn- render-plain [x] |
39 |
| - (cond (and (seq? x) (keyword? (first x))) |
40 |
| - (let [[type value & args] x] |
41 |
| - (case type |
42 |
| - :newline "\n" |
43 |
| - :value (format "%s <%s>" value (string/join "," args)))) |
44 |
| - (seq? x) |
45 |
| - (string/join "" (map render-plain x)) |
46 |
| - :else (str x))) |
47 |
| - |
48 |
| -(defn- diff-text [expected actual] |
49 |
| - (when (zero? (:exit (shell/sh "git" "--version"))) |
50 |
| - (let [actual-file (File/createTempFile "actual" ".txt") |
51 |
| - expected-file (File/createTempFile "expected" ".txt")] |
52 |
| - (spit actual-file (render-plain actual)) |
53 |
| - (spit expected-file (render-plain expected)) |
54 |
| - (try (let [{:keys [exit out err] :as result} |
55 |
| - (shell/sh "git" "diff" |
56 |
| - (if (= "dumb" (System/getenv "TERM")) "--no-color" "--color") |
57 |
| - "--minimal" |
58 |
| - "--no-index" |
59 |
| - (str actual-file) (str expected-file))] |
60 |
| - (case exit |
61 |
| - (0 1) out |
62 |
| - (ex-info "Failed to call diff" result))) |
63 |
| - (finally |
64 |
| - (io/delete-file actual-file) |
65 |
| - (io/delete-file expected-file)))))) |
66 |
| - |
67 |
| -(defn- test-message [msg expected actual] |
68 |
| - (let [expected-text (render-plain expected) |
69 |
| - actual-text (render-plain actual)] |
70 |
| - (with-out-str |
71 |
| - (println (format "Inspect test failed" (when msg (str ": " msg)))) |
72 |
| - (let [diff (diff-text expected actual)] |
73 |
| - (when-not (string/blank? diff) |
74 |
| - (println) |
75 |
| - (println "=== Text Diff ===\n") |
76 |
| - (println diff))) |
77 |
| - (let [[only-in-expected only-in-actual both] (data/diff expected actual)] |
78 |
| - (when (seq only-in-expected) |
79 |
| - (println) |
80 |
| - (println "=== Expected data diff ===\n") |
81 |
| - (pprint/pprint only-in-expected)) |
82 |
| - (when (seq only-in-actual) |
83 |
| - (println) |
84 |
| - (println "=== Actual data diff ===\n") |
85 |
| - (pprint/pprint only-in-actual))) |
86 |
| - (when-not (= expected-text actual-text) |
87 |
| - (when expected |
88 |
| - (println) |
89 |
| - (println "=== Expected text ===\n") |
90 |
| - (println expected-text)) |
91 |
| - (when actual |
92 |
| - (println) |
93 |
| - (println "=== Actual text ===\n") |
94 |
| - (println actual-text) |
95 |
| - (println)))))) |
96 |
| - |
97 | 29 | (def nil-result
|
98 | 30 | '("nil" (:newline)))
|
99 | 31 |
|
|
0 commit comments