From d502843aae9b139591fe393580fb3a7e48a624db Mon Sep 17 00:00:00 2001 From: Roger Peppe Date: Tue, 23 Jul 2024 09:45:15 +0100 Subject: [PATCH] cmd/cue,internal/buildattr: add tests for `@ignore` tags MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Change-Id: I54e4b098bd425d80d4dfa18b1086a0181cc2dee7 Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1198248 Reviewed-by: Daniel Martí TryBot-Result: CUEcueckoo Unity-Result: CUE porcuepine --- .../script/modtidy_with_build_attrs.txtar | 51 +++++++++++ internal/buildattr/buildattr_test.go | 86 +++++++++++++++++++ 2 files changed, 137 insertions(+) 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) {