Skip to content

Commit

Permalink
No commit message
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaoxubeii committed Sep 18, 2018
1 parent d4ba617 commit 3730903
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/cmd/go/internal/clean/clean.go
Expand Up @@ -158,7 +158,7 @@ func runClean(cmd *base.Command, args []string) {
base.Fatalf("go clean -modcache: no module cache")
}
if cfg.BuildN || cfg.BuildX {
b.Showcmd("", "rm -r %s", modfetch.PkgMod)
b.Showcmd("", "rm -rf %s", modfetch.PkgMod)
}
if !cfg.BuildN {
if err := removeAll(modfetch.PkgMod); err != nil {
Expand Down
26 changes: 26 additions & 0 deletions src/cmd/go/script_test.go
Expand Up @@ -53,6 +53,32 @@ func TestScript(t *testing.T) {
}
}

// TestScript runs the tests in testdata/script/*.txt.
func TestCleanModeCache(t *testing.T) {
testenv.MustHaveGoBuild(t)
if skipExternal {
t.Skipf("skipping external tests on %s/%s", runtime.GOOS, runtime.GOARCH)
}

files, err := filepath.Glob("testdata/script/mod_clean_cache.txt")
if err != nil {
t.Fatal(err)
}
for _, file := range files {
file := file
name := strings.TrimSuffix(filepath.Base(file), ".txt")
t.Run(name, func(t *testing.T) {
t.Parallel()
ts := &testScript{t: t, name: name, file: file}
ts.setup()
if !*testWork {
defer removeAll(ts.workdir)
}
ts.run()
})
}
}

// A testScript holds execution state for a single test script.
type testScript struct {
t *testing.T
Expand Down
23 changes: 23 additions & 0 deletions src/cmd/go/testdata/script/mod_clean_cache.txt
@@ -0,0 +1,23 @@
env GO111MODULE=on

go mod download rsc.io/quote@v1.5.0
exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.0.info
exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.0.mod
exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.0.zip

go clean -modcache -n
stdout '^rm -rf .*/pkg/mod$'
exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.0.info
exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.0.mod
exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.0.zip

go clean -modcache
! exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.0.info
! exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.0.mod
! exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.0.zip

-- go.mod --
module m

-- m.go --
package m

0 comments on commit 3730903

Please sign in to comment.