Skip to content

Commit a82844c

Browse files
committed
Improve warnings to call out if change matches consensus
1 parent 43b7232 commit a82844c

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

test/Clojure_json-path.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,26 +18,31 @@ queries:
1818
document: ["first", "second", "third"]
1919
result: "second"
2020
status: fail
21+
consensus: ["second", "third"]
2122
- id: array_index_slice_only_end
2223
selector: $[:2]
2324
document: ["first", "second", "third", "forth", "fifth"]
2425
result: "third"
2526
status: fail
27+
consensus: ["first", "second"]
2628
- id: array_index_slice_only_start
2729
selector: $[1:]
2830
document: ["first", "second", "third", "forth", "fifth"]
2931
result: "second"
3032
status: fail
33+
consensus: ["second", "third", "forth", "fifth"]
3134
- id: array_index_slice_start_end
3235
selector: $[1:3]
3336
document: ["first", "second", "third", "forth", "fifth"]
3437
result: "second"
3538
status: fail
39+
consensus: ["second", "third"]
3640
- id: array_index_slice_start_end_step
3741
selector: $[0:3:2]
3842
document: ["first", "second", "third", "forth", "fifth"]
3943
result: "first"
4044
status: fail
45+
consensus: ["first", "third"]
4146
- id: array_index_slice_start_end_step_0
4247
selector: $[0:3:0]
4348
document: ["first", "second", "third", "forth", "fifth"]
@@ -48,11 +53,13 @@ queries:
4853
document: ["first", "second", "third", "forth", "fifth"]
4954
result: "first"
5055
status: fail
56+
consensus: ["first", "second", "third"]
5157
- id: array_index_slice_start_end_step_non_aligned
5258
selector: $[0:4:2]
5359
document: ["first", "second", "third", "forth", "fifth"]
5460
result: "first"
5561
status: fail
62+
consensus: ["first", "third"]
5663
- id: array_index_slice_start_equals_end
5764
selector: $[0:0]
5865
document: ["first", "second"]
@@ -63,16 +70,19 @@ queries:
6370
document: ["first", "second"]
6471
result: "first"
6572
status: fail
73+
consensus: ["first"]
6674
- id: array_index_union
6775
selector: $[0,1]
6876
document: ["first", "second", "third"]
6977
result: "first"
7078
status: fail
79+
consensus: ["first", "second"]
7180
- id: key_bracket_notation_with_star_literal
7281
selector: $['*']
7382
document: {"*": "value"}
7483
result: ["value"]
7584
status: fail
85+
consensus: "value"
7686
- id: key_dot_notation
7787
selector: $.key
7888
document: {"key": "value"}
@@ -123,6 +133,7 @@ queries:
123133
document: ["string", 42, {"key": "value"}, [0, 1]]
124134
result: ["string", 42, {"key": "value"}, 0, 1]
125135
status: fail
136+
consensus: ["string", 42, {"key": "value"}, [0, 1]]
126137
- id: wildcard_bracket_notation_on_null_value_array
127138
selector: $[*]
128139
document: [40, null, 42]
@@ -133,13 +144,16 @@ queries:
133144
document: {"some": "string", "int": 42, "object": {"key": "value"}, "array": [0, 1]}
134145
result: ["string", 42, {"key": "value"}, 0, 1]
135146
status: fail
147+
consensus: ["string", 42, {"key": "value"}, [0, 1]]
136148
- id: wildcard_dot_notation_on_array
137149
selector: $.*
138150
document: ["string", 42, {"key": "value"}, [0, 1]]
139151
result: ["string", 42, {"key": "value"}, 0, 1]
140152
status: fail
153+
consensus: ["string", 42, {"key": "value"}, [0, 1]]
141154
- id: wildcard_dot_notation_on_object
142155
selector: $.*
143156
document: {"some": "string", "int": 42, "object": {"key": "value"}, "array": [0, 1]}
144157
result: ["string", 42, {"key": "value"}, 0, 1]
145158
status: fail
159+
consensus: ["string", 42, {"key": "value"}, [0, 1]]

test/json_path/test/regression_test.clj

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,17 @@
2222
(deftest warning-on-changes-for-non-conforming-queries-based-on-consensus
2323
(->> (queries_from_suite "test/Clojure_json-path.yaml")
2424
(filter (fn [{status :status}] (not= status "pass")))
25-
(map (fn [{:keys [selector document result status id]}]
25+
(map (fn [{:keys [selector document result status consensus id]}]
2626
(testing id
2727
(let [last-recorded result
2828
current (json-path/at-path selector document)]
2929
(when (not= last-recorded
3030
current)
31-
(println (format "Warning: result has changed for %s: %s (status %s)" id selector status))
32-
(println (format " was %s" (pr-str last-recorded)))
33-
(println (format " now is %s" (pr-str current))))))))
31+
(if (= consensus
32+
current)
33+
(println (format "Result has changed for %s: %s now matching the consensus" id selector))
34+
(do
35+
(println (format "Warning: result has changed for %s: %s (status %s)" id selector status))
36+
(println (format " was %s" (pr-str last-recorded)))
37+
(println (format " now is %s" (pr-str current))))))))))
3438
doall))

0 commit comments

Comments
 (0)