diff --git a/cmd/cue/cmd/testdata/script/modtidy_with_build_attrs.txtar b/cmd/cue/cmd/testdata/script/modtidy_with_build_attrs.txtar index f4230e3cab7..a6590229e18 100644 --- a/cmd/cue/cmd/testdata/script/modtidy_with_build_attrs.txtar +++ b/cmd/cue/cmd/testdata/script/modtidy_with_build_attrs.txtar @@ -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: { @@ -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" @@ -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" @@ -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" diff --git a/internal/buildattr/buildattr_test.go b/internal/buildattr/buildattr_test.go index f234e75457d..d21150a0645 100644 --- a/internal/buildattr/buildattr_test.go +++ b/internal/buildattr/buildattr_test.go @@ -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, @@ -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) {