|
8 | 8 | (defn queries_from_suite [suite-yaml]
|
9 | 9 | (:queries (yaml/from-file suite-yaml)))
|
10 | 10 |
|
11 |
| -(defn- query-implementation [{:keys [selector document ordered]}] |
| 11 | +(defn- query-implementation-for [{:keys [selector document ordered]}] |
12 | 12 | (let [current (json-path/at-path selector document)]
|
13 | 13 | (if (= ordered false)
|
14 | 14 | (sort-by json/write-str current)
|
15 | 15 | current)))
|
16 | 16 |
|
| 17 | +(defn- expected-by-consensus [query] |
| 18 | + (if (contains? query :scalar-consensus) |
| 19 | + (:scalar-consensus query) |
| 20 | + (:consensus query))) |
| 21 | + |
17 | 22 | (deftest regression
|
18 | 23 | (let [non-consensus-query-ids (->> (queries_from_suite "test/Clojure_json-path.yaml")
|
19 | 24 | (map :id)
|
20 | 25 | set)]
|
21 | 26 | (->> (queries_from_suite "test/consensus.yaml")
|
22 | 27 | (remove (fn [{id :id}] (contains? non-consensus-query-ids id)))
|
23 |
| - (map (fn [{:keys [id selector document ordered] :as query}] |
24 |
| - (let [expected (if (contains? query :scalar-consensus) |
25 |
| - (:scalar-consensus query) |
26 |
| - (:consensus query))] |
27 |
| - (testing id |
28 |
| - (is (= expected |
29 |
| - (query-implementation query))))))) |
| 28 | + (map (fn [{:keys [id] :as query}] |
| 29 | + (testing id |
| 30 | + (is (= (expected-by-consensus query) |
| 31 | + (query-implementation-for query)))))) |
30 | 32 | doall)))
|
31 | 33 |
|
32 |
| -(defn- report-change [current-reordered status result {:keys [selector document consensus id]}] |
| 34 | +(defn- report-result [current-result current-exception previous {:keys [id selector] :as query}] |
33 | 35 | (println
|
34 | 36 | (format "Warning: implementation has changed for %s: %s (previous status %s)"
|
35 |
| - id selector status)) |
36 |
| - (when (or (nil? consensus) |
37 |
| - (not= consensus current-reordered)) |
38 |
| - (when-not (= status "error") |
39 |
| - (println (format " was %s" (pr-str result)))) |
40 |
| - (println (format " now is %s" (pr-str current-reordered)))) |
41 |
| - (when-not (nil? consensus) |
42 |
| - (if (= consensus |
43 |
| - current-reordered) |
44 |
| - (println " now matching consensus") |
45 |
| - (println (format " but should be %s" (pr-str consensus)))))) |
| 37 | + id selector (:status previous))) |
| 38 | + (println "Old:") |
| 39 | + (if (= (:status previous) "error") |
| 40 | + (println " Error") |
| 41 | + (println (format" %s" (pr-str (:result previous))))) |
| 42 | + (println "New:") |
| 43 | + (if (some? current-exception) |
| 44 | + (println " Error") |
| 45 | + (println (format" %s" (pr-str current-result)))) |
| 46 | + (when-let [consensus (expected-by-consensus query)] |
| 47 | + (println "Consensus:") |
| 48 | + (println (format" %s" (pr-str consensus))))) |
46 | 49 |
|
47 | 50 | ;; This section is for warning us if we are moving away from previously
|
48 | 51 | ;; recorded results which however are not backed by a consensus based
|
|
52 | 55 | query-lookup (zipmap (map :id all-queries)
|
53 | 56 | all-queries)]
|
54 | 57 | (->> (queries_from_suite "test/Clojure_json-path.yaml")
|
55 |
| - (map (fn [{:keys [id status result]}] |
56 |
| - (let [query (get query-lookup id)] |
57 |
| - (testing id |
58 |
| - (try |
59 |
| - (let [current (query-implementation query)] |
60 |
| - (when (or (= "error" status) |
61 |
| - (not= result current)) |
62 |
| - (report-change current status result query))) |
63 |
| - (catch Exception e |
64 |
| - (when (not= "error" |
65 |
| - status) |
66 |
| - (do |
67 |
| - (println (format "Warning: implementation has changed to error for %s: %s (status %s)" id (:selector query) status)) |
68 |
| - (println (format " was %s" (pr-str result))))))))))) |
| 58 | + (map (fn [{:keys [id status result] :as previous}] |
| 59 | + (let [query (get query-lookup id)] |
| 60 | + (testing id |
| 61 | + (try |
| 62 | + (let [current-result (query-implementation-for query)] |
| 63 | + (when (or (= "error" status) |
| 64 | + (not= result current-result)) |
| 65 | + (report-result current-result nil previous query))) |
| 66 | + (catch Exception e |
| 67 | + (when (not= "error" |
| 68 | + status) |
| 69 | + (report-result nil e previous query)))))))) |
69 | 70 | doall)))
|
0 commit comments