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