this repo has no description
0
fork

Configure Feed

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

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 <mpvl@gmail.com>
Change-Id: I170c070ce55a0ec79156fc3331f174caddde617b
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1167860
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>
Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
Unity-Result: CUE porcuepine <cue.porcuepine@gmail.com>

+41 -36
+41 -36
internal/core/adt/eval_test.go
··· 37 37 todo = flag.Bool("todo", false, "run tests marked with #todo-compile") 38 38 ) 39 39 40 + // TestEval tests the default implementation of the evaluator. 40 41 func TestEval(t *testing.T) { 41 42 test := cuetxtar.TxTarTest{ 42 43 Root: "../../../cue/testdata", ··· 49 50 test.ToDo = nil 50 51 } 51 52 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) 88 55 }) 89 56 } 90 57 ··· 94 61 95 62 var needFix = map[string]string{ 96 63 "DIR/NAME": "reason", 64 + } 65 + 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) 97 102 } 98 103 99 104 // TestX is for debugging. Do not delete.