Skip to content

Commit

Permalink
cue/load: change stdlib import test case
Browse files Browse the repository at this point in the history
This test case doesn't check an import that looks like it's from the
stdlib but _does_ have a valid identifier.

Also add a test case for the situation where there's a directory
inside `cue.mod` that looks like a standard library package.
It should not be possible to import such a package but currently
is (only from the command line).

For #2964.

Signed-off-by: Roger Peppe <rogpeppe@gmail.com>
Change-Id: I41e95480fbcb002babdca0bb5e28361f8ee72d17
  • Loading branch information
rogpeppe committed Mar 20, 2024
1 parent b648cf4 commit d564b9b
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 6 deletions.
32 changes: 26 additions & 6 deletions cue/load/loader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,15 +211,35 @@ dir: $CWD/testdata/testmod
display:command-line-arguments
files:
-`}, {
// NOTE: dir should probably be set to $CWD/testdata, but either way.
cfg: dirCfg,
args: []string{"non-existing"},
want: `err: implied package identifier "non-existing" from import path "non-existing" is not valid
path: non-existing
args: []string{"foo.com/bad-identifier"},
want: `err: implied package identifier "bad-identifier" from import path "foo.com/bad-identifier" is not valid
path: foo.com/bad-identifier
module: mod.test/test
root: $CWD/testdata/testmod
dir: $CWD/testdata/testmod/cue.mod/gen/non-existing
display:non-existing`,
dir: $CWD/testdata/testmod/cue.mod/gen/foo.com/bad-identifier
display:foo.com/bad-identifier`,
}, {
cfg: dirCfg,
args: []string{"nonexisting"},
want: `err: cannot find package "nonexisting"
path: nonexisting
module: mod.test/test
root: $CWD/testdata/testmod
dir: $CWD/testdata/testmod/cue.mod/gen/nonexisting
display:nonexisting`,
}, {
// TODO this should not work, as "strconv" is a standard library
// import and should always be treated as such.
cfg: dirCfg,
args: []string{"strconv"},
want: `path: strconv
module: mod.test/test
root: $CWD/testdata/testmod
dir: $CWD/testdata/testmod/cue.mod/gen/strconv
display:strconv
files:
$CWD/testdata/testmod/cue.mod/pkg/strconv/strconv.cue`,
}, {
cfg: dirCfg,
args: []string{"./empty"},
Expand Down
3 changes: 3 additions & 0 deletions cue/load/testdata/testmod/cue.mod/pkg/strconv/strconv.cue
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Note: this is an invalidate substitute for the stdlib strconv
// package and should not be considered for import.
package strconv

0 comments on commit d564b9b

Please sign in to comment.