...

Text file src/cmd/go/testdata/script/mod_find.txt

Documentation: cmd/go/testdata/script

     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# Module path from Godeps/Godeps.json overrides GOPATH.
    28cd $GOPATH/src/example.com/x/y/z
    29go mod init
    30stderr 'unexpected.com/z'
    31rm go.mod
    32
    33# Empty directory outside GOPATH fails.
    34mkdir $WORK/empty
    35cd $WORK/empty
    36! go mod init
    37stderr 'cannot determine module path for source directory'
    38rm go.mod
    39
    40# Empty directory inside GOPATH/src uses location inside GOPATH.
    41mkdir $GOPATH/src/empty
    42cd $GOPATH/src/empty
    43go mod init
    44stderr 'empty'
    45rm go.mod
    46
    47# In Plan 9, directories are automatically created in /n.
    48# For example, /n/go.mod always exist, but it's a directory.
    49# Test that we ignore directories when trying to find go.mod.
    50cd $WORK/gomoddir
    51! go list .
    52stderr '^go: go.mod file not found in current directory or any parent directory; see ''go help modules''$'
    53
    54[!symlink] stop
    55
    56# gplink1/src/empty where gopathlink -> GOPATH
    57symlink $WORK/gopathlink -> gopath
    58cd $WORK/gopathlink/src/empty
    59go mod init
    60rm go.mod
    61
    62# GOPATH/src/link where link -> out of GOPATH
    63symlink $GOPATH/src/link -> $WORK/empty
    64cd $WORK/empty
    65! go mod init
    66cd $GOPATH/src/link
    67go mod init
    68stderr link
    69rm go.mod
    70
    71# GOPATH/src/empty where GOPATH itself is a symlink
    72env GOPATH=$WORK/gopathlink
    73cd $GOPATH/src/empty
    74go mod init
    75rm go.mod
    76cd $WORK/gopath/src/empty
    77go mod init
    78rm go.mod
    79
    80# GOPATH/src/link where GOPATH and link are both symlinks
    81cd $GOPATH/src/link
    82go mod init
    83stderr link
    84rm go.mod
    85
    86# Too hard: doesn't match unevaluated nor completely evaluated. (Only partially evaluated.)
    87# Whether this works depends on which OS we are running on.
    88# cd $WORK/gopath/src/link
    89# ! go mod init
    90
    91-- $WORK/x/x.go --
    92package x // import "x"
    93
    94-- $GOPATH/src/example.com/x/y/y.go --
    95package y
    96-- $GOPATH/src/example.com/x/y/z/z.go --
    97package z
    98-- $GOPATH/src/example.com/x/y/z/Godeps/Godeps.json --
    99{"ImportPath": "unexpected.com/z"}
   100
   101-- $WORK/gomoddir/go.mod/README.txt --
   102../go.mod is a directory, not a file.
   103-- $WORK/gomoddir/p.go --
   104package p

View as plain text