Skip to content

Commit

Permalink
tools/trim: prepare for using test matrix
Browse files Browse the repository at this point in the history
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 <[email protected]>
Change-Id: Id0edc3346074ec31ee045de862b58f41232752b9
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1194197
Unity-Result: CUE porcuepine <[email protected]>
TryBot-Result: CUEcueckoo <[email protected]>
Reviewed-by: Daniel Martí <[email protected]>
  • Loading branch information
mpvl committed May 3, 2024
1 parent a983b19 commit 926f060
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
2 changes: 2 additions & 0 deletions internal/cuetdtest/matrix.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
23 changes: 18 additions & 5 deletions tools/trim/trim_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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)
}
Expand All @@ -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.

Expand Down

0 comments on commit 926f060

Please sign in to comment.