From 97eeee401293345757de7f479bb1c6a4bfe629b2 Mon Sep 17 00:00:00 2001 From: Paul Jolly Date: Tue, 23 Jul 2024 16:22:54 +0100 Subject: [PATCH] cue: add a regression test for a default elimination bug fixed in evalv3 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The old evaluator does not correctly follow the rewrite rules for default values: https://cuelang.org/docs/reference/spec/#default-values It then makes a further mistake by output different values for JSON or Yaml. The new evaluator correctly determines that the field is incomplete because it is left with 3 | >=3. Add a regression test to lock in the behaviour of the new evaluator. Closes #2916. Signed-off-by: Paul Jolly Change-Id: I9a5151df9702dfa46271edf543978bce6b1ec3a1 Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1198299 TryBot-Result: CUEcueckoo Unity-Result: CUE porcuepine Reviewed-by: Daniel Martí --- .../testdata/script/export_issue2916.txtar | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 cmd/cue/cmd/testdata/script/export_issue2916.txtar diff --git a/cmd/cue/cmd/testdata/script/export_issue2916.txtar b/cmd/cue/cmd/testdata/script/export_issue2916.txtar new file mode 100644 index 00000000000..d5edb72cb69 --- /dev/null +++ b/cmd/cue/cmd/testdata/script/export_issue2916.txtar @@ -0,0 +1,44 @@ +# https://cuelang.org/issue/2916 +# +# The old evaluator does not correctly follow the rewrite rules for default +# values: +# +# https://cuelang.org/docs/reference/spec/#default-values +# +# It then makes a further mistake by output different values for JSON or Yaml. +# +# The new evaluator correctly determines that the field is incomplete because +# it is left with 3 | >=3. + +exec cue export file.cue --out json +cmp stdout stdout.json.golden +exec cue export file.cue --out yaml +cmp stdout stdout.yaml.golden + +# This issue is already fixed in the new evaluator. +env CUE_EXPERIMENT=evalv3 + +! exec cue export file.cue --out json +cmp stderr stderr.golden +! exec cue export file.cue --out yaml +cmp stderr stderr.golden +-- file.cue -- +a: { + b: _ + [_]: c: uint | *1 + [string]: c: >=3 | *3 +} +-- stderr.golden -- +a.b.c: incomplete value >=3 & int | 3 +-- stdout.json.golden -- +{ + "a": { + "b": { + "c": 3 + } + } +} +-- stdout.yaml.golden -- +a: + b: + c: 1