this repo has no description
0
fork

Configure Feed

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

internal: adapt to testing.TB.Context in Go 1.24

Thanks to Roger's proposal at https://go.dev/issue/36532,
Go at master just gained a new method in the testing package:

pkg testing, type TB interface, Context() context.Context

Our cuetdtest.M and cuetxtar.Test types implement testing.TB
as of Go 1.23, but with the addition of this new method,
our own `Context() cue.Context` methods conflict with the above.

Rename our Context methods to CueContext, which resolves this conflict
and is likely less confusing in the context of a testing.TB anyway.

Add testing.TB interface implementation assertions in both packages.
This way, the next time Go's testing.TB interface grows,
the errors will directly point to these two packages as build errors
as opposed to pointing to the dozen of downstream test packages.

Signed-off-by: Daniel Martí <mvdan@mvdan.cc>
Change-Id: I51869b22f42209e133056adca35a6970e47facc9
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1199833
Unity-Result: CUE porcuepine <cue.porcuepine@gmail.com>
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>
Reviewed-by: Matthew Sackman <matthew@cue.works>

+37 -29
+1 -1
cue/bench_test.go
··· 94 94 b.Run(m.Name(), func(b *testing.B) { 95 95 b.ReportAllocs() 96 96 for i := 0; i < b.N; i++ { 97 - ctx := m.Context() 97 + ctx := m.CueContext() 98 98 value := ctx.BuildInstance(cuetxtar.Load(a, b.TempDir())[0]) 99 99 value.Validate() 100 100 }
+14 -14
cue/types_test.go
··· 41 41 func getValue(t *cuetdtest.M, body string) cue.Value { 42 42 t.Helper() 43 43 44 - ctx := t.Context() 44 + ctx := t.CueContext() 45 45 return ctx.CompileString(body, cue.Filename("test")) 46 46 } 47 47 ··· 144 144 cuetdtest.FullMatrix.Run(t, "", func(t *cuetdtest.M) { 145 145 t.TODO_V3() 146 146 147 - ctx := t.Context() 147 + ctx := t.CueContext() 148 148 149 149 valIn := mustCompile(t, ctx, tc.input) 150 150 valOut := tc.fun(valIn) ··· 963 963 964 964 func TestLookup(t *testing.T) { 965 965 cuetdtest.FullMatrix.Do(t, func(t *cuetdtest.M) { 966 - ctx := t.Context() 966 + ctx := t.CueContext() 967 967 val := mustCompile(t, ctx, ` 968 968 #V: { 969 969 x: int ··· 1168 1168 1169 1169 func TestFillPath(t *testing.T) { 1170 1170 cuetdtest.FullMatrix.Do(t, func(t *cuetdtest.M) { 1171 - ctx := t.Context() 1171 + ctx := t.CueContext() 1172 1172 1173 1173 val := ctx.BuildExpr(ast.NewStruct("bar", ast.NewString("baz"))) 1174 1174 if err := val.Err(); err != nil { ··· 1403 1403 1404 1404 for _, tc := range testCases { 1405 1405 cuetdtest.FullMatrix.Run(t, "", func(t *cuetdtest.M) { 1406 - ctx := t.Context() 1406 + ctx := t.CueContext() 1407 1407 v := mustCompile(t, ctx, tc.in) 1408 1408 v = v.FillPath(tc.path, tc.x) 1409 1409 ··· 1659 1659 if tc.todo_nosharing { 1660 1660 t.TODO_NoSharing() 1661 1661 } 1662 - ctx := t.Context() 1662 + ctx := t.CueContext() 1663 1663 v := mustCompile(t, ctx, tc.in) 1664 1664 v = v.LookupPath(path) 1665 1665 ··· 1722 1722 1723 1723 for _, tc := range testCases { 1724 1724 cuetdtest.FullMatrix.Run(t, tc.def, func(t *cuetdtest.M) { 1725 - ctx := t.Context() 1725 + ctx := t.CueContext() 1726 1726 v := mustCompile(t, ctx, tc.in) 1727 1727 v = v.LookupDef(tc.def) 1728 1728 got := fmt.Sprint(v) ··· 2336 2336 }} 2337 2337 for _, tc := range testCases { 2338 2338 cuetdtest.FullMatrix.Run(t, "", func(t *cuetdtest.M) { 2339 - ctx := t.Context() 2339 + ctx := t.CueContext() 2340 2340 2341 2341 a := mustCompile(t, ctx, tc.a) 2342 2342 b := mustCompile(t, ctx, tc.b) ··· 2495 2495 t.TODO_V3() 2496 2496 } 2497 2497 2498 - ctx := t.Context() 2498 + ctx := t.CueContext() 2499 2499 val := ctx.CompileString(tc.in, cue.Filename("validate")) 2500 2500 err := val.Validate(tc.opts...) 2501 2501 if gotErr := err != nil; gotErr != tc.err { ··· 2528 2528 } 2529 2529 for _, tc := range testCases { 2530 2530 cuetdtest.FullMatrix.Run(t, strings.Join(tc, "."), func(t *cuetdtest.M) { 2531 - ctx := t.Context() 2531 + ctx := t.CueContext() 2532 2532 val := mustCompile(t, ctx, config) 2533 2533 2534 2534 v := val.Lookup(tc[0]) ··· 2697 2697 ` 2698 2698 2699 2699 cuetdtest.FullMatrix.Do(t, func(t *cuetdtest.M) { 2700 - ctx := t.Context() 2700 + ctx := t.CueContext() 2701 2701 v1 := mustCompile(t, ctx, config) 2702 2702 v2 := mustCompile(t, ctx, config2) 2703 2703 both := v1.Unify(v2) ··· 3168 3168 }} 3169 3169 for _, tc := range testCases { 3170 3170 cuetdtest.FullMatrix.Run(t, "", func(t *cuetdtest.M) { 3171 - ctx := t.Context() 3171 + ctx := t.CueContext() 3172 3172 3173 3173 val := ctx.CompileString(tc.input, cue.Filename("in")) 3174 3174 v := val.Lookup("v", "w", "x") ··· 3263 3263 t.TODO_V3() 3264 3264 } 3265 3265 3266 - c := t.Context() 3266 + c := t.CueContext() 3267 3267 v := c.CompileString(tc.value) 3268 3268 v = v.LookupPath(cue.ParsePath("a")) 3269 3269 pos := v.Pos().String() ··· 3519 3519 continue 3520 3520 } 3521 3521 cuetdtest.FullMatrix.Run(t, "", func(t *cuetdtest.M) { 3522 - ctx := t.Context() 3522 + ctx := t.CueContext() 3523 3523 3524 3524 // don't use mustCompile because some test cases here need to 3525 3525 // inspect the value error.
+1 -1
encoding/jsonschema/decode_test.go
··· 63 63 } 64 64 cfg.Strict = t.HasTag("strict") 65 65 66 - ctx := t.Context() 66 + ctx := t.CueContext() 67 67 68 68 fsys, err := txtar.FS(t.Archive) 69 69 if err != nil {
+1 -1
internal/core/dep/dep_test.go
··· 45 45 } 46 46 47 47 test.Run(t, func(t *cuetxtar.Test) { 48 - val := t.Context().BuildInstance(t.Instance()) 48 + val := t.CueContext().BuildInstance(t.Instance()) 49 49 if val.Err() != nil { 50 50 t.Fatal(val.Err()) 51 51 }
+2 -2
internal/core/export/export_test.go
··· 78 78 // different from parsed or evaluated CUE, such as having Vertex values. 79 79 func TestGenerated(t *testing.T) { 80 80 cuetdtest.FullMatrix.Do(t, func(t *cuetdtest.M) { 81 - ctx := t.Context() 81 + ctx := t.CueContext() 82 82 83 83 testCases := []struct { 84 84 in func(ctx *adt.OpContext) (adt.Expr, error) ··· 349 349 // Issue #1204 350 350 for _, tc := range testCases { 351 351 cuetdtest.FullMatrix.Run(t, "", func(t *cuetdtest.M) { 352 - ctx := t.Context() 352 + ctx := t.CueContext() 353 353 354 354 v := ctx.BuildExpr(tc.expr) 355 355
+1 -1
internal/core/export/self_test.go
··· 49 49 } 50 50 51 51 test.Run(t, func(t *cuetxtar.Test) { 52 - r := t.Context() 52 + r := t.CueContext() 53 53 54 54 a := t.Instances() 55 55
+6 -2
internal/cuetdtest/matrix.go
··· 35 35 version internal.EvaluatorVersion 36 36 } 37 37 38 + // Ensure that M always implements testing.TB. 39 + // Note that testing.TB may gain new methods in future Go releases. 40 + var _ testing.TB = (*M)(nil) 41 + 38 42 func (t *M) Name() string { return t.name } 39 43 func (t *M) Fallback() string { return t.fallback } 40 44 func (t *M) IsDefault() bool { return t.name == DefaultVersion } 41 45 42 - func (t *M) Context() *cue.Context { 46 + func (t *M) CueContext() *cue.Context { 43 47 ctx := cuecontext.New() 44 48 r := (*runtime.Runtime)(ctx) 45 49 r.SetVersion(t.version) ··· 49 53 50 54 // Runtime creates a runtime that is configured according to the matrix. 51 55 func (t *M) Runtime() *runtime.Runtime { 52 - return (*runtime.Runtime)(t.Context()) 56 + return (*runtime.Runtime)(t.CueContext()) 53 57 } 54 58 55 59 const DefaultVersion = "v2"
+8 -4
internal/cuetxtar/txtar.go
··· 127 127 hasGold bool 128 128 } 129 129 130 + // Ensure that Test always implements testing.TB. 131 + // Note that testing.TB may gain new methods in future Go releases. 132 + var _ testing.TB = (*Test)(nil) 133 + 130 134 // Write implements [io.Writer] by writing to the output for the test, 131 135 // which will be tested against the main golden file. 132 136 func (t *Test) Write(b []byte) (n int, err error) { ··· 345 349 346 350 // Runtime returns a new runtime based on the configuration of the test. 347 351 func (t *Test) Runtime() *runtime.Runtime { 348 - return (*runtime.Runtime)(t.Context()) 352 + return (*runtime.Runtime)(t.CueContext()) 349 353 } 350 354 351 - // Context returns a new cue.Context based on the configuration of the test. 352 - func (t *Test) Context() *cue.Context { 355 + // CueContext returns a new cue.CueContext based on the configuration of the test. 356 + func (t *Test) CueContext() *cue.Context { 353 357 if t.M != nil { 354 - return t.M.Context() 358 + return t.M.CueContext() 355 359 } 356 360 return cuecontext.New() 357 361 }
+1 -1
internal/diff/diff_test.go
··· 405 405 }} 406 406 for _, tc := range testCases { 407 407 cuetdtest.FullMatrix.Run(t, tc.name, func(t *cuetdtest.M) { 408 - ctx := t.Context() 408 + ctx := t.CueContext() 409 409 // it is not fatal if x or y contain errors: some test cases 410 410 // rely on interacting with such errors. 411 411 x := ctx.CompileString(tc.x, cue.Filename("x"))
+1 -1
tools/flow/flow_test.go
··· 48 48 } 49 49 50 50 test.Run(t, func(t *cuetxtar.Test) { 51 - v := t.Context().BuildInstance(t.Instance()) 51 + v := t.CueContext().BuildInstance(t.Instance()) 52 52 if err := v.Err(); err != nil { 53 53 t.Fatal(errors.Details(err, nil)) 54 54 }
+1 -1
tools/trim/trim_test.go
··· 43 43 test.Run(t, func(t *cuetxtar.Test) { 44 44 45 45 a := t.Instance() 46 - ctx := t.Context() 46 + ctx := t.CueContext() 47 47 val := ctx.BuildInstance(a) 48 48 // Note: don't require val.Err to be nil because there are deliberate 49 49 // errors in some tests, to ensure trim still works even with some errors.