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