Skip to content

Commit

Permalink
cmd/cue: check the structure of CUE_CACHE_DIR after downloading modules
Browse files Browse the repository at this point in the history
This acts as a nice regression test and visualization, and we will see
the impact of future changes like https://cuelang.org/issue/3139.

Note that ./mod/modcache already covers the presence of specific cache
files via its Go unit tests, but this added testscript check is a nice
complement which covers all files and shows the entire structure.

For #3139.

Signed-off-by: Daniel Martí <[email protected]>
Change-Id: I2ffa32f7ccb44b52c0bfad1bfe56f93a450d5a70
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1195517
Unity-Result: CUE porcuepine <[email protected]>
Reviewed-by: Paul Jolly <[email protected]>
TryBot-Result: CUEcueckoo <[email protected]>
  • Loading branch information
mvdan committed May 30, 2024
1 parent 4cdaa5d commit d94b670
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 1 deletion.
26 changes: 25 additions & 1 deletion cmd/cue/cmd/script_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ func TestScript(t *testing.T) {
// responds with [tokenErrorCodePending] once, and then succeeds
// * immediate-success: polling for a token with device_code succeeds right away
"oauthregistry": func(ts *testscript.TestScript, neg bool, args []string) {
if len(args) != 1 {
if neg || len(args) != 1 {
ts.Fatalf("usage: oauthregistry <mode>")
}
ts.Setenv("CUE_EXPERIMENT", "modules")
Expand All @@ -213,6 +213,30 @@ func TestScript(t *testing.T) {
ts.Setenv("CUE_REGISTRY", u.Host+"+insecure")
ts.Defer(srv.Close)
},
// find-files recursively lists files under a directory, like `find -type f` on Linux.
// It prints slash-separated paths relative to the root working directory of the testscript run,
// for the sake of avoiding verbose and non-deterministic absolute paths.
"find-files": func(ts *testscript.TestScript, neg bool, args []string) {
if neg || len(args) == 0 {
ts.Fatalf("usage: find-files args...")
}
out := ts.Stdout()
workdir := ts.Getenv("WORK")
for _, arg := range args {
err := filepath.WalkDir(arg, func(path string, d fs.DirEntry, err error) error {
if err != nil {
return err
}
if d.Type().IsRegular() {
rel, err := filepath.Rel(workdir, path)
ts.Check(err)
fmt.Fprintln(out, filepath.ToSlash(rel))
}
return nil
})
ts.Check(err)
}
},
},
Setup: func(e *testscript.Env) error {
// If a testscript loads CUE packages but forgot to set up a cue.mod,
Expand Down
29 changes: 29 additions & 0 deletions cmd/cue/cmd/testdata/script/modtidy_initial.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ cmp stdout want-stdout

# Check that the tidy check succeeds
exec cue mod tidy --check

# Check what the structure of CUE_CACHE_DIR looks like after fetching modules.
find-files ${CUE_CACHE_DIR}
cmp stdout cue-cache-dir.files
# Unused dependencies should not have their entire source downloaded or extracted.
! stdout 'unused\.com.*\.zip$'
-- want-module --
module: "main.org@v0"
language: {
Expand Down Expand Up @@ -54,6 +60,29 @@ import "example.com@v0:main"

main

-- cue-cache-dir.files --
.tmp/cache/[email protected]/bar/x.cue
.tmp/cache/[email protected]/cue.mod/module.cue
.tmp/cache/[email protected]/baz.cue
.tmp/cache/[email protected]/cue.mod/module.cue
.tmp/cache/cache/download/bar.com/@v/v0.5.0.lock
.tmp/cache/cache/download/bar.com/@v/v0.5.0.mod
.tmp/cache/cache/download/bar.com/@v/v0.5.0.zip
.tmp/cache/cache/download/baz.org/@v/v0.10.1.lock
.tmp/cache/cache/download/baz.org/@v/v0.10.1.mod
.tmp/cache/cache/download/baz.org/@v/v0.10.1.zip
.tmp/cache/cache/download/example.com/@v/v0.0.1.lock
.tmp/cache/cache/download/example.com/@v/v0.0.1.mod
.tmp/cache/cache/download/example.com/@v/v0.0.1.zip
.tmp/cache/cache/download/foo.com/bar/hello/@v/v0.2.3.lock
.tmp/cache/cache/download/foo.com/bar/hello/@v/v0.2.3.mod
.tmp/cache/cache/download/foo.com/bar/hello/@v/v0.2.3.zip
.tmp/cache/cache/download/unused.com/@v/v0.2.4.lock
.tmp/cache/cache/download/unused.com/@v/v0.2.4.mod
.tmp/cache/[email protected]/cue.mod/module.cue
.tmp/cache/[email protected]/top.cue
.tmp/cache/foo.com/bar/[email protected]/cue.mod/module.cue
.tmp/cache/foo.com/bar/[email protected]/x.cue
-- _registry/example.com_v0.0.1/cue.mod/module.cue --
module: "example.com@v0"
language: version: "v0.8.0"
Expand Down

0 comments on commit d94b670

Please sign in to comment.