From 954a765c077b077f833653836a5f89e0467f57f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Mart=C3=AD?= Date: Thu, 14 Mar 2024 15:02:57 +0000 Subject: [PATCH] cmd/cue: repurpose modinit test for language.version MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Since we added fallbackVersion in https://cuelang.org/cl/1177860, the norm is for `cue mod init` to add a language.version field, and it should only be skipped in the rare case where a version exists but it is somehow invalid, such as being inserted via ldflags. All other modinit tests already check that we insert a version by using $CUE_VERSION_OVERRIDE like this test used to. Make this test useful by testing the now-rare edge case of no version. Also make setting CUE_EXPERIMENT=modules explicit rather than via the _registry directory, which is less obvious and more verbose. Signed-off-by: Daniel Martí Change-Id: Ieb92e397b472323bf0d00df17fa3093cf259450c Dispatch-Trailer: {"type":"trybot","CL":1182873,"patchset":1,"ref":"refs/changes/73/1182873/1","targetBranch":"master"} --- .../testdata/script/modinit_with_version.txtar | 18 ------------------ .../script/modinit_without_version.txtar | 14 ++++++++++++++ 2 files changed, 14 insertions(+), 18 deletions(-) delete mode 100644 cmd/cue/cmd/testdata/script/modinit_with_version.txtar create mode 100644 cmd/cue/cmd/testdata/script/modinit_without_version.txtar diff --git a/cmd/cue/cmd/testdata/script/modinit_with_version.txtar b/cmd/cue/cmd/testdata/script/modinit_with_version.txtar deleted file mode 100644 index 44f036dbc..000000000 --- a/cmd/cue/cmd/testdata/script/modinit_with_version.txtar +++ /dev/null @@ -1,18 +0,0 @@ -# Check that cue mod init adds the language version. -env CUE_VERSION_OVERRIDE=v0.1.2 -exec cue mod init foo.example -cmp cue.mod/module.cue want-module - -# cue mod tidy should be a no-op after cue mod init -exec cue mod tidy -cmp cue.mod/module.cue want-module - --- want-module -- -module: "foo.example@v0" -language: { - version: "v0.1.2" -} --- _registry/example.com_e_v0.0.1/cue.mod/module.cue -- -module: "example.com/e@v0" --- _registry/example.com_e_v0.0.1/main.cue -- -package e diff --git a/cmd/cue/cmd/testdata/script/modinit_without_version.txtar b/cmd/cue/cmd/testdata/script/modinit_without_version.txtar new file mode 100644 index 000000000..228f15736 --- /dev/null +++ b/cmd/cue/cmd/testdata/script/modinit_without_version.txtar @@ -0,0 +1,14 @@ +# Check that cue mod init skips the language version +# when it lacks any version information at all. +# A zero pseudo-version is one such case, as there are no semver numbers. +env CUE_EXPERIMENT=modules +env CUE_VERSION_OVERRIDE=v0.0.0-00010101000000-000000000000 +exec cue mod init foo.example +cmp cue.mod/module.cue want-module + +# cue mod tidy should be a no-op after cue mod init +exec cue mod tidy +cmp cue.mod/module.cue want-module + +-- want-module -- +module: "foo.example@v0"