Skip to content

Commit d502843

Browse files
committed
cmd/cue,internal/buildattr: add tests for @ignore tags
This CL adds some tests for the up-coming `@ignore` functionality so that we can see the difference when it is implemented. Note that the syntax is just the general CUE attribute syntax so it's valid, just ignored by the loader as yet. For #2962. Signed-off-by: Roger Peppe <[email protected]> Change-Id: I54e4b098bd425d80d4dfa18b1086a0181cc2dee7 Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1198248 Reviewed-by: Daniel Martí <[email protected]> TryBot-Result: CUEcueckoo <[email protected]> Unity-Result: CUE porcuepine <[email protected]>
1 parent 00879f0 commit d502843

File tree

2 files changed

+137
-0
lines changed

2 files changed

+137
-0
lines changed

cmd/cue/cmd/testdata/script/modtidy_with_build_attrs.txtar

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,32 @@ deps: {
4141
v: "v0.0.1"
4242
default: true
4343
}
44+
"test.example/d7@v0": {
45+
v: "v0.0.1"
46+
default: true
47+
}
48+
"test.example/d8@v0": {
49+
v: "v0.0.1"
50+
default: true
51+
}
4452
}
4553
-- want-stdout-1 --
4654
prod: false
55+
ignore: {
56+
self: "test.example/d7"
57+
}
4758
x: {
4859
self: "test.example/d2"
4960
}
5061
-- want-stdout-2 --
5162
prod: true
63+
ignore: {
64+
self: "test.example/d7"
65+
}
5266
x: {
67+
ignore: {
68+
self: "test.example/d8"
69+
}
5370
self: "test.example/d1"
5471
prodenabled: false
5572
y: {
@@ -79,6 +96,15 @@ import "test.example/d2"
7996

8097
prod: false
8198
x: d2
99+
-- ignorable.cue --
100+
@ignore()
101+
102+
package foo
103+
104+
import "test.example/d7"
105+
106+
ignore: d7
107+
82108
-- _registry/test.example_d1_v0.0.1/cue.mod/module.cue --
83109
module: "test.example/d1"
84110
language: version: "v0.9.2"
@@ -123,6 +149,17 @@ import "test.example/d6"
123149

124150
y: d6
125151

152+
-- _registry/test.example_d1_v0.0.1/ignorable.cue --
153+
154+
@ignore()
155+
156+
package d1
157+
158+
import "test.example/d8"
159+
160+
ignore: d8
161+
162+
126163
-- _registry/test.example_d2_v0.0.1/cue.mod/module.cue --
127164
module: "test.example/d2"
128165
language: version: "v0.9.2"
@@ -158,3 +195,17 @@ language: version: "v0.9.2"
158195
-- _registry/test.example_d6_v0.0.1/x.cue --
159196
package d6
160197
self: "test.example/d6"
198+
199+
-- _registry/test.example_d7_v0.0.1/cue.mod/module.cue --
200+
module: "test.example/d7"
201+
language: version: "v0.9.2"
202+
-- _registry/test.example_d7_v0.0.1/x.cue --
203+
package d7
204+
self: "test.example/d7"
205+
206+
-- _registry/test.example_d8_v0.0.1/cue.mod/module.cue --
207+
module: "test.example/d8"
208+
language: version: "v0.9.2"
209+
-- _registry/test.example_d8_v0.0.1/x.cue --
210+
package d8
211+
self: "test.example/d8"

internal/buildattr/buildattr_test.go

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,21 @@ var shouldBuildFileTests = []struct {
2727
syntax: `
2828
@if(foo)
2929
30+
package something
31+
`,
32+
wantOK: false,
33+
wantTagCalls: map[string]bool{"foo": true},
34+
wantAttr: "@if(foo)",
35+
}, {
36+
testName: "PackageWithComments",
37+
syntax: `
38+
39+
// Some comment
40+
41+
@if(foo)
42+
43+
// Other comment
44+
3045
package something
3146
`,
3247
wantOK: false,
@@ -243,6 +258,77 @@ package something
243258
"baz": true,
244259
},
245260
wantAttr: "@if(foo || (!bar && baz))",
261+
}, {
262+
testName: "IgnoreOnly",
263+
syntax: `
264+
@ignore()
265+
266+
package something
267+
`,
268+
wantOK: true,
269+
}, {
270+
testName: "IgnoreWithBuildAttrs",
271+
syntax: `
272+
@ignore()
273+
@if(blah)
274+
275+
package something
276+
`,
277+
wantOK: false,
278+
wantTagCalls: map[string]bool{
279+
"blah": true,
280+
},
281+
wantAttr: "@if(blah)",
282+
}, {
283+
testName: "IgnoreWithMultipleEarlierIfs",
284+
syntax: `
285+
@if(foo)
286+
@if(bar)
287+
@ignore()
288+
289+
package something
290+
`,
291+
wantOK: false,
292+
wantError: `previous declaration here:
293+
testfile.cue:2:1
294+
multiple @if attributes:
295+
testfile.cue:3:1
296+
`,
297+
wantAttr: "@if(foo)",
298+
}, {
299+
testName: "IgnoreWithMultipleLaterIfs",
300+
syntax: `
301+
@ignore()
302+
@if(foo)
303+
@if(bar)
304+
305+
package something
306+
`,
307+
wantOK: false,
308+
wantError: `previous declaration here:
309+
testfile.cue:3:1
310+
multiple @if attributes:
311+
testfile.cue:4:1
312+
`,
313+
wantAttr: "@if(foo)",
314+
}, {
315+
testName: "IgnoreWithoutPackageClause",
316+
syntax: `
317+
@ignore()
318+
a: 5
319+
`,
320+
wantOK: true,
321+
}, {
322+
testName: "IfAfterDeclaration",
323+
syntax: `
324+
a: 1
325+
@if(foo)
326+
`,
327+
wantOK: false,
328+
wantTagCalls: map[string]bool{
329+
"foo": true,
330+
},
331+
wantAttr: "@if(foo)",
246332
}}
247333

248334
func TestShouldBuildFile(t *testing.T) {

0 commit comments

Comments
 (0)