Skip to content

Commit 3ba376f

Browse files
committed
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 Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1214302 Unity-Result: CUE porcuepine <[email protected]> TryBot-Result: CUEcueckoo <[email protected]> Reviewed-by: Paul Jolly <[email protected]>
1 parent a1db0ad commit 3ba376f

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

encoding/jsonschema/external_test.go

+25
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,14 @@ 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+
//lint:ignore SA1000 this regular expression is meant to fail to compile on Go 1.24 and earlier
87+
_, err := regexp.Compile(`\p{Letter}`)
88+
return err == nil
89+
}()
90+
8291
func runExternalSchemaTests(t *testing.T, m *cuetdtest.M, filename string, s *externaltest.Schema) {
8392
t.Logf("file %v", path.Join("testdata/external", filename))
8493
ctx := m.CueContext()
@@ -94,6 +103,22 @@ func runExternalSchemaTests(t *testing.T, m *cuetdtest.M, filename string, s *ex
94103
if vers == jsonschema.VersionUnknown {
95104
t.Skipf("skipping test for unknown schema version %v", versStr)
96105
}
106+
107+
// The upcoming Go 1.25 implements Unicode category aliases in regular expressions,
108+
// such that e.g. \p{Letter} begins working on Go tip and 1.25 pre-releases.
109+
// Our tests must run on the latest two stable Go versions, currently 1.23 and 1.24,
110+
// where such character classes lead to schema compilation errors.
111+
//
112+
// As a temporary compromise, only run these tests on the broken and older Go versions.
113+
// With the testdata files being updated with the latest stable Go, 1.24,
114+
// this results in testdata reflecting what most Go users see with the latest Go,
115+
// while we are still able to use `go test` normally with Go tip.
116+
// TODO: swap around to expect the fixed behavior once Go 1.25.0 is released.
117+
// TODO: get rid of this whole thing once we require Go 1.25 or later in the future.
118+
if rxCharacterClassCategoryAlias.Match(s.Schema) && supportsCharacterClassCategoryAlias {
119+
t.Skip("regexp character classes for Unicode category aliases work only on Go 1.25 and later")
120+
}
121+
97122
schemaAST, extractErr := jsonschema.Extract(jsonValue, &jsonschema.Config{
98123
StrictFeatures: true,
99124
DefaultVersion: vers,

0 commit comments

Comments
 (0)