this repo has no description
0
fork

Configure Feed

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

cue/cuecontext: expand TestEvalVersion to test more combinations

I recently realised that using cuecontext.EvaluatorVersion(EvalDefault)
to select the default version is not actually the same as not using
the option, which intuitively should also result in default behavior.

Yet to be determined how best to resolve this inconsistency,
hence the TODO. It is best to expand the test cases before we apply
a fix in any case, as then we can see precisely what the fix does.

Signed-off-by: Daniel Martí <mvdan@mvdan.cc>
Change-Id: Ieb016586bc55f7c20f602df6572e2dc26850b319
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1208335
Unity-Result: CUE porcuepine <cue.porcuepine@gmail.com>
Reviewed-by: Matthew Sackman <matthew@cue.works>
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>

+30 -9
+30 -9
cue/cuecontext/cuecontext_test.go
··· 18 18 "fmt" 19 19 "testing" 20 20 21 + "github.com/go-quicktest/qt" 22 + 21 23 "cuelang.org/go/cue" 22 24 "cuelang.org/go/cue/ast" 23 25 "cuelang.org/go/internal" ··· 83 85 defer func() { cueexperiment.Flags.EvalV3 = saved }() 84 86 85 87 test := func(c *cue.Context, want internal.EvaluatorVersion) { 88 + t.Helper() 86 89 opCtx := adt.NewContext((*runtime.Runtime)(c), nil) 87 - got := opCtx.Version 88 - if got != want { 89 - t.Errorf("got %v; want %v", got, want) 90 - } 90 + qt.Check(t, qt.Equals(opCtx.Version, want)) 91 + } 92 + 93 + // The experiment evaluator version setting does not affect the specific 94 + // versions like Stable or V3, as they are fixed. 95 + testFixedVersions := func() { 96 + // We currently don't have an experimental version, so it's the current version. 97 + test(New(EvaluatorVersion(EvalExperiment)), internal.EvalV3) 98 + test(New(EvaluatorVersion(EvalV2)), internal.EvalV2) 99 + test(New(EvaluatorVersion(EvalV3)), internal.EvalV3) 91 100 } 92 101 93 - cueexperiment.Flags.EvalV3 = true 102 + // The current and default evaluator version is EvalV3. 103 + qt.Assert(t, qt.Equals(cueexperiment.Flags.EvalV3, true)) 104 + test(New(), internal.EvalV3) 105 + // TODO(mvdan): explicitly selecting the default should result in evalv3 here, 106 + // just like implicitly selecting the default by not using the EvaluatorVersion flag. 107 + // It currently does not, because internally, we treat "unset" vs "default" 108 + // as different version selection scenarios. 109 + // 110 + // Or, if we want an evaluator version to describe "latest stable", opposing 111 + // EvalExperiment to describe "latest experimental", we should rename it to EvalStable 112 + // and keep its current behavior. 113 + test(New(EvaluatorVersion(EvalDefault)), internal.EvalV2) 94 114 95 - test(New(), internal.DevVersion) 96 - test(New(EvaluatorVersion(EvalV2)), internal.DefaultVersion) 97 - test(New(EvaluatorVersion(EvalV3)), internal.DevVersion) 115 + testFixedVersions() 98 116 117 + // Turning off the evalv3 experiment switches the default back to EvalV2. 99 118 cueexperiment.Flags.EvalV3 = false 119 + test(New(), internal.EvalV2) 120 + test(New(EvaluatorVersion(EvalDefault)), internal.EvalV2) 100 121 101 - test(New(), internal.DefaultVersion) 122 + testFixedVersions() 102 123 }