1 cp go.work go.work.orig
2
3 # If the current directory contains a go.mod file,
4 # 'go work use .' should add an entry for it.
5 cd bar/baz
6 go work use .
7 cmp ../../go.work ../../go.work.rel
8
9 # If the current directory lacks a go.mod file, 'go work use .'
10 # should remove its entry.
11 mv go.mod go.mod.bak
12 go work use .
13 cmp ../../go.work ../../go.work.orig
14
15 # If the path is absolute, it should remain absolute.
16 mv go.mod.bak go.mod
17 go work use $PWD
18 grep -count=1 '^use ' ../../go.work
19 grep '^use ["]?'$PWD'["]?$' ../../go.work
20
21 # An absolute path should replace an entry for the corresponding relative path
22 # and vice-versa.
23 go work use .
24 cmp ../../go.work ../../go.work.rel
25 go work use $PWD
26 grep -count=1 '^use ' ../../go.work
27 grep '^use ["]?'$PWD'["]?$' ../../go.work
28
29 # If both the absolute and relative paths are named, 'go work use' should error
30 # out: we don't know which one to use, and shouldn't add both because the
31 # resulting workspace would contain a duplicate module.
32 cp ../../go.work.orig ../../go.work
33 ! go work use $PWD .
34 stderr '^go: already added "\./bar/baz" as "'$PWD'"$'
35 cmp ../../go.work ../../go.work.orig
36
37
38 -- go.mod --
39 module example
40 go 1.18
41 -- go.work --
42 go 1.18
43 -- go.work.rel --
44 go 1.18
45
46 use ./bar/baz
47 -- bar/baz/go.mod --
48 module example/bar/baz
49 go 1.18
50
View as plain text