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

     1  ! go work init doesnotexist
     2  stderr 'go: directory doesnotexist does not exist'
     3  go env GOWORK
     4  ! stdout .
     5  
     6  go work init ./a ./b
     7  cmpenv go.work go.work.want
     8  go env GOWORK
     9  stdout '^'$WORK'(\\|/)gopath(\\|/)src(\\|/)go.work$'
    10  
    11  ! go run  example.com/b
    12  stderr 'a(\\|/)a.go:4:8: no required module provides package rsc.io/quote; to add it:\n\tcd '$WORK(\\|/)gopath(\\|/)src(\\|/)a'\n\tgo get rsc.io/quote'
    13  cd a
    14  go get rsc.io/quote
    15  cat go.mod
    16  go env GOMOD # go env GOMOD reports the module in a single module context
    17  stdout $GOPATH(\\|/)src(\\|/)a(\\|/)go.mod
    18  cd ..
    19  go run example.com/b
    20  stdout 'Hello, world.'
    21  
    22  # And try from a different directory
    23  cd c
    24  go run  example.com/b
    25  stdout 'Hello, world.'
    26  cd $GOPATH/src
    27  
    28  go list all # all includes both modules
    29  stdout 'example.com/a'
    30  stdout 'example.com/b'
    31  
    32  # -mod can only be set to readonly in workspace mode
    33  go list -mod=readonly all
    34  ! go list -mod=mod all
    35  stderr '^go: -mod may only be set to readonly or vendor when in workspace mode'
    36  env GOWORK=off
    37  go list -mod=mod all
    38  env GOWORK=
    39  
    40  # Test that duplicates in the use list return an error
    41  cp go.work go.work.backup
    42  cp go.work.dup go.work
    43  ! go run example.com/b
    44  stderr 'go.work:6: path .* appears multiple times in workspace'
    45  cp go.work.backup go.work
    46  
    47  cp go.work.d go.work
    48  go work use # update go version
    49  go run example.com/d
    50  
    51  # Test that we don't run into "newRequirements called with unsorted roots"
    52  # panic with unsorted main modules.
    53  cp go.work.backwards go.work
    54  go work use # update go version
    55  go run example.com/d
    56  
    57  # Test that command-line-arguments work inside and outside modules.
    58  # This exercises the code that determines which module command-line-arguments
    59  # belongs to.
    60  go list ./b/main.go
    61  env GOWORK=off
    62  go build -n -o foo foo.go
    63  env GOWORK=
    64  go build -n -o foo foo.go
    65  
    66  -- go.work.dup --
    67  go 1.18
    68  
    69  use (
    70  	a
    71  	b
    72  	../src/a
    73  )
    74  -- go.work.want --
    75  go $goversion
    76  
    77  use (
    78  	./a
    79  	./b
    80  )
    81  -- go.work.d --
    82  go 1.18
    83  
    84  use (
    85  	a
    86  	b
    87  	d
    88  )
    89  -- a/go.mod --
    90  
    91  module example.com/a
    92  
    93  -- a/a.go --
    94  package a
    95  
    96  import "fmt"
    97  import "rsc.io/quote"
    98  
    99  func HelloFromA() {
   100  	fmt.Println(quote.Hello())
   101  }
   102  
   103  -- b/go.mod --
   104  
   105  module example.com/b
   106  
   107  -- b/main.go --
   108  package main
   109  
   110  import "example.com/a"
   111  
   112  func main() {
   113  	a.HelloFromA()
   114  }
   115  -- b/lib/hello.go --
   116  package lib
   117  
   118  import "example.com/a"
   119  
   120  func Hello() {
   121  	a.HelloFromA()
   122  }
   123  
   124  -- c/README --
   125  Create this directory so we can cd to
   126  it and make sure paths are interpreted
   127  relative to the go.work, not the cwd.
   128  -- d/go.mod --
   129  module example.com/d
   130  
   131  -- d/main.go --
   132  package main
   133  
   134  import "example.com/b/lib"
   135  
   136  func main() {
   137  	lib.Hello()
   138  }
   139  
   140  -- go.work.backwards --
   141  go 1.18
   142  
   143  use (
   144  	d
   145  	b
   146  	a
   147  )
   148  
   149  -- foo.go --
   150  package main
   151  import "fmt"
   152  func main() {
   153  	fmt.Println("Hello, World")
   154  }
   155  

View as plain text