1 env GO111MODULE=on
2
3 # We should not create a go.mod file unless the user ran 'go mod init' explicitly.
4 # However, we should suggest 'go mod init' if we can find an alternate config file.
5 cd $WORK/test/x
6 ! go list .
7 stderr 'found .git/config in .*[/\\]test'
8 stderr '\s*cd \.\. && go mod init'
9
10 # The command we suggested should succeed.
11 cd ..
12 go mod init
13 go list -m all
14 stdout '^m$'
15
16 # We should not suggest creating a go.mod file in $GOROOT, even though there may be a .git/config there.
17 cd $GOROOT
18 ! go list .
19 ! stderr 'go mod init'
20
21 # We should also not suggest creating a go.mod file in $GOROOT if its own
22 # .git/config has been stripped away and we find one in a parent directory.
23 # (https://golang.org/issue/34191)
24 env GOROOT=$WORK/parent/goroot
25 cd $GOROOT
26 ! go list .
27 ! stderr 'go mod init'
28
29 cd $GOROOT/doc
30 ! go list .
31 ! stderr 'go mod init'
32
33 -- $WORK/test/.git/config --
34 -- $WORK/test/x/x.go --
35 package x // import "m/x"
36 -- $WORK/parent/.git/config --
37 -- $WORK/parent/goroot/README --
38 This directory isn't really a GOROOT, but let's pretend that it is.
39 -- $WORK/parent/goroot/doc/README --
40 This is a subdirectory of our fake GOROOT.
41
View as plain text