| 1 |
env GO111MODULE=on |
| 2 |
|
| 3 |
# Derive module path from import comment. |
| 4 |
cd $WORK/x |
| 5 |
exists x.go |
| 6 |
go mod init |
| 7 |
stderr 'module x' |
| 8 |
|
| 9 |
# Import comment works even with CRLF line endings. |
| 10 |
rm go.mod |
| 11 |
replace '\n' '\r\n' x.go |
| 12 |
go mod init |
| 13 |
stderr 'module x' |
| 14 |
|
| 15 |
# Derive module path from location inside GOPATH. |
| 16 |
# 'go mod init' should succeed if modules are not explicitly disabled. |
| 17 |
cd $GOPATH/src/example.com/x/y |
| 18 |
go mod init |
| 19 |
stderr 'module example.com/x/y$' |
| 20 |
rm go.mod |
| 21 |
|
| 22 |
# go mod init rejects a zero-length go.mod file |
| 23 |
cp $devnull go.mod # can't use touch to create it because Windows |
| 24 |
! go mod init |
| 25 |
stderr 'go.mod already exists' |
| 26 |
|
| 27 |
# Empty directory outside GOPATH fails. |
| 28 |
mkdir $WORK/empty |
| 29 |
cd $WORK/empty |
| 30 |
! go mod init |
| 31 |
stderr 'cannot determine module path for source directory' |
| 32 |
rm go.mod |
| 33 |
|
| 34 |
# Empty directory inside GOPATH/src uses location inside GOPATH. |
| 35 |
mkdir $GOPATH/src/empty |
| 36 |
cd $GOPATH/src/empty |
| 37 |
go mod init |
| 38 |
stderr 'empty' |
| 39 |
rm 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. |
| 44 |
cd $WORK/gomoddir |
| 45 |
! go list . |
| 46 |
stderr '^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 |
| 51 |
symlink $WORK/gopathlink -> gopath |
| 52 |
cd $WORK/gopathlink/src/empty |
| 53 |
go mod init |
| 54 |
rm go.mod |
| 55 |
|
| 56 |
# GOPATH/src/link where link -> out of GOPATH |
| 57 |
symlink $GOPATH/src/link -> $WORK/empty |
| 58 |
cd $WORK/empty |
| 59 |
! go mod init |
| 60 |
cd $GOPATH/src/link |
| 61 |
go mod init |
| 62 |
stderr link |
| 63 |
rm go.mod |
| 64 |
|
| 65 |
# GOPATH/src/empty where GOPATH itself is a symlink |
| 66 |
env GOPATH=$WORK/gopathlink |
| 67 |
cd $GOPATH/src/empty |
| 68 |
go mod init |
| 69 |
rm go.mod |
| 70 |
cd $WORK/gopath/src/empty |
| 71 |
go mod init |
| 72 |
rm go.mod |
| 73 |
|
| 74 |
# GOPATH/src/link where GOPATH and link are both symlinks |
| 75 |
cd $GOPATH/src/link |
| 76 |
go mod init |
| 77 |
stderr link |
| 78 |
rm 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 -- |
| 86 |
package x // import "x" |
| 87 |
|
| 88 |
-- $GOPATH/src/example.com/x/y/y.go -- |
| 89 |
package y |
| 90 |
-- $GOPATH/src/example.com/x/y/z/z.go -- |
| 91 |
package 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 -- |
| 98 |
package p |