Skip to content

Commit

Permalink
cue: add a regression test for a default elimination bug fixed in evalv3
Browse files Browse the repository at this point in the history
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 <paul@myitcv.io>
Change-Id: I9a5151df9702dfa46271edf543978bce6b1ec3a1
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1198299
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>
Unity-Result: CUE porcuepine <cue.porcuepine@gmail.com>
Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
  • Loading branch information
myitcv committed Jul 23, 2024
1 parent 9025f67 commit 97eeee4
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions cmd/cue/cmd/testdata/script/export_issue2916.txtar
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 97eeee4

Please sign in to comment.