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

     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  # Module path from Godeps/Godeps.json overrides GOPATH.
    28  cd $GOPATH/src/example.com/x/y/z
    29  go mod init
    30  stderr 'unexpected.com/z'
    31  rm go.mod
    32  
    33  # Empty directory outside GOPATH fails.
    34  mkdir $WORK/empty
    35  cd $WORK/empty
    36  ! go mod init
    37  stderr 'cannot determine module path for source directory'
    38  rm go.mod
    39  
    40  # Empty directory inside GOPATH/src uses location inside GOPATH.
    41  mkdir $GOPATH/src/empty
    42  cd $GOPATH/src/empty
    43  go mod init
    44  stderr 'empty'
    45  rm 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.
    50  cd $WORK/gomoddir
    51  ! go list .
    52  stderr '^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
    57  symlink $WORK/gopathlink -> gopath
    58  cd $WORK/gopathlink/src/empty
    59  go mod init
    60  rm go.mod
    61  
    62  # GOPATH/src/link where link -> out of GOPATH
    63  symlink $GOPATH/src/link -> $WORK/empty
    64  cd $WORK/empty
    65  ! go mod init
    66  cd $GOPATH/src/link
    67  go mod init
    68  stderr link
    69  rm go.mod
    70  
    71  # GOPATH/src/empty where GOPATH itself is a symlink
    72  env GOPATH=$WORK/gopathlink
    73  cd $GOPATH/src/empty
    74  go mod init
    75  rm go.mod
    76  cd $WORK/gopath/src/empty
    77  go mod init
    78  rm go.mod
    79  
    80  # GOPATH/src/link where GOPATH and link are both symlinks
    81  cd $GOPATH/src/link
    82  go mod init
    83  stderr link
    84  rm 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 --
    92  package x // import "x"
    93  
    94  -- $GOPATH/src/example.com/x/y/y.go --
    95  package y
    96  -- $GOPATH/src/example.com/x/y/z/z.go --
    97  package 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 --
   104  package p
   105  

View as plain text