Skip to content

Commit ca254d6

Browse files
committed
internal/core/adt: hoist the test body of TestEval
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]>
1 parent 5062118 commit ca254d6

File tree

1 file changed

+41
-36
lines changed

1 file changed

+41
-36
lines changed

internal/core/adt/eval_test.go

+41-36
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ var (
3737
todo = flag.Bool("todo", false, "run tests marked with #todo-compile")
3838
)
3939

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

52-
test.Run(t, func(t *cuetxtar.Test) {
53-
a := t.Instance()
54-
r := runtime.New()
55-
56-
v, err := r.Build(nil, a)
57-
if err != nil {
58-
t.WriteErrors(err)
59-
return
60-
}
61-
62-
e := eval.New(r)
63-
ctx := e.NewContext(v)
64-
v.Finalize(ctx)
65-
66-
stats := ctx.Stats()
67-
w := t.Writer("stats")
68-
fmt.Fprintln(w, stats)
69-
// if n := stats.Leaks(); n > 0 {
70-
// t.Skipf("%d leaks reported", n)
71-
// }
72-
73-
if b := validate.Validate(ctx, v, &validate.Config{
74-
AllErrors: true,
75-
}); b != nil {
76-
fmt.Fprintln(t, "Errors:")
77-
t.WriteErrors(b.Err)
78-
fmt.Fprintln(t, "")
79-
fmt.Fprintln(t, "Result:")
80-
}
81-
82-
if v == nil {
83-
return
84-
}
85-
86-
debug.WriteNode(t, r, v, &debug.Config{Cwd: t.Dir})
87-
fmt.Fprintln(t)
53+
test.Run(t, func(tc *cuetxtar.Test) {
54+
runEvalTest(tc)
8855
})
8956
}
9057

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

66+
func runEvalTest(t *cuetxtar.Test) {
67+
a := t.Instance()
68+
r := runtime.New()
69+
70+
v, err := r.Build(nil, a)
71+
if err != nil {
72+
t.WriteErrors(err)
73+
return
74+
}
75+
76+
e := eval.New(r)
77+
ctx := e.NewContext(v)
78+
v.Finalize(ctx)
79+
80+
stats := ctx.Stats()
81+
w := t.Writer("stats")
82+
fmt.Fprintln(w, stats)
83+
// if n := stats.Leaks(); n > 0 {
84+
// t.Skipf("%d leaks reported", n)
85+
// }
86+
87+
if b := validate.Validate(ctx, v, &validate.Config{
88+
AllErrors: true,
89+
}); b != nil {
90+
fmt.Fprintln(t, "Errors:")
91+
t.WriteErrors(b.Err)
92+
fmt.Fprintln(t, "")
93+
fmt.Fprintln(t, "Result:")
94+
}
95+
96+
if v == nil {
97+
return
98+
}
99+
100+
debug.WriteNode(t, r, v, &debug.Config{Cwd: t.Dir})
101+
fmt.Fprintln(t)
102+
}
103+
99104
// TestX is for debugging. Do not delete.
100105
func TestX(t *testing.T) {
101106
verbosity := 0

0 commit comments

Comments
 (0)