1 # Regression test for golang.org/issue/31481.
2
3 env GO111MODULE=on
4
5 # golang.org/issue/31481: an explicit flag should make directories in the module
6 # cache writable in order to work around the historical inability of 'rm -rf' to
7 # forcibly remove files in unwritable directories.
8 go get -modcacherw rsc.io/quote@v1.5.2
9 cp $WORK/extraneous.txt $GOPATH/pkg/mod/rsc.io/quote@v1.5.2/extraneous_file.go
10
11 # After adding an extraneous file, 'go mod verify' should fail.
12 ! go mod verify
13
14 # However, files within those directories should still be read-only to avoid
15 # accidental mutations.
16 [!root] ! cp $WORK/extraneous.txt $GOPATH/pkg/mod/rsc.io/quote@v1.5.2/go.mod
17
18 # If all 'go' commands ran with the flag, the system's 'rm' binary
19 # should be able to remove the module cache if the '-rf' flags are set.
20 [!GOOS:windows] [exec:rm] exec rm -rf $GOPATH/pkg/mod
21 [!GOOS:windows] [!exec:rm] go clean -modcache
22 [GOOS:windows] [exec:cmd.exe] exec cmd.exe /c rmdir /s /q $GOPATH\pkg\mod
23 [GOOS:windows] [!exec:cmd.exe] go clean -modcache
24 ! exists $GOPATH/pkg/mod
25
26 # The directories in the module cache should by default be unwritable,
27 # so that tests and tools will not accidentally add extraneous files to them.
28 # Windows does not respect FILE_ATTRIBUTE_READONLY on directories, according
29 # to MSDN, so there we disable testing whether the directory itself is
30 # unwritable.
31 go get rsc.io/quote@latest
32 [!root] ! cp $WORK/extraneous.txt $GOPATH/pkg/mod/rsc.io/quote@v1.5.2/go.mod
33 [!GOOS:windows] [!root] ! cp $WORK/extraneous.txt $GOPATH/pkg/mod/rsc.io/quote@v1.5.2/extraneous_file.go
34 ! exists $GOPATH/pkg/mod/rsc.io/quote@v1.5.2/extraneous_file.go
35
36
37 # Repeat part of the test with 'go mod download' instead of 'go get' to verify
38 # -modcacherw is supported on 'go mod' subcommands.
39 go clean -modcache
40 go mod download -modcacherw rsc.io/quote
41 cp $WORK/extraneous.txt $GOPATH/pkg/mod/rsc.io/quote@v1.5.2/extraneous_file.go
42 ! go mod verify
43 [!root] ! cp $WORK/extraneous.txt $GOPATH/pkg/mod/rsc.io/quote@v1.5.2/go.mod
44
45
46 -- $WORK/extraneous.txt --
47 module oops
48 -- go.mod --
49 module golang.org/issue/31481
50
View as plain text