this repo has no description
0
fork

Configure Feed

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

evaluator: regression test for order independent eval fixed in evalv3

The old evaluator does not correctly handle declarations in a different
order, despite CUE being order independent.

The new evaluator correctly handles this situation.

Add a regression test to lock in the behaviour of the new evaluator.

Fixes #3376

Signed-off-by: Paul Jolly <paul@myitcv.io>
Change-Id: I1c020846663e265b6c244eabd1d678650e8f1fe2
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1199680
Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>
Unity-Result: CUE porcuepine <cue.porcuepine@gmail.com>

+114
+114
cmd/cue/cmd/testdata/script/eval_issue3376.txtar
··· 1 + # https://cuelang.org/issue/3376 2 + # 3 + # The old evaluator does not correctly handle the difference in order of 4 + # declarations. To the extent that scenario2 gives an error: 5 + # 6 + # items.a: cannot add to field _: 7 + # ./scenario2.cue:1:32 8 + # 9 + # and scenario4 results in a SIGSEV. 10 + # 11 + # The new evaluator correctly results in no errors in these cases. 12 + 13 + # evalv2 - scenario 1 14 + exec cue eval ./scenario1.cue 15 + 16 + # evalv2 - scenario 2 17 + # 18 + # This should not fail but it does. Fixed in evalv3 19 + ! exec cue eval ./scenario2.cue 20 + cmp stderr scenario2.evalv2.stderr 21 + 22 + # evalv2 - scenario 3 23 + exec cue eval ./scenario3.cue 24 + 25 + # evalv2 - scenario 4 26 + # 27 + # This should not fail but it does with a SIGSEV. Fixed in evalv3 28 + ! exec cue eval ./scenario4.cue 29 + stderr 'panic: runtime error: invalid memory address or nil pointer dereference' 30 + 31 + env CUE_EXPERIMENT=evalv3 32 + 33 + # evalv3 - scenario 1 34 + exec cue eval ./scenario1.cue 35 + 36 + # evalv3 - scenario 2 37 + exec cue eval ./scenario2.cue 38 + 39 + # evalv3 - scenario 3 40 + exec cue eval ./scenario3.cue 41 + 42 + # evalv3 - scenario 4 43 + exec cue eval ./scenario4.cue 44 + 45 + -- scenario1.cue -- 46 + #Item: { 47 + id!: string 48 + deps: [...or(known_ids)] | or(known_ids) 49 + } 50 + 51 + known_ids: [for k,v in items { v.id } ] 52 + 53 + items: [string]: #Item 54 + 55 + items: [Key=_]: { id: (Key) + "-id" } 56 + 57 + items: a: deps: items.b.id 58 + items: b: deps: [] 59 + items: c: deps: [items.a.id, items.b.id] 60 + 61 + -- scenario2.cue -- 62 + known_ids: [for k,v in items { v.id } ] 63 + 64 + #Item: { 65 + id!: string 66 + deps: [...or(known_ids)] | or(known_ids) 67 + } 68 + 69 + 70 + items: [string]: #Item 71 + 72 + items: [Key=_]: { id: (Key) + "-id" } 73 + 74 + items: a: deps: items.b.id 75 + items: b: deps: [] 76 + items: c: deps: [items.a.id, items.b.id] 77 + 78 + -- scenario3.cue -- 79 + #Item: { 80 + id!: string 81 + deps?: [...or(known_ids)] | or(known_ids) 82 + } 83 + 84 + known_ids: [for k,v in items { v.id } ] 85 + 86 + items: [string]: #Item 87 + 88 + items: [Key=_]: { id: (Key) + "-id" } 89 + 90 + items: a: deps: items.b.id 91 + items: b: deps: [] 92 + items: c: deps: [items.a.id, items.b.id] 93 + items: d: _ 94 + 95 + -- scenario4.cue -- 96 + known_ids: [for k,v in items { v.id } ] 97 + 98 + #Item: { 99 + id!: string 100 + deps?: [...or(known_ids)] | or(known_ids) 101 + } 102 + 103 + items: [string]: #Item 104 + 105 + items: [Key=_]: { id: (Key) + "-id" } 106 + 107 + items: a: deps: items.b.id 108 + items: b: deps: [] 109 + items: c: deps: [items.a.id, items.b.id] 110 + items: d: _ 111 + 112 + -- scenario2.evalv2.stderr -- 113 + items.a: cannot add to field _: 114 + ./scenario2.cue:1:32