Skip to content

Commit

Permalink
internal/mod: more tests
Browse files Browse the repository at this point in the history
This CL adds some tests for behavior that changes with subsequent
CLs in this chain.

Also adjust some tests so they are using legitimate import
paths with a valid package name implied from the import path.

 For #3155

Signed-off-by: Roger Peppe <rogpeppe@gmail.com>
Change-Id: Ia811527f0389b422e916b4eb472600b2640569f5
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1195279
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>
Unity-Result: CUE porcuepine <cue.porcuepine@gmail.com>
Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
  • Loading branch information
rogpeppe authored and mvdan committed May 28, 2024
1 parent 1a58708 commit 9c800db
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 4 deletions.
8 changes: 8 additions & 0 deletions internal/mod/modimports/modimports_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@ import "other"
-- omitted --
-- y.cue --
package y
-- sub/x.cue --
package x
import (
"imported-from-sub.com/foo"
)
`))
tfs := txtarfs.FS(dirContents)
imps, err := AllImports(PackageFiles(tfs, ".", "*"))
Expand All @@ -111,4 +116,7 @@ package y
imps, err = AllImports(PackageFiles(tfs, "foo", "*"))
qt.Assert(t, qt.IsNil(err))
qt.Assert(t, qt.DeepEquals(imps, []string{"other"}))
imps, err = AllImports(PackageFiles(tfs, "sub", "x"))
qt.Assert(t, qt.IsNil(err))
qt.Assert(t, qt.DeepEquals(imps, []string{"imported-from-sub.com/foo"}))
}
4 changes: 4 additions & 0 deletions internal/mod/modimports/testdata/simple.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ y/y1.cue "dep3" "dep4"
y/y2.cue
y/z1.cue
y/z2.cue
z.cue
-- want-imports --
dep1
dep2:a
Expand Down Expand Up @@ -40,6 +41,9 @@ package z
-- y/z2.cue --
package z

-- z.cue --
package example

-- _omitted1/foo.cue --
not even looked at

Expand Down
4 changes: 2 additions & 2 deletions internal/mod/modload/testdata/tidy/canuseprerelease.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# no stable releases available.

-- tidy-check-error --
module is not tidy: cannot find module providing package example.com@v0
module is not tidy: cannot find module providing package example.com@v0:main
-- want --
module: "main.org@v0"
language: {
Expand All @@ -20,7 +20,7 @@ language: version: "v0.8.0"
-- main.cue --
package main

import "example.com@v0"
import "example.com@v0:main"

-- _registry/example.com_v0.0.1-foo/cue.mod/module.cue --
module: "example.com@v0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ deps: {
-- main.cue --
package main

import "example.com"
import "example.com:main"

-- _registry/example.com_v0.0.1/cue.mod/module.cue --
module: "example.com@v0"
Expand Down
2 changes: 1 addition & 1 deletion internal/mod/modload/testdata/tidy/preferstable.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ language: {
-- main.cue --
package main

import "example.com@v0"
import "example.com@v0:main"

-- _registry/example.com_v0.0.1/cue.mod/module.cue --
module: "example.com@v0"
Expand Down
32 changes: 32 additions & 0 deletions internal/mod/modpkgload/testdata/multidir.txtar
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
-- test0/initial-requirements --
main.test@v0
example.com@v0.0.1
-- test0/root-packages --
main.test@v0:main
-- test0/default-major-versions --
-- test0/want --
main.test@v0:main
flags: inAll,isRoot,fromRoot,importsLoaded
mod: main.test@v0
location: .
imports:
example.com/blah@v0
example.com/blah@v0
flags: inAll,isRoot,fromRoot,importsLoaded
mod: example.com@v0.0.1
location: _registry/example.com_v0.0.1/blah
-- main.cue --
package main
import "example.com/blah@v0"

-- _registry/example.com_v0.0.1/cue.mod/module.cue --
module: "example.com@v0"
language: version: "v0.8.0"
-- _registry/example.com_v0.0.1/blah/blah.cue --
package blah
-- _registry/example.com_v0.0.1/x.cue --
package blah
import _ "foo.com/bar/hello/goodbye@v0"
-- _registry/example.com_v0.0.1/y.cue --
package other
import _ "foo.com/bar/somethingelse@v0"
28 changes: 28 additions & 0 deletions internal/mod/modpkgload/testdata/nocuefiles.txtar
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
-- test0/initial-requirements --
main.test@v0
example.com@v0.0.1
-- test0/root-packages --
main.test@v0:main
-- test0/default-major-versions --
-- test0/want --
main.test@v0:main
flags: inAll,isRoot,fromRoot,importsLoaded
mod: main.test@v0
location: .
imports:
example.com/blah@v0
example.com/blah@v0
flags: inAll,isRoot,fromRoot,importsLoaded
mod: example.com@v0.0.1
location: _registry/example.com_v0.0.1/blah
-- main.cue --
package main
import "example.com/blah@v0"

-- _registry/example.com_v0.0.1/cue.mod/module.cue --
module: "example.com@v0"
language: version: "v0.8.0"
-- _registry/example.com_v0.0.1/blah/x.cue --
package a
-- _registry/example.com_v0.0.1/blah/other/other.cue --
package b

0 comments on commit 9c800db

Please sign in to comment.