Skip to content

Commit d20e479

Browse files
committed
encoding/jsonschema: commit external test stats
This makes the JSON Schema external test statistics a little more obvious in code review. Signed-off-by: Roger Peppe <[email protected]> Change-Id: Id508a24d0636e9af6a1a44d5fed98bf89947d986 Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1200529 Reviewed-by: Daniel Martí <[email protected]> TryBot-Result: CUEcueckoo <[email protected]>
1 parent bfce150 commit d20e479

File tree

3 files changed

+40
-15
lines changed

3 files changed

+40
-15
lines changed

encoding/jsonschema/external_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ import (
4040
// The commit below references the JSON schema test main branch as of Sun May 19 19:01:03 2024 +0300
4141

4242
//go:generate go run vendor_external.go -- 9fc880bfb6d8ccd093bc82431f17d13681ffae8e
43+
//go:generate go run teststats.go -o external_teststats.txt
4344

4445
const testDir = "testdata/external"
4546

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Generated by teststats. DO NOT EDIT
2+
v2:
3+
schema extract (pass / total): 975 / 1637 = 59.6%
4+
tests (pass / total): 3140 / 7175 = 43.8%
5+
tests on extracted schemas (pass / total): 3140 / 3546 = 88.6%
6+
7+
v3:
8+
schema extract (pass / total): 967 / 1637 = 59.1%
9+
tests (pass / total): 3074 / 7175 = 42.8%
10+
tests on extracted schemas (pass / total): 3074 / 3538 = 86.9%

encoding/jsonschema/teststats.go

+29-15
Original file line numberDiff line numberDiff line change
@@ -20,36 +20,50 @@ package main
2020
import (
2121
"flag"
2222
"fmt"
23+
"io"
2324
"log"
25+
"os"
2426
"path"
2527
"sort"
2628

2729
"cuelang.org/go/cue/token"
2830
"cuelang.org/go/encoding/jsonschema/internal/externaltest"
2931
)
3032

31-
var list = flag.String("list", "", "list all failed tests for a given evaluator version")
33+
var (
34+
list = flag.String("list", "", "list all failed tests for a given evaluator version")
35+
out = flag.String("o", "", "write output to a file")
36+
)
3237

3338
const testDir = "testdata/external"
3439

3540
func main() {
41+
flag.Parse()
3642
tests, err := externaltest.ReadTestDir(testDir)
3743
if err != nil {
3844
log.Fatal(err)
3945
}
40-
flag.Parse()
46+
outw := os.Stdout
47+
if *out != "" {
48+
var err error
49+
outw, err = os.Create(*out)
50+
if err != nil {
51+
log.Fatal(err)
52+
}
53+
fmt.Fprintf(outw, "# Generated by teststats. DO NOT EDIT\n")
54+
}
4155
if *list != "" {
42-
listFailures(*list, tests)
56+
listFailures(outw, *list, tests)
4357
} else {
44-
fmt.Printf("v2:\n")
45-
showStats("v2", tests)
46-
fmt.Println()
47-
fmt.Printf("v3:\n")
48-
showStats("v3", tests)
58+
fmt.Fprintf(outw, "v2:\n")
59+
showStats(outw, "v2", tests)
60+
fmt.Fprintf(outw, "\n")
61+
fmt.Fprintf(outw, "v3:\n")
62+
showStats(outw, "v3", tests)
4963
}
5064
}
5165

52-
func showStats(version string, tests map[string][]*externaltest.Schema) {
66+
func showStats(outw io.Writer, version string, tests map[string][]*externaltest.Schema) {
5367
schemaOK := 0
5468
schemaTot := 0
5569
testOK := 0
@@ -76,17 +90,17 @@ func showStats(version string, tests map[string][]*externaltest.Schema) {
7690
}
7791
}
7892
}
79-
fmt.Printf("\tschema extract (pass / total): %d / %d = %.1f%%\n", schemaOK, schemaTot, percent(schemaOK, schemaTot))
80-
fmt.Printf("\ttests (pass / total): %d / %d = %.1f%%\n", testOK, testTot, percent(testOK, testTot))
81-
fmt.Printf("\ttests on extracted schemas (pass / total): %d / %d = %.1f%%\n", schemaOKTestOK, schemaOKTestTot, percent(schemaOKTestOK, schemaOKTestTot))
93+
fmt.Fprintf(outw, "\tschema extract (pass / total): %d / %d = %.1f%%\n", schemaOK, schemaTot, percent(schemaOK, schemaTot))
94+
fmt.Fprintf(outw, "\ttests (pass / total): %d / %d = %.1f%%\n", testOK, testTot, percent(testOK, testTot))
95+
fmt.Fprintf(outw, "\ttests on extracted schemas (pass / total): %d / %d = %.1f%%\n", schemaOKTestOK, schemaOKTestTot, percent(schemaOKTestOK, schemaOKTestTot))
8296
}
8397

84-
func listFailures(version string, tests map[string][]*externaltest.Schema) {
98+
func listFailures(outw io.Writer, version string, tests map[string][]*externaltest.Schema) {
8599
for _, filename := range sortedKeys(tests) {
86100
schemas := tests[filename]
87101
for _, schema := range schemas {
88102
if schema.Skip[version] != "" {
89-
fmt.Printf("%s: schema fail (%s)\n", testdataPos(schema), schema.Description)
103+
fmt.Fprintf(outw, "%s: schema fail (%s)\n", testdataPos(schema), schema.Description)
90104
continue
91105
}
92106
for _, test := range schema.Tests {
@@ -95,7 +109,7 @@ func listFailures(version string, tests map[string][]*externaltest.Schema) {
95109
if !test.Valid {
96110
reason = "unexpected success"
97111
}
98-
fmt.Printf("%s: %s (%s; %s)\n", testdataPos(test), reason, schema.Description, test.Description)
112+
fmt.Fprintf(outw, "%s: %s (%s; %s)\n", testdataPos(test), reason, schema.Description, test.Description)
99113
}
100114
}
101115
}

0 commit comments

Comments
 (0)