Skip to content

Commit 9959a3e

Browse files
committed
encoding/jsonschema: prepare for matrix test runs
Currently we are just running the external tests on the old evaluator, but we want confidence in what's happening in both evaluators. In order to do so, we will record skip reasons for both old and new evaluators, so prepare for that by making the `skip` field into a struct and moving all the existing skip fields into a field inside that, corresponding to the point in the matrix that is being run currently. In the next CL, we will actually run the matrix tests and populate the `skip.v3` field. Most of this CL has been accomplished with an automated script. Also, in passing, remove the `externaltest.ParseTestData` function as it's not used. Signed-off-by: Roger Peppe <[email protected]> Change-Id: I6f59c6eb837a7c15eb7467f6860167534b6d1e75 Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1200519 TryBot-Result: CUEcueckoo <[email protected]> Unity-Result: CUE porcuepine <[email protected]> Reviewed-by: Daniel Martí <[email protected]>
1 parent 1a2e26e commit 9959a3e

File tree

261 files changed

+14494
-4852
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

261 files changed

+14494
-4852
lines changed

encoding/jsonschema/external_test.go

+7-7
Original file line numberDiff line numberDiff line change
@@ -203,28 +203,28 @@ func testName(s string) string {
203203
// testFailed marks the current test as failed with the
204204
// given error message, and updates the
205205
// skip field pointed to by skipField if necessary.
206-
func testFailed(t *testing.T, skipField *string, p positioner, errStr string) {
206+
func testFailed(t *testing.T, skipField *externaltest.Skip, p positioner, errStr string) {
207207
if cuetest.UpdateGoldenFiles {
208-
if *skipField == "" && !allowRegressions() {
208+
if *skipField == nil && !allowRegressions() {
209209
t.Fatalf("test regression; was succeeding, now failing: %v", errStr)
210210
}
211-
*skipField = errStr
211+
*skipField = externaltest.Skip{"v2": errStr}
212212
return
213213
}
214-
if *skipField != "" {
214+
if *skipField != nil {
215215
t.Skipf("skipping due to known error: %v", *skipField)
216216
}
217217
t.Fatal(errStr)
218218
}
219219

220220
// testFails marks the current test as succeeded and updates the
221221
// skip field pointed to by skipField if necessary.
222-
func testSucceeded(t *testing.T, skipField *string, p positioner) {
222+
func testSucceeded(t *testing.T, skipField *externaltest.Skip, p positioner) {
223223
if cuetest.UpdateGoldenFiles {
224-
*skipField = ""
224+
*skipField = nil
225225
return
226226
}
227-
if *skipField != "" {
227+
if *skipField != nil {
228228
t.Fatalf("unexpectedly more correct behavior (test success) on skipped test")
229229
}
230230
}

encoding/jsonschema/internal/externaltest/tests.go

+10-11
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package externaltest
22

33
import (
44
"bytes"
5-
"encoding/json"
65
stdjson "encoding/json"
76
"fmt"
87
"os"
@@ -20,7 +19,7 @@ type Schema struct {
2019
Description string `json:"description"`
2120
Comment string `json:"comment,omitempty"`
2221
Schema stdjson.RawMessage `json:"schema"`
23-
Skip string `json:"skip,omitempty"`
22+
Skip Skip `json:"skip,omitempty"`
2423
Tests []*Test `json:"tests"`
2524
}
2625

@@ -30,9 +29,17 @@ type Test struct {
3029
Comment string `json:"comment,omitempty"`
3130
Data stdjson.RawMessage `json:"data"`
3231
Valid bool `json:"valid"`
33-
Skip string `json:"skip,omitempty"`
32+
Skip Skip `json:"skip,omitempty"`
3433
}
3534

35+
// Skip records information about whether a given schema
36+
// or test will be skipped when testing. If not present,
37+
// the test will be expected to pass.
38+
//
39+
// Each key in the map represents the name of a point
40+
// in the cuetdtest matrix.
41+
type Skip map[string]string
42+
3643
type location struct {
3744
root cue.Value
3845
path cue.Path
@@ -42,14 +49,6 @@ func (loc location) Pos() token.Pos {
4249
return loc.root.LookupPath(loc.path).Pos()
4350
}
4451

45-
func ParseTestData(data []byte) ([]*Schema, error) {
46-
var schemas []*Schema
47-
if err := json.Unmarshal(data, &schemas); err != nil {
48-
return nil, err
49-
}
50-
return schemas, nil
51-
}
52-
5352
// WriteTestDir writes test data files as read by ReadTestDir
5453
// to the given directory. The keys of tests are filenames relative
5554
// to dir.

encoding/jsonschema/testdata/external/config.cue

+13-4
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,8 @@ allTests: [_]: [... #Schema]
1919
// skip is not part of the orginal test data, but
2020
// is inserted by our test logic (when CUE_UPDATE=1)
2121
// to indicate which tests are passing and which
22-
// are failing. The text indicates some reason as to
23-
// why the schema is skipped.
24-
skip?: string
22+
// are failing. See #Skip for details.
23+
skip?: #Skip
2524
}
2625

2726
#Test: {
@@ -35,5 +34,15 @@ allTests: [_]: [... #Schema]
3534
// to indicate which tests are passing and which
3635
// are failing. The text indicates some reason as to
3736
// why the test is skipped.
38-
skip?: string
37+
skip?: #Skip
38+
}
39+
40+
// #Skip indicates that a test or schema should be skipped
41+
// in the external test. The text indicates some reason as to
42+
// why the schema is skipped for a given evaluator version.
43+
//
44+
// If all fields are empty, the skip field itself should be omitted.
45+
#Skip: {
46+
v2?: string
47+
v3?: string
3948
}

encoding/jsonschema/testdata/external/tests/draft2019-09/additionalItems.json

+15-5
Original file line numberDiff line numberDiff line change
@@ -102,15 +102,19 @@
102102
"description": "empty array",
103103
"data": [],
104104
"valid": true,
105-
"skip": "5 errors in empty disjunction:\nconflicting values [] and {...} (mismatched types list and struct):\n generated.cue:2:1\n generated.cue:2:45\n instance.json:1:1\nconflicting values bool and [] (mismatched types bool and list):\n generated.cue:2:8\n instance.json:1:1\nconflicting values null and [] (mismatched types null and list):\n generated.cue:2:1\n instance.json:1:1\nconflicting values number and [] (mismatched types number and list):\n generated.cue:2:15\n instance.json:1:1\nconflicting values string and [] (mismatched types string and list):\n generated.cue:2:24\n instance.json:1:1\n"
105+
"skip": {
106+
"v2": "5 errors in empty disjunction:\nconflicting values [] and {...} (mismatched types list and struct):\n generated.cue:2:1\n generated.cue:2:45\n instance.json:1:1\nconflicting values bool and [] (mismatched types bool and list):\n generated.cue:2:8\n instance.json:1:1\nconflicting values null and [] (mismatched types null and list):\n generated.cue:2:1\n instance.json:1:1\nconflicting values number and [] (mismatched types number and list):\n generated.cue:2:15\n instance.json:1:1\nconflicting values string and [] (mismatched types string and list):\n generated.cue:2:24\n instance.json:1:1\n"
107+
}
106108
},
107109
{
108110
"description": "fewer number of items present (1)",
109111
"data": [
110112
1
111113
],
112114
"valid": true,
113-
"skip": "5 errors in empty disjunction:\nconflicting values [1] and {...} (mismatched types list and struct):\n generated.cue:2:1\n generated.cue:2:45\n instance.json:1:1\nconflicting values bool and [1] (mismatched types bool and list):\n generated.cue:2:8\n instance.json:1:1\nconflicting values null and [1] (mismatched types null and list):\n generated.cue:2:1\n instance.json:1:1\nconflicting values number and [1] (mismatched types number and list):\n generated.cue:2:15\n instance.json:1:1\nconflicting values string and [1] (mismatched types string and list):\n generated.cue:2:24\n instance.json:1:1\n"
115+
"skip": {
116+
"v2": "5 errors in empty disjunction:\nconflicting values [1] and {...} (mismatched types list and struct):\n generated.cue:2:1\n generated.cue:2:45\n instance.json:1:1\nconflicting values bool and [1] (mismatched types bool and list):\n generated.cue:2:8\n instance.json:1:1\nconflicting values null and [1] (mismatched types null and list):\n generated.cue:2:1\n instance.json:1:1\nconflicting values number and [1] (mismatched types number and list):\n generated.cue:2:15\n instance.json:1:1\nconflicting values string and [1] (mismatched types string and list):\n generated.cue:2:24\n instance.json:1:1\n"
117+
}
114118
},
115119
{
116120
"description": "fewer number of items present (2)",
@@ -119,7 +123,9 @@
119123
2
120124
],
121125
"valid": true,
122-
"skip": "5 errors in empty disjunction:\nconflicting values [1,2] and {...} (mismatched types list and struct):\n generated.cue:2:1\n generated.cue:2:45\n instance.json:1:1\nconflicting values bool and [1,2] (mismatched types bool and list):\n generated.cue:2:8\n instance.json:1:1\nconflicting values null and [1,2] (mismatched types null and list):\n generated.cue:2:1\n instance.json:1:1\nconflicting values number and [1,2] (mismatched types number and list):\n generated.cue:2:15\n instance.json:1:1\nconflicting values string and [1,2] (mismatched types string and list):\n generated.cue:2:24\n instance.json:1:1\n"
126+
"skip": {
127+
"v2": "5 errors in empty disjunction:\nconflicting values [1,2] and {...} (mismatched types list and struct):\n generated.cue:2:1\n generated.cue:2:45\n instance.json:1:1\nconflicting values bool and [1,2] (mismatched types bool and list):\n generated.cue:2:8\n instance.json:1:1\nconflicting values null and [1,2] (mismatched types null and list):\n generated.cue:2:1\n instance.json:1:1\nconflicting values number and [1,2] (mismatched types number and list):\n generated.cue:2:15\n instance.json:1:1\nconflicting values string and [1,2] (mismatched types string and list):\n generated.cue:2:24\n instance.json:1:1\n"
128+
}
123129
},
124130
{
125131
"description": "equal number of items present",
@@ -188,7 +194,9 @@
188194
false
189195
],
190196
"valid": true,
191-
"skip": "5 errors in empty disjunction:\nconflicting values [1,\"foo\",false] and {...} (mismatched types list and struct):\n generated.cue:2:1\n generated.cue:2:41\n instance.json:1:1\nconflicting values bool and [1,\"foo\",false] (mismatched types bool and list):\n generated.cue:2:8\n instance.json:1:1\nconflicting values null and [1,\"foo\",false] (mismatched types null and list):\n generated.cue:2:1\n instance.json:1:1\nconflicting values number and [1,\"foo\",false] (mismatched types number and list):\n generated.cue:2:15\n instance.json:1:1\nconflicting values string and [1,\"foo\",false] (mismatched types string and list):\n generated.cue:2:24\n instance.json:1:1\n"
197+
"skip": {
198+
"v2": "5 errors in empty disjunction:\nconflicting values [1,\"foo\",false] and {...} (mismatched types list and struct):\n generated.cue:2:1\n generated.cue:2:41\n instance.json:1:1\nconflicting values bool and [1,\"foo\",false] (mismatched types bool and list):\n generated.cue:2:8\n instance.json:1:1\nconflicting values null and [1,\"foo\",false] (mismatched types null and list):\n generated.cue:2:1\n instance.json:1:1\nconflicting values number and [1,\"foo\",false] (mismatched types number and list):\n generated.cue:2:15\n instance.json:1:1\nconflicting values string and [1,\"foo\",false] (mismatched types string and list):\n generated.cue:2:24\n instance.json:1:1\n"
199+
}
192200
}
193201
]
194202
},
@@ -217,7 +225,9 @@
217225
null
218226
],
219227
"valid": true,
220-
"skip": "5 errors in empty disjunction:\nconflicting values [1,null] and {...} (mismatched types list and struct):\n generated.cue:2:1\n generated.cue:2:41\n instance.json:1:1\nconflicting values bool and [1,null] (mismatched types bool and list):\n generated.cue:2:8\n instance.json:1:1\nconflicting values null and [1,null] (mismatched types null and list):\n generated.cue:2:1\n instance.json:1:1\nconflicting values number and [1,null] (mismatched types number and list):\n generated.cue:2:15\n instance.json:1:1\nconflicting values string and [1,null] (mismatched types string and list):\n generated.cue:2:24\n instance.json:1:1\n"
228+
"skip": {
229+
"v2": "5 errors in empty disjunction:\nconflicting values [1,null] and {...} (mismatched types list and struct):\n generated.cue:2:1\n generated.cue:2:41\n instance.json:1:1\nconflicting values bool and [1,null] (mismatched types bool and list):\n generated.cue:2:8\n instance.json:1:1\nconflicting values null and [1,null] (mismatched types null and list):\n generated.cue:2:1\n instance.json:1:1\nconflicting values number and [1,null] (mismatched types number and list):\n generated.cue:2:15\n instance.json:1:1\nconflicting values string and [1,null] (mismatched types string and list):\n generated.cue:2:24\n instance.json:1:1\n"
230+
}
221231
}
222232
]
223233
},

