Skip to content

Commit f702c5c

Browse files
mvdancueckoo
authored andcommitted
encoding/jsonschema: fix the tests on Go tip
Due to https://go.dev/issue/70780 now being fixed at Go tip for 1.25, the tests started failing as we unexpectedly succeeded at extracting and compiling schemas using those regexp character classes. Fix the tests on Go tip by having them be skipped, so that testdata faithfully reflects what most people see with CUE on the latest Go 1.24. Leave TODOs as reminders to update this as Go releases progress. Signed-off-by: Daniel Martí <[email protected]> Change-Id: I0dd9016ee006745eaca7c17003f97e37f21b4c26 Dispatch-Trailer: {"type":"trybot","CL":1214302,"patchset":1,"ref":"refs/changes/02/1214302/1","targetBranch":"master"}
1 parent 4b194d7 commit f702c5c

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

encoding/jsonschema/external_test.go

+24
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"maps"
2222
"os"
2323
"path"
24+
"regexp"
2425
"slices"
2526
"strings"
2627
"testing"
@@ -79,6 +80,13 @@ func TestExternal(t *testing.T) {
7980
qt.Assert(t, qt.IsNil(err))
8081
}
8182

83+
var rxCharacterClassCategoryAlias = regexp.MustCompile(`\\p{(Cased_Letter|Close_Punctuation|Combining_Mark|Connector_Punctuation|Control|Currency_Symbol|Dash_Punctuation|Decimal_Number|Enclosing_Mark|Final_Punctuation|Format|Initial_Punctuation|Letter|Letter_Number|Line_Separator|Lowercase_Letter|Mark|Math_Symbol|Modifier_Letter|Modifier_Symbol|Nonspacing_Mark|Number|Open_Punctuation|Other|Other_Letter|Other_Number|Other_Punctuation|Other_Symbol|Paragraph_Separator|Private_Use|Punctuation|Separator|Space_Separator|Spacing_Mark|Surrogate|Symbol|Titlecase_Letter|Unassigned|Uppercase_Letter|cntrl|digit|punct)}`)
84+
85+
var supportsCharacterClassCategoryAlias = func() bool {
86+
_, err := regexp.Compile(`\p{Letter}`)
87+
return err == nil
88+
}()
89+
8290
func runExternalSchemaTests(t *testing.T, m *cuetdtest.M, filename string, s *externaltest.Schema) {
8391
t.Logf("file %v", path.Join("testdata/external", filename))
8492
ctx := m.CueContext()
@@ -94,6 +102,22 @@ func runExternalSchemaTests(t *testing.T, m *cuetdtest.M, filename string, s *ex
94102
if vers == jsonschema.VersionUnknown {
95103
t.Skipf("skipping test for unknown schema version %v", versStr)
96104
}
105+
106+
// The upcoming Go 1.25 implements Unicode category aliases in regular expressions,
107+
// such that e.g. \p{Letter} begins working on Go tip and 1.25 pre-releases.
108+
// Our tests must run on the latest two stable Go versions, currently 1.23 and 1.24,
109+
// where such character classes lead to schema compilation errors.
110+
//
111+
// As a temporary compromise, only run these tests on the broken and older Go versions.
112+
// With the testdata files being updated with the latest stable Go, 1.24,
113+
// this results in testdata reflecting what most Go users see with the latest Go,
114+
// while we are still able to use `go test` normally with Go tip.
115+
// TODO: swap around to expect the fixed behavior once Go 1.25.0 is released.
116+
// TODO: get rid of this whole thing once we require Go 1.25 or later in the future.
117+
if rxCharacterClassCategoryAlias.Match(s.Schema) && supportsCharacterClassCategoryAlias {
118+
t.Skip("regexp character classes for Unicode category aliases work only on Go 1.25 and later")
119+
}
120+
97121
schemaAST, extractErr := jsonschema.Extract(jsonValue, &jsonschema.Config{
98122
StrictFeatures: true,
99123
DefaultVersion: vers,

0 commit comments

Comments
 (0)