...
1env GO111MODULE=on
2
3# Derive module path from import comment.
4cd $WORK/x
5exists x.go
6go mod init
7stderr 'module x'
8
9# Import comment works even with CRLF line endings.
10rm go.mod
11replace '\n' '\r\n' x.go
12go mod init
13stderr 'module x'
14
15# Derive module path from location inside GOPATH.
16# 'go mod init' should succeed if modules are not explicitly disabled.
17cd $GOPATH/src/example.com/x/y
18go mod init
19stderr 'module example.com/x/y$'
20rm go.mod
21
22# go mod init rejects a zero-length go.mod file
23cp $devnull go.mod # can't use touch to create it because Windows
24! go mod init
25stderr 'go.mod already exists'
26
27# Empty directory outside GOPATH fails.
28mkdir $WORK/empty
29cd $WORK/empty
30! go mod init
31stderr 'cannot determine module path for source directory'
32rm go.mod
33
34# Empty directory inside GOPATH/src uses location inside GOPATH.
35mkdir $GOPATH/src/empty
36cd $GOPATH/src/empty
37go mod init
38stderr 'empty'
39rm go.mod
40
41# In Plan 9, directories are automatically created in /n.
42# For example, /n/go.mod always exist, but it's a directory.
43# Test that we ignore directories when trying to find go.mod.
44cd $WORK/gomoddir
45! go list .
46stderr '^go: go.mod file not found in current directory or any parent directory; see ''go help modules''$'
47
48[!symlink] stop
49
50# gplink1/src/empty where gopathlink -> GOPATH
51symlink $WORK/gopathlink -> gopath
52cd $WORK/gopathlink/src/empty
53go mod init
54rm go.mod
55
56# GOPATH/src/link where link -> out of GOPATH
57symlink $GOPATH/src/link -> $WORK/empty
58cd $WORK/empty
59! go mod init
60cd $GOPATH/src/link
61go mod init
62stderr link
63rm go.mod
64
65# GOPATH/src/empty where GOPATH itself is a symlink
66env GOPATH=$WORK/gopathlink
67cd $GOPATH/src/empty
68go mod init
69rm go.mod
70cd $WORK/gopath/src/empty
71go mod init
72rm go.mod
73
74# GOPATH/src/link where GOPATH and link are both symlinks
75cd $GOPATH/src/link
76go mod init
77stderr link
78rm go.mod
79
80# Too hard: doesn't match unevaluated nor completely evaluated. (Only partially evaluated.)
81# Whether this works depends on which OS we are running on.
82# cd $WORK/gopath/src/link
83# ! go mod init
84
85-- $WORK/x/x.go --
86package x // import "x"
87
88-- $GOPATH/src/example.com/x/y/y.go --
89package y
90-- $GOPATH/src/example.com/x/y/z/z.go --
91package z
92-- $GOPATH/src/example.com/x/y/z/Godeps/Godeps.json --
93{"ImportPath": "unexpected.com/z"}
94
95-- $WORK/gomoddir/go.mod/README.txt --
96../go.mod is a directory, not a file.
97-- $WORK/gomoddir/p.go --
98package p
View as plain text