...
1cp 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.
5cd bar/baz
6go work use .
7cmp ../../go.work ../../go.work.rel
8
9# If the current directory lacks a go.mod file, 'go work use .'
10# should remove its entry.
11mv go.mod go.mod.bak
12go work use .
13cmp ../../go.work ../../go.work.orig
14
15# If the path is absolute, it should remain absolute.
16mv go.mod.bak go.mod
17go work use $PWD
18grep -count=1 '^use ' ../../go.work
19grep '^use ["]?'$PWD'["]?$' ../../go.work
20
21# An absolute path should replace an entry for the corresponding relative path
22# and vice-versa.
23go work use .
24cmp ../../go.work ../../go.work.rel
25go work use $PWD
26grep -count=1 '^use ' ../../go.work
27grep '^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.
32cp ../../go.work.orig ../../go.work
33! go work use $PWD .
34stderr '^go: already added "\./bar/baz" as "'$PWD'"$'
35cmp ../../go.work ../../go.work.orig
36
37
38-- go.mod --
39module example
40go 1.18
41-- go.work --
42go 1.18
43-- go.work.rel --
44go 1.18
45
46use ./bar/baz
47-- bar/baz/go.mod --
48module example/bar/baz
49go 1.18
View as plain text