Skip to content

Commit

Permalink
internal/cueexperiment: remove yamlv3experiment
Browse files Browse the repository at this point in the history
It was always on and deprecated in v0.11, slated for removal in v0.12.
Now that we're on our way to v0.12.0-alpha.1, remove it.

Simplify cueexperiment.TestInit once again, matching godebug.TestInit.
envflag is now its own package with enough tests covering edge cases
such as non-zero default values and deprecated flags,
so there is no need to test those again here.

Moreover, we add, change, and remove experiments every release,
so having to update the test code as well adds unnecessary churn.

If we want an end-to-end test to ensure that each of the CUE_EXPERIMENT
or CUE_DEBUG flags work as expected from cmd/cue and the Go API,
we should write those tests as proper integration tests anyway,
like we did for CUE_DEBUG=sortfields in https://cuelang.org/cl/1204654.

Signed-off-by: Daniel Martí <mvdan@mvdan.cc>
Change-Id: Ib064782c12f30ba29b92cac92ab5850a1a95b104
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1204666
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>
Unity-Result: CUE porcuepine <cue.porcuepine@gmail.com>
Reviewed-by: Roger Peppe <rogpeppe@gmail.com>
  • Loading branch information
mvdan committed Nov 28, 2024
1 parent 2b55328 commit 5e20434
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 35 deletions.
14 changes: 2 additions & 12 deletions internal/cueexperiment/exp.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,6 @@ import (
var Flags struct {
Modules bool `envflag:"deprecated,default:true"`

// YAMLV3Decoder swaps the old internal/third_party/yaml decoder with the new
// decoder implemented in internal/encoding/yaml on top of yaml.v3.
// We keep it around for v0.11 for the sake of not breaking users
// with CUE_EXPERIMENT=yamlv3decoder=1 who must still suppport older CUE versions,
// but currently the feature is always enabled.
// TODO(mvdan): remove for v0.12.
YAMLV3Decoder bool `envflag:"deprecated,default:true"`

// EvalV3 enables the new evaluator. The new evaluator addresses various
// performance concerns.
EvalV3 bool
Expand All @@ -46,8 +38,6 @@ func Init() error {
return initOnce()
}

var initOnce = sync.OnceValue(initAlways)

func initAlways() error {
var initOnce = sync.OnceValue(func() error {
return envflag.Init(&Flags, "CUE_EXPERIMENT")
}
})
27 changes: 4 additions & 23 deletions internal/cueexperiment/exp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,9 @@ import (

func TestInit(t *testing.T) {
// This is just a smoke test to make sure it's all wired up OK.

// Check the default values.
t.Setenv("CUE_EXPERIMENT", "")
err := initAlways()
qt.Assert(t, qt.IsNil(err))
qt.Assert(t, qt.IsTrue(Flags.Modules))
qt.Assert(t, qt.IsTrue(Flags.YAMLV3Decoder))

// Check that we can enable all experiments.
t.Setenv("CUE_EXPERIMENT", "modules,yamlv3decoder")
err = initAlways()
t.Setenv("CUE_EXPERIMENT", "evalv3,embed=0")
err := Init()
qt.Assert(t, qt.IsNil(err))
qt.Assert(t, qt.IsTrue(Flags.Modules))
qt.Assert(t, qt.IsTrue(Flags.YAMLV3Decoder))

// Check that we cannot disable the YAML v3 experiment.
t.Setenv("CUE_EXPERIMENT", "yamlv3decoder=0")
err = initAlways()
qt.Assert(t, qt.ErrorMatches(err, `cannot parse CUE_EXPERIMENT: cannot change default value of deprecated flag "yamlv3decoder"`))

// Check that we cannot disable the modules experiment.
t.Setenv("CUE_EXPERIMENT", "modules=0")
err = initAlways()
qt.Assert(t, qt.ErrorMatches(err, `cannot parse CUE_EXPERIMENT: cannot change default value of deprecated flag "modules"`))
qt.Assert(t, qt.IsTrue(Flags.EvalV3))
qt.Assert(t, qt.IsFalse(Flags.Embed))
}

0 comments on commit 5e20434

Please sign in to comment.