encoding/jsonschema/testdata/external/tests/draft2019-09/additionalProperties.json

+27-9
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@
2828
"quux": "boom"
2929
},
3030
"valid": false,
31-
"skip": "unexpected success"
31+
"skip": {
32+
"v2": "unexpected success"
33+
}
3234
},
3335
{
3436
"description": "ignores arrays",
@@ -82,7 +84,9 @@
8284
"élmény": 2
8385
},
8486
"valid": false,
85-
"skip": "unexpected success"
87+
"skip": {
88+
"v2": "unexpected success"
89+
}
8690
}
8791
]
8892
},
@@ -227,15 +231,19 @@
227231
"type": "number"
228232
}
229233
},
230-
"skip": "extract error: cannot compile resulting schema: reference \"strings\" in label expression refers to field against which it would be matched:\n generated.cue:5:3\n",
234+
"skip": {
235+
"v2": "extract error: cannot compile resulting schema: reference \"strings\" in label expression refers to field against which it would be matched:\n generated.cue:5:3\n"
236+
},
231237
"tests": [
232238
{
233239
"description": "Valid against both keywords",
234240
"data": {
235241
"apple": 4
236242
},
237243
"valid": true,
238-
"skip": "could not compile schema"
244+
"skip": {
245+
"v2": "could not compile schema"
246+
}
239247
},
240248
{
241249
"description": "Valid against propertyNames, but not additionalProperties",
@@ -244,7 +252,9 @@
244252
"pear": "available"
245253
},
246254
"valid": false,
247-
"skip": "could not compile schema"
255+
"skip": {
256+
"v2": "could not compile schema"
257+
}
248258
}
249259
]
250260
},
@@ -265,23 +275,29 @@
265275
},
266276
"additionalProperties": false
267277
},
268-
"skip": "extract error: unsupported constraint \"dependentSchemas\"",
278+
"skip": {
279+
"v2": "extract error: unsupported constraint \"dependentSchemas\""
280+
},
269281
"tests": [
270282
{
271283
"description": "additionalProperties doesn't consider dependentSchemas",
272284
"data": {
273285
"foo": ""
274286
},
275287
"valid": false,
276-
"skip": "could not compile schema"
288+
"skip": {
289+
"v2": "could not compile schema"
290+
}
277291
},
278292
{
279293
"description": "additionalProperties can't see bar",
280294
"data": {
281295
"bar": ""
282296
},
283297
"valid": false,
284-
"skip": "could not compile schema"
298+
"skip": {
299+
"v2": "could not compile schema"
300+
}
285301
},
286302
{
287303
"description": "additionalProperties can't see bar even when foo2 is present",
@@ -290,7 +306,9 @@
290306
"bar": ""
291307
},
292308
"valid": false,
293-
"skip": "could not compile schema"
309+
"skip": {
310+
"v2": "could not compile schema"
311+
}
294312
}
295313
]
296314
}

