From 926f060df9841a5743e3a75129599ee805ffdf84 Mon Sep 17 00:00:00 2001 From: Marcel van Lohuizen Date: Thu, 2 May 2024 16:46:42 +0200 Subject: [PATCH] tools/trim: prepare for using test matrix MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Many tests fail at the moment, but at least prepare the tests to use the test matrix. Issue #3060 Signed-off-by: Marcel van Lohuizen Change-Id: Id0edc3346074ec31ee045de862b58f41232752b9 Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1194197 Unity-Result: CUE porcuepine TryBot-Result: CUEcueckoo Reviewed-by: Daniel Martí --- internal/cuetdtest/matrix.go | 2 ++ tools/trim/trim_test.go | 23 ++++++++++++++++++----- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/internal/cuetdtest/matrix.go b/internal/cuetdtest/matrix.go index aac86896619..ac30394384a 100644 --- a/internal/cuetdtest/matrix.go +++ b/internal/cuetdtest/matrix.go @@ -66,6 +66,8 @@ var FullMatrix Matrix = []M{{ var SmallMatrix Matrix = FullMatrix[:2] +var DefaultOnlyMatrix Matrix = FullMatrix[:1] + // Run runs a test with the given name f for each configuration in the matrix. func (m Matrix) Run(t *testing.T, name string, f func(t *M)) { t.Run(name, func(t *testing.T) { diff --git a/tools/trim/trim_test.go b/tools/trim/trim_test.go index 457c1dcce3e..ddb8df4fdc6 100644 --- a/tools/trim/trim_test.go +++ b/tools/trim/trim_test.go @@ -25,9 +25,18 @@ import ( "cuelang.org/go/cue/errors" "cuelang.org/go/cue/format" "cuelang.org/go/cue/parser" + "cuelang.org/go/internal/core/runtime" + "cuelang.org/go/internal/cuetdtest" "cuelang.org/go/internal/cuetxtar" ) +var ( + // TODO(evalv3): many broken tests in new evaluator, use FullMatrix to + // expose. This is probably due to the changed underlying representation. + // matrix = cuetdtest.FullMatrix + matrix = cuetdtest.DefaultOnlyMatrix +) + func TestFiles(t *testing.T) { testCases := []struct { name string @@ -250,12 +259,13 @@ foo: entry: { `, }} for _, tc := range testCases { - t.Run(tc.name, func(t *testing.T) { + matrix.Run(t, tc.name, func(t *cuetdtest.M) { f, err := parser.ParseFile("test", tc.in) if err != nil { t.Fatal(err) } r := cuecontext.New() + t.UpdateRuntime((*runtime.Runtime)(r)) v := r.BuildFile(f) if err := v.Err(); err != nil { t.Fatal(err) @@ -265,7 +275,7 @@ foo: entry: { t.Fatal(err) } - out := formatNode(t, f) + out := formatNode(t.T, f) if got := string(out); got != tc.out { t.Errorf("\ngot:\n%s\nwant:\n%s", got, tc.out) } @@ -277,14 +287,17 @@ const trace = false func TestData(t *testing.T) { test := cuetxtar.TxTarTest{ - Root: "./testdata", - Name: "trim", + Root: "./testdata", + Name: "trim", + Matrix: matrix, } test.Run(t, func(t *cuetxtar.Test) { a := t.Instance() - val := cuecontext.New().BuildInstance(a) + ctx := cuecontext.New() + t.UpdateRuntime((*runtime.Runtime)(ctx)) + val := ctx.BuildInstance(a) // Note: don't check val.Err because there are deliberate // errors in some tests.