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

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

View as plain text