cuelang.org/go@v0.13.0/encoding/jsonschema/teststats.go (about) 1 // Copyright 2024 CUE Authors 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 //go:build ignore 16 17 // This command prints a summary of which external tests are passing and failing. 18 package main 19 20 import ( 21 "flag" 22 "fmt" 23 "io" 24 "log" 25 "maps" 26 "os" 27 "path" 28 "slices" 29 30 "cuelang.org/go/cue/token" 31 "cuelang.org/go/encoding/jsonschema/internal/externaltest" 32 ) 33 34 const testDir = "testdata/external" 35 36 func main() { 37 flag.Usage = func() { 38 fmt.Fprintf(os.Stderr, "usage: teststats version\n") 39 fmt.Fprintf(os.Stderr, "\nList all failed tests for the given evaluator version (e.g. v2 or v3)\n") 40 os.Exit(2) 41 } 42 flag.Parse() 43 tests, err := externaltest.ReadTestDir(testDir) 44 if err != nil { 45 log.Fatal(err) 46 } 47 if flag.NArg() != 1 { 48 flag.Usage() 49 } 50 listFailures(os.Stdout, flag.Arg(0), tests) 51 } 52 53 func listFailures(outw io.Writer, version string, tests map[string][]*externaltest.Schema) { 54 for _, filename := range slices.Sorted(maps.Keys(tests)) { 55 schemas := tests[filename] 56 for _, schema := range schemas { 57 if schema.Skip[version] != "" { 58 fmt.Fprintf(outw, "%s: schema fail (%s)\n", testdataPos(schema), schema.Description) 59 continue 60 } 61 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 } 69 } 70 } 71 } 72 } 73 74 type positioner interface { 75 Pos() token.Pos 76 } 77 78 func testdataPos(p positioner) token.Position { 79 pp := p.Pos().Position() 80 pp.Filename = path.Join(testDir, pp.Filename) 81 return pp 82 }