this repo has no description
0
fork

Configure Feed

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

internal/core/adt: use cuetdtest for TestValidate

This helps with upcoming error position
improvements.

Signed-off-by: Marcel van Lohuizen <mpvl@gmail.com>
Change-Id: I638caadea16d115376d345f31360deaff1c8038c
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1220036
Unity-Result: CUE porcuepine <cue.porcuepine@gmail.com>
Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>

+64 -22
+64 -22
internal/core/adt/validate_test.go
··· 25 25 "cuelang.org/go/internal/core/compile" 26 26 "cuelang.org/go/internal/core/eval" 27 27 "cuelang.org/go/internal/cuetdtest" 28 + "cuelang.org/go/internal/cuetest" 28 29 "github.com/google/go-cmp/cmp" 29 30 ) 30 31 ··· 45 46 #foo: { use: string } 46 47 `, 47 48 lookup: "#foo", 48 - out: "incomplete\n#foo.use: incomplete value string:\n test:2:16", 49 + out: `incomplete 50 + #foo.use: incomplete value string: 51 + test:2:16`, 49 52 }, { 50 53 name: "definitions not considered for completeness", 51 54 cfg: &adt.ValidateConfig{Concrete: true}, ··· 68 71 in: ` 69 72 1 & 2 70 73 `, 71 - out: "eval\nconflicting values 2 and 1:\n test:2:3\n test:2:7", 74 + out: `eval 75 + conflicting values 2 and 1: 76 + test:2:3 77 + test:2:7`, 72 78 }, { 73 79 name: "evaluation error in field", 74 80 in: ` 75 81 x: 1 & 2 76 82 `, 77 - out: "eval\nx: conflicting values 2 and 1:\n test:2:6\n test:2:10", 83 + out: `eval 84 + x: conflicting values 2 and 1: 85 + test:2:6 86 + test:2:10`, 78 87 }, { 79 88 name: "first error", 80 89 in: ` 81 90 x: 1 & 2 82 91 y: 2 & 4 83 92 `, 84 - out: "eval\nx: conflicting values 2 and 1:\n test:2:6\n test:2:10", 93 + out: `eval 94 + x: conflicting values 2 and 1: 95 + test:2:6 96 + test:2:10`, 85 97 }, { 86 98 name: "all errors", 87 99 cfg: &adt.ValidateConfig{AllErrors: true}, ··· 90 102 y: 2 & 4 91 103 `, 92 104 out: `eval 93 - x: conflicting values 2 and 1: 94 - test:2:6 95 - test:2:10 96 - y: conflicting values 4 and 2: 97 - test:3:6 98 - test:3:10`, 105 + x: conflicting values 2 and 1: 106 + test:2:6 107 + test:2:10 108 + y: conflicting values 4 and 2: 109 + test:3:6 110 + test:3:10`, 99 111 }, { 100 112 name: "incomplete", 101 113 cfg: &adt.ValidateConfig{Concrete: true}, ··· 103 115 y: 2 + x 104 116 x: string 105 117 `, 106 - out: "incomplete\ny: non-concrete value string in operand to +:\n test:2:6\n test:3:6", 118 + out: `incomplete 119 + y: non-concrete value string in operand to +: 120 + test:2:6 121 + test:3:6`, 107 122 }, { 108 123 name: "allowed incomplete cycle", 109 124 in: ` ··· 125 140 y: x + 1 126 141 x: y - 1 127 142 `, 128 - out: "cycle\ny: cycle with field: x:\n test:2:6\nx: cycle with field: y:\n test:3:6", 143 + out: `cycle 144 + y: cycle with field: x: 145 + test:2:6 146 + x: cycle with field: y: 147 + test:3:6`, 129 148 }, { 130 149 // TODO: different error position 131 150 name: "disallow cycle", ··· 134 153 a: b - 100 135 154 b: a + 100 136 155 c: [c[1], c[0]] `, 137 - out: "cycle\na: cycle with field: b:\n test:2:6\nb: cycle with field: a:\n test:3:6", 156 + out: `cycle 157 + a: cycle with field: b: 158 + test:2:6 159 + b: cycle with field: a: 160 + test:3:6`, 138 161 }, { 139 162 name: "treat cycles as incomplete when not disallowing", 140 163 cfg: &adt.ValidateConfig{}, ··· 151 174 y: string 152 175 x: 1 & 2 153 176 `, 154 - out: "eval\nx: conflicting values 2 and 1:\n test:3:6\n test:3:10", 177 + out: `eval 178 + x: conflicting values 2 and 1: 179 + test:3:6 180 + test:3:10`, 155 181 }, { 156 182 name: "consider defaults for concreteness", 157 183 cfg: &adt.ValidateConfig{Concrete: true}, ··· 176 202 a: int 177 203 } 178 204 `, 179 - out: "incomplete\nx.a: incomplete value int:\n test:3:7", 205 + out: `incomplete 206 + x.a: incomplete value int: 207 + test:3:7`, 180 208 }, { 181 209 name: "pick up non-concrete value in default", 182 210 cfg: &adt.ValidateConfig{Concrete: true}, ··· 185 213 a: 1 | 2 186 214 } 187 215 `, 188 - out: "incomplete\nx.a: incomplete value 1 | 2", 216 + out: `incomplete 217 + x.a: incomplete value 1 | 2`, 189 218 }, { 190 219 name: "required field not present", 191 220 cfg: &adt.ValidateConfig{Final: true}, ··· 196 225 height: 1.80 197 226 } 198 227 `, 199 - out: "incomplete\nPerson.name: field is required but not present:\n test:3:5", 228 + out: `incomplete 229 + Person.name: field is required but not present: 230 + test:3:5`, 200 231 }, { 201 232 name: "allow required fields in definitions", 202 233 cfg: &adt.ValidateConfig{Concrete: true}, ··· 231 262 x: {bar: 2} 232 263 x: string | {foo!: string} 233 264 `, 234 - out: "incomplete\nx.foo: field is required but not present:\n test:3:18", 265 + out: `incomplete 266 + x.foo: field is required but not present: 267 + test:3:18`, 235 268 }, { 236 269 name: "disallow incomplete error with final", 237 270 cfg: &adt.ValidateConfig{Final: true}, ··· 239 272 x: y + 1 240 273 y: int 241 274 `, 242 - out: "incomplete\nx: non-concrete value int in operand to +:\n test:2:7\n test:3:7", 275 + out: `incomplete 276 + x: non-concrete value int in operand to +: 277 + test:2:7 278 + test:3:7`, 243 279 }, { 244 280 name: "allow incomplete error with final while in definition", 245 281 cfg: &adt.ValidateConfig{Final: true}, ··· 265 301 b: #Def 266 302 `, 267 303 // TODO: \n test:3:7", only works without structure sharing. 268 - out: "incomplete\nb.a.x: field is required but not present:\n test:2:13", 304 + out: `incomplete 305 + b.a.x: field is required but not present: 306 + test:2:13`, 269 307 skipNoShare: true, 270 308 }, { 271 309 // Issue #3864: issue resulting from structure sharing. ··· 285 323 x: y: "dev" 286 324 } 287 325 `, 288 - out: "incomplete\nconfig.v.x.y: incomplete value string:\n test:2:11", 289 - }} 326 + out: `incomplete 327 + config.v.x.y: incomplete value string: 328 + test:2:11`}} 290 329 291 330 cuetdtest.Run(t, testCases, func(t *cuetdtest.T, tc *testCase) { 331 + t.Update(cuetest.UpdateGoldenFiles) 292 332 if tc.skipNoShare { 293 333 t.M.TODO_NoSharing(t) 294 334 } ··· 318 358 } 319 359 320 360 got := strings.TrimSpace(w.String()) 361 + got = strings.ReplaceAll(got, "\n", "\n\t\t\t\t") 362 + t.Equal(got, tc.out) 321 363 if tc.out != got { 322 364 t.Error(cmp.Diff(tc.out, got)) 323 365 }