Skip to content

Commit

Permalink
internal/core/adt: hoist the test body of TestEval
Browse files Browse the repository at this point in the history
The body will be used for testing both the old and new
evaluator in a separate test. This prepares for that and keeps
the diff down the line.
runEvalTest is not passed as an argument to Run directly, as
it will soon have a different signature.

Signed-off-by: Marcel van Lohuizen <[email protected]>
Change-Id: I170c070ce55a0ec79156fc3331f174caddde617b
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1167860
TryBot-Result: CUEcueckoo <[email protected]>
Reviewed-by: Daniel Martí <[email protected]>
Unity-Result: CUE porcuepine <[email protected]>
  • Loading branch information
mpvl committed Aug 25, 2023
1 parent 5062118 commit ca254d6
Showing 1 changed file with 41 additions and 36 deletions.
77 changes: 41 additions & 36 deletions internal/core/adt/eval_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ var (
todo = flag.Bool("todo", false, "run tests marked with #todo-compile")
)

// TestEval tests the default implementation of the evaluator.
func TestEval(t *testing.T) {
test := cuetxtar.TxTarTest{
Root: "../../../cue/testdata",
Expand All @@ -49,42 +50,8 @@ func TestEval(t *testing.T) {
test.ToDo = nil
}

test.Run(t, func(t *cuetxtar.Test) {
a := t.Instance()
r := runtime.New()

v, err := r.Build(nil, a)
if err != nil {
t.WriteErrors(err)
return
}

e := eval.New(r)
ctx := e.NewContext(v)
v.Finalize(ctx)

stats := ctx.Stats()
w := t.Writer("stats")
fmt.Fprintln(w, stats)
// if n := stats.Leaks(); n > 0 {
// t.Skipf("%d leaks reported", n)
// }

if b := validate.Validate(ctx, v, &validate.Config{
AllErrors: true,
}); b != nil {
fmt.Fprintln(t, "Errors:")
t.WriteErrors(b.Err)
fmt.Fprintln(t, "")
fmt.Fprintln(t, "Result:")
}

if v == nil {
return
}

debug.WriteNode(t, r, v, &debug.Config{Cwd: t.Dir})
fmt.Fprintln(t)
test.Run(t, func(tc *cuetxtar.Test) {
runEvalTest(tc)
})
}

Expand All @@ -96,6 +63,44 @@ var needFix = map[string]string{
"DIR/NAME": "reason",
}

func runEvalTest(t *cuetxtar.Test) {
a := t.Instance()
r := runtime.New()

v, err := r.Build(nil, a)
if err != nil {
t.WriteErrors(err)
return
}

e := eval.New(r)
ctx := e.NewContext(v)
v.Finalize(ctx)

stats := ctx.Stats()
w := t.Writer("stats")
fmt.Fprintln(w, stats)
// if n := stats.Leaks(); n > 0 {
// t.Skipf("%d leaks reported", n)
// }

if b := validate.Validate(ctx, v, &validate.Config{
AllErrors: true,
}); b != nil {
fmt.Fprintln(t, "Errors:")
t.WriteErrors(b.Err)
fmt.Fprintln(t, "")
fmt.Fprintln(t, "Result:")
}

if v == nil {
return
}

debug.WriteNode(t, r, v, &debug.Config{Cwd: t.Dir})
fmt.Fprintln(t)
}

// TestX is for debugging. Do not delete.
func TestX(t *testing.T) {
verbosity := 0
Expand Down

0 comments on commit ca254d6

Please sign in to comment.