this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

encoding/jsonschema: improve teststats

It's useful to be able to print all the tests that fail
in v3-roundtrip that don't fail in v3, so add that
functionality.

Also try to print a position from the embedded json
data rather than from the schema that verifies it.

Signed-off-by: Roger Peppe <rogpeppe@gmail.com>
Change-Id: Ic40fece68bff3ccd5aa2e099288b0f2634468865
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1224358
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>
Unity-Result: CUE porcuepine <cue.porcuepine@gmail.com>
Reviewed-by: Daniel Martí <mvdan@mvdan.cc>

+58 -12
+29 -1
encoding/jsonschema/internal/externaltest/tests.go
··· 4 4 "bytes" 5 5 stdjson "encoding/json" 6 6 "fmt" 7 + "iter" 7 8 "os" 8 9 "path/filepath" 10 + "strings" 9 11 10 12 "cuelang.org/go/cue" 11 13 "cuelang.org/go/cue/cuecontext" ··· 47 49 } 48 50 49 51 func (loc location) Pos() token.Pos { 50 - return loc.root.LookupPath(loc.path).Pos() 52 + var v cue.Value 53 + for v = range conjuncts(loc.root.LookupPath(loc.path)) { 54 + p := v.Pos() 55 + if strings.HasSuffix(p.Filename(), ".json") { 56 + return p 57 + } 58 + } 59 + return v.Pos() 60 + } 61 + 62 + func conjuncts(v cue.Value) iter.Seq[cue.Value] { 63 + return func(yield func(cue.Value) bool) { 64 + yieldConjuncts(v, yield) 65 + } 66 + } 67 + 68 + func yieldConjuncts(v cue.Value, yield func(cue.Value) bool) bool { 69 + op, args := v.Expr() 70 + if op != cue.AndOp { 71 + return yield(v) 72 + } 73 + for _, v := range args { 74 + if !yieldConjuncts(v, yield) { 75 + return false 76 + } 77 + } 78 + return true 51 79 } 52 80 53 81 // WriteTestDir writes test data files as read by ReadTestDir
+29 -11
encoding/jsonschema/teststats.go
··· 26 26 "os" 27 27 "path" 28 28 "slices" 29 + "strings" 29 30 30 31 "cuelang.org/go/cue/token" 31 32 "cuelang.org/go/encoding/jsonschema/internal/externaltest" ··· 36 37 func main() { 37 38 flag.Usage = func() { 38 39 fmt.Fprintf(os.Stderr, "usage: teststats version\n") 39 - fmt.Fprintf(os.Stderr, "\nList all failed tests for the given evaluator version (e.g. v3)\n") 40 + fmt.Fprintf(os.Stderr, ` 41 + List all failed tests for the given evaluator version (e.g. v3). 42 + If multiple versions are given, it prints tests that fail for all 43 + those versions. If a version starts with a ! character, 44 + it excludes tests that do not fail for that version. 45 + `) 40 46 os.Exit(2) 41 47 } 42 48 flag.Parse() ··· 44 50 if err != nil { 45 51 log.Fatal(err) 46 52 } 47 - if flag.NArg() != 1 { 53 + if flag.NArg() < 1 { 48 54 flag.Usage() 49 55 } 50 - listFailures(os.Stdout, flag.Arg(0), tests) 56 + listFailures(os.Stdout, flag.Args(), tests) 51 57 } 52 58 53 - func listFailures(outw io.Writer, version string, tests map[string][]*externaltest.Schema) { 59 + func listFailures(outw io.Writer, versions []string, tests map[string][]*externaltest.Schema) { 54 60 for _, filename := range slices.Sorted(maps.Keys(tests)) { 55 61 schemas := tests[filename] 56 62 for _, schema := range schemas { 57 - if schema.Skip[version] != "" { 63 + if match(schema.Skip, versions) { 58 64 fmt.Fprintf(outw, "%s: schema fail (%s)\n", testdataPos(schema), schema.Description) 59 65 continue 60 66 } 61 67 for _, test := range schema.Tests { 62 - if test.Skip[version] != "" { 63 - reason := "fail" 64 - if !test.Valid { 65 - reason = "unexpected success" 66 - } 67 - fmt.Fprintf(outw, "%s: %s (%s; %s)\n", testdataPos(test), reason, schema.Description, test.Description) 68 + if !match(test.Skip, versions) { 69 + continue 68 70 } 71 + reason := "fail" 72 + if !test.Valid { 73 + reason = "unexpected success" 74 + } 75 + fmt.Fprintf(outw, "%s: %s (%s; %s)\n", testdataPos(test), reason, schema.Description, test.Description) 69 76 } 70 77 } 71 78 } 79 + } 80 + 81 + func match(skip map[string]string, versions []string) bool { 82 + for _, v := range versions { 83 + v, wantSuccess := strings.CutPrefix(v, "!") 84 + _, failed := skip[v] 85 + if failed != !wantSuccess { 86 + return false 87 + } 88 + } 89 + return true 72 90 } 73 91 74 92 type positioner interface {