this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

cmd/cue: add tests for bad version and qualifier in import paths

Cover edge cases where a package qualifier interacts with the version
in an import path: a full version before a qualifier, and a second
version string inside the qualifier. Also test qualifier-before-version
as a CLI argument.

We do this as part of a new registry_importpath_bad_version.txtar test,
which replaces the registry_importpath_with_full_version.txtar
to be a bit more generic about import paths with bad versions.

For #2859.

Signed-off-by: Daniel Martí <mvdan@mvdan.cc>
Change-Id: I82a3ee5c444a35335725062b68b8e7943f69d8c5
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1233778
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>
Reviewed-by: Roger Peppe <rogpeppe@gmail.com>
Unity-Result: CUE porcuepine <cue.porcuepine@gmail.com>

+114 -22
+5
cmd/cue/cmd/testdata/script/mod_absolute_package.txtar
··· 28 28 ! exec cue vet -d self foo.com/bar@v3.latest data.json 29 29 cmp stderr stderr4-golden 30 30 31 + # Check that the package qualifier must come after the version, not before. 32 + # TODO: this should give a clear error. 33 + ! exec cue export foo.com/bar:baz@v1.5.0 34 + stderr 'cannot combine scope with file' 35 + 31 36 -- stdout1-golden -- 32 37 { 33 38 "self": "foo.com_v2.1.0/bar"
+99
cmd/cue/cmd/testdata/script/registry_importpath_bad_version.txtar
··· 1 + # Test that the version must only be a major version, and not a full version. 2 + cd full-version 3 + ! exec cue export . 4 + cmp stderr ../expect-stderr-full-version 5 + 6 + # Test that the version must come before the package qualifier, not after. 7 + # TODO: this should give a clear error. 8 + cd ../qualifier-before 9 + ! exec cue export . 10 + cmp stderr ../expect-stderr-qualifier-before 11 + 12 + # Test that a full version is rejected even with a qualifier after it. 13 + cd ../full-version-qualifier 14 + ! exec cue export . 15 + cmp stderr ../expect-stderr-full-version-qualifier 16 + 17 + # Test that a version in the qualifier is not treated as a path version. 18 + # TODO: this should give a clear error. 19 + cd ../version-in-qualifier 20 + ! exec cue export . 21 + cmp stderr ../expect-stderr-version-in-qualifier 22 + 23 + # Test that qualifier after the version works correctly. 24 + cd ../qualifier-after 25 + exec cue export . 26 + cmp stdout ../expect-stdout-qualifier-after 27 + 28 + -- expect-stderr-full-version -- 29 + test.org/full-version@v0: import failed: cannot find package "example.com/main@v0.0.2": malformed import path "example.com/main@v0.0.2": import paths can only contain a major version specifier: 30 + ./main.cue:2:8 31 + -- expect-stderr-qualifier-before -- 32 + test.org/qualifier-before@v0: import failed: cannot find package "example.com/main": no files in package directory with package name "other@v0": 33 + ./main.cue:2:8 34 + -- expect-stderr-full-version-qualifier -- 35 + test.org/full-version-qualifier@v0: import failed: cannot find package "example.com/main@v0.0.2": malformed import path "example.com/main@v0.0.2:other": import paths can only contain a major version specifier: 36 + ./main.cue:2:8 37 + -- expect-stderr-version-in-qualifier -- 38 + test.org/version-in-qualifier@v0: import failed: cannot find package "example.com/main@v0": no files in package directory with package name "other@v1": 39 + ./main.cue:2:8 40 + -- expect-stdout-qualifier-after -- 41 + { 42 + "foo": "from other" 43 + } 44 + -- full-version/main.cue -- 45 + package main 46 + import "example.com/main@v0.0.2" 47 + 48 + main.foo 49 + -- full-version/cue.mod/module.cue -- 50 + module: "test.org/full-version" 51 + language: version: "v0.8.0" 52 + deps: "example.com/main": v: "v0.0.2" 53 + -- qualifier-before/main.cue -- 54 + package main 55 + import "example.com/main:other@v0" 56 + 57 + other.foo 58 + -- qualifier-before/cue.mod/module.cue -- 59 + module: "test.org/qualifier-before" 60 + language: version: "v0.8.0" 61 + deps: "example.com/main": v: "v0.0.2" 62 + -- full-version-qualifier/main.cue -- 63 + package main 64 + import "example.com/main@v0.0.2:other" 65 + 66 + other.foo 67 + -- full-version-qualifier/cue.mod/module.cue -- 68 + module: "test.org/full-version-qualifier" 69 + language: version: "v0.8.0" 70 + deps: "example.com/main": v: "v0.0.2" 71 + -- version-in-qualifier/main.cue -- 72 + package main 73 + import "example.com/main@v0:other@v1" 74 + 75 + other.foo 76 + -- version-in-qualifier/cue.mod/module.cue -- 77 + module: "test.org/version-in-qualifier" 78 + language: version: "v0.8.0" 79 + deps: "example.com/main": v: "v0.0.2" 80 + -- qualifier-after/main.cue -- 81 + package main 82 + import "example.com/main@v0:other" 83 + 84 + other 85 + -- qualifier-after/cue.mod/module.cue -- 86 + module: "test.org/qualifier-after" 87 + language: version: "v0.8.0" 88 + deps: "example.com/main": v: "v0.0.2" 89 + -- _registry/example.com_main_v0.0.2/cue.mod/module.cue -- 90 + module: "example.com/main@v0" 91 + language: version: "v0.8.0" 92 + 93 + -- _registry/example.com_main_v0.0.2/main.cue -- 94 + package main 95 + 96 + -- _registry/example.com_main_v0.0.2/other.cue -- 97 + package other 98 + 99 + foo: "from other"
-22
cmd/cue/cmd/testdata/script/registry_importpath_with_full_version.txtar
··· 1 - ! exec cue eval . 2 - cmp stderr expect-stderr 3 - 4 - -- expect-stderr -- 5 - test.org@v0: import failed: cannot find package "example.com/e@v0.0.2": malformed import path "example.com/e@v0.0.2": import paths can only contain a major version specifier: 6 - ./main.cue:2:8 7 - -- main.cue -- 8 - package main 9 - import "example.com/e@v0.0.2" 10 - 11 - e.foo 12 - 13 - -- cue.mod/module.cue -- 14 - module: "test.org" 15 - language: version: "v0.8.0" 16 - deps: "example.com/e": v: "v0.0.2" 17 - -- _registry/example.com_e_v0.0.2/cue.mod/module.cue -- 18 - module: "example.com/e@v0" 19 - language: version: "v0.8.0" 20 - 21 - -- _registry/example.com_e_v0.0.2/main.cue -- 22 - package e
+10
mod/module/module_test.go
··· 488 488 modErr: `module path inappropriately contains version`, 489 489 }, { 490 490 path: `foo.com/bar/baz`, 491 + }, { 492 + // TODO: CheckImportPath should reject a version inside the qualifier. 493 + path: `foo.com/bar:baz@v0`, 494 + modErr: `module path inappropriately contains version`, 495 + fileErr: `malformed file path "foo.com/bar:baz@v0": invalid char ':'`, 496 + }, { 497 + // TODO: CheckImportPath should reject a version inside the qualifier. 498 + path: `foo.com/bar@v0:baz@v1`, 499 + modErr: `module path inappropriately contains version`, 500 + fileErr: `malformed file path "foo.com/bar@v0:baz@v1": invalid char ':'`, 491 501 }} 492 502 493 503 func TestCheckPathWithoutVersion(t *testing.T) {