Skip to content

Commit

Permalink
cmd/cue,internal/buildattr: add tests for @ignore tags
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
rogpeppe committed Jul 23, 2024
1 parent 00879f0 commit d502843
Show file tree
Hide file tree
Showing 2 changed files with 137 additions and 0 deletions.
51 changes: 51 additions & 0 deletions cmd/cue/cmd/testdata/script/modtidy_with_build_attrs.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,32 @@ deps: {
v: "v0.0.1"
default: true
}
"test.example/d7@v0": {
v: "v0.0.1"
default: true
}
"test.example/d8@v0": {
v: "v0.0.1"
default: true
}
}
-- want-stdout-1 --
prod: false
ignore: {
self: "test.example/d7"
}
x: {
self: "test.example/d2"
}
-- want-stdout-2 --
prod: true
ignore: {
self: "test.example/d7"
}
x: {
ignore: {
self: "test.example/d8"
}
self: "test.example/d1"
prodenabled: false
y: {
Expand Down Expand Up @@ -79,6 +96,15 @@ import "test.example/d2"

prod: false
x: d2
-- ignorable.cue --
@ignore()

package foo

import "test.example/d7"

ignore: d7

-- _registry/test.example_d1_v0.0.1/cue.mod/module.cue --
module: "test.example/d1"
language: version: "v0.9.2"
Expand Down Expand Up @@ -123,6 +149,17 @@ import "test.example/d6"

y: d6

-- _registry/test.example_d1_v0.0.1/ignorable.cue --

@ignore()

package d1

import "test.example/d8"

ignore: d8


-- _registry/test.example_d2_v0.0.1/cue.mod/module.cue --
module: "test.example/d2"
language: version: "v0.9.2"
Expand Down Expand Up @@ -158,3 +195,17 @@ language: version: "v0.9.2"
-- _registry/test.example_d6_v0.0.1/x.cue --
package d6
self: "test.example/d6"

-- _registry/test.example_d7_v0.0.1/cue.mod/module.cue --
module: "test.example/d7"
language: version: "v0.9.2"
-- _registry/test.example_d7_v0.0.1/x.cue --
package d7
self: "test.example/d7"

-- _registry/test.example_d8_v0.0.1/cue.mod/module.cue --
module: "test.example/d8"
language: version: "v0.9.2"
-- _registry/test.example_d8_v0.0.1/x.cue --
package d8
self: "test.example/d8"
86 changes: 86 additions & 0 deletions internal/buildattr/buildattr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,21 @@ var shouldBuildFileTests = []struct {
syntax: `
@if(foo)
package something
`,
wantOK: false,
wantTagCalls: map[string]bool{"foo": true},
wantAttr: "@if(foo)",
}, {
testName: "PackageWithComments",
syntax: `
// Some comment
@if(foo)
// Other comment
package something
`,
wantOK: false,
Expand Down Expand Up @@ -243,6 +258,77 @@ package something
"baz": true,
},
wantAttr: "@if(foo || (!bar && baz))",
}, {
testName: "IgnoreOnly",
syntax: `
@ignore()
package something
`,
wantOK: true,
}, {
testName: "IgnoreWithBuildAttrs",
syntax: `
@ignore()
@if(blah)
package something
`,
wantOK: false,
wantTagCalls: map[string]bool{
"blah": true,
},
wantAttr: "@if(blah)",
}, {
testName: "IgnoreWithMultipleEarlierIfs",
syntax: `
@if(foo)
@if(bar)
@ignore()
package something
`,
wantOK: false,
wantError: `previous declaration here:
testfile.cue:2:1
multiple @if attributes:
testfile.cue:3:1
`,
wantAttr: "@if(foo)",
}, {
testName: "IgnoreWithMultipleLaterIfs",
syntax: `
@ignore()
@if(foo)
@if(bar)
package something
`,
wantOK: false,
wantError: `previous declaration here:
testfile.cue:3:1
multiple @if attributes:
testfile.cue:4:1
`,
wantAttr: "@if(foo)",
}, {
testName: "IgnoreWithoutPackageClause",
syntax: `
@ignore()
a: 5
`,
wantOK: true,
}, {
testName: "IfAfterDeclaration",
syntax: `
a: 1
@if(foo)
`,
wantOK: false,
wantTagCalls: map[string]bool{
"foo": true,
},
wantAttr: "@if(foo)",
}}

func TestShouldBuildFile(t *testing.T) {
Expand Down

0 comments on commit d502843

Please sign in to comment.