encoding/jsonschema/testdata/external/tests/draft2019-09/allOf.json

+24-8
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,19 @@
4141
"foo": "baz"
4242
},
4343
"valid": false,
44-
"skip": "unexpected success"
44+
"skip": {
45+
"v2": "unexpected success"
46+
}
4547
},
4648
{
4749
"description": "mismatch first",
4850
"data": {
4951
"bar": 2
5052
},
5153
"valid": false,
52-
"skip": "unexpected success"
54+
"skip": {
55+
"v2": "unexpected success"
56+
}
5357
},
5458
{
5559
"description": "wrong type",
@@ -113,7 +117,9 @@
113117
"baz": null
114118
},
115119
"valid": false,
116-
"skip": "unexpected success"
120+
"skip": {
121+
"v2": "unexpected success"
122+
}
117123
},
118124
{
119125
"description": "mismatch first allOf",
@@ -122,7 +128,9 @@
122128
"baz": null
123129
},
124130
"valid": false,
125-
"skip": "unexpected success"
131+
"skip": {
132+
"v2": "unexpected success"
133+
}
126134
},
127135
{
128136
"description": "mismatch second allOf",
@@ -131,15 +139,19 @@
131139
"bar": 2
132140
},
133141
"valid": false,
134-
"skip": "unexpected success"
142+
"skip": {
143+
"v2": "unexpected success"
144+
}
135145
},
136146
{
137147
"description": "mismatch both",
138148
"data": {
139149
"bar": 2
140150
},
141151
"valid": false,
142-
"skip": "unexpected success"
152+
"skip": {
153+
"v2": "unexpected success"
154+
}
143155
}
144156
]
145157
},
@@ -200,7 +212,9 @@
200212
"description": "any value is invalid",
201213
"data": "foo",
202214
"valid": false,
203-
"skip": "unexpected success"
215+
"skip": {
216+
"v2": "unexpected success"
217+
}
204218
}
205219
]
206220
},
@@ -218,7 +232,9 @@
218232
"description": "any value is invalid",
219233
"data": "foo",
220234
"valid": false,
221-
"skip": "unexpected success"
235+
"skip": {
236+
"v2": "unexpected success"
237+
}
222238
}
223239
]
224240
},

0 commit comments

Comments
 (0)