...
1env GO111MODULE=on
2[short] skip
3
4# Populate go.sum.
5go mod tidy
6cp go.mod go.mod.orig
7
8go list -test all
9stdout rsc.io/quote
10stdout golang.org/x/text/language
11
12# why a package?
13go mod why golang.org/x/text/language
14cmp stdout why-language.txt
15
16# why a module?
17go mod why -m golang.org...
18cmp stdout why-text-module.txt
19
20# why a package used only in tests?
21go mod why rsc.io/testonly
22cmp stdout why-testonly.txt
23
24# why a module used only in a test of a dependency?
25go mod why -m rsc.io/testonly
26cmp stdout why-testonly.txt
27
28# test package not needed
29go mod why golang.org/x/text/unused
30cmp stdout why-unused.txt
31
32# vendor doesn't use packages used only in tests.
33go mod why -vendor rsc.io/testonly
34cmp stdout why-vendor.txt
35
36# vendor doesn't use modules used only in tests.
37go mod why -vendor -m rsc.io/testonly
38cmp stdout why-vendor-module.txt
39
40# test multiple packages
41go mod why golang.org/x/text/language golang.org/x/text/unused
42cmp stdout why-both.txt
43
44# test multiple modules
45go mod why -m rsc.io/quote rsc.io/sampler
46cmp stdout why-both-module.txt
47
48# package in a module that isn't even in the module graph
49# (https://golang.org/issue/26977)
50go mod why rsc.io/fortune
51cmp stdout why-missing.txt
52
53# None of these command should have changed the go.mod file.
54cmp go.mod go.mod.orig
55
56-- go.mod --
57module mymodule
58require rsc.io/quote v1.5.2
59
60-- x/x.go --
61package x
62import _ "mymodule/z"
63
64-- y/y.go --
65package y
66
67-- y/y_test.go --
68package y
69import _ "rsc.io/quote"
70
71-- z/z.go --
72package z
73import _ "mymodule/y"
74
75
76-- why-language.txt --
77# golang.org/x/text/language
78mymodule/y
79mymodule/y.test
80rsc.io/quote
81rsc.io/sampler
82golang.org/x/text/language
83-- why-unused.txt --
84# golang.org/x/text/unused
85(main module does not need package golang.org/x/text/unused)
86-- why-text-module.txt --
87# golang.org/x/text
88mymodule/y
89mymodule/y.test
90rsc.io/quote
91rsc.io/sampler
92golang.org/x/text/language
93-- why-testonly.txt --
94# rsc.io/testonly
95mymodule/y
96mymodule/y.test
97rsc.io/quote
98rsc.io/sampler
99rsc.io/sampler.test
100rsc.io/testonly
101-- why-vendor.txt --
102# rsc.io/testonly
103(main module does not need to vendor package rsc.io/testonly)
104-- why-vendor-module.txt --
105# rsc.io/testonly
106(main module does not need to vendor module rsc.io/testonly)
107-- why-both.txt --
108# golang.org/x/text/language
109mymodule/y
110mymodule/y.test
111rsc.io/quote
112rsc.io/sampler
113golang.org/x/text/language
114
115# golang.org/x/text/unused
116(main module does not need package golang.org/x/text/unused)
117-- why-both-module.txt --
118# rsc.io/quote
119mymodule/y
120mymodule/y.test
121rsc.io/quote
122
123# rsc.io/sampler
124mymodule/y
125mymodule/y.test
126rsc.io/quote
127rsc.io/sampler
128-- why-missing.txt --
129# rsc.io/fortune
130(main module does not need package rsc.io/fortune)
View as plain text