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