aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/go/testdata/script/mod_graph_version.txt
blob: f9a73f4617b34366cb2ffd146ad969614034f641 (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
# For this module, Go 1.17 prunes out a (transitive and otherwise-irrelevant)
# requirement on a retracted higher version of a dependency.
# However, when Go 1.16 reads the same requirements from the go.mod file,
# it does not prune out that requirement, and selects the retracted version.
#
# The Go 1.16 module graph looks like:
#
# m ---- lazy v0.1.0 ---- requireincompatible v0.1.0 ---- incompatible v2.0.0+incompatible
# |        |
# + -------+------------- incompatible v1.0.0
#
# The Go 1.17 module graph is the same except that the dependencies of
# requireincompatible are pruned out (because the module that requires
# it — lazy v0.1.0 — specifies 'go 1.17', and it is not otherwise relevant to
# the main module).

cp go.mod go.mod.orig

go mod graph
cp stdout graph-1.17.txt
stdout '^example\.com/m example\.com/retract/incompatible@v1\.0\.0$'
stdout '^example\.net/lazy@v0\.1\.0 example\.com/retract/incompatible@v1\.0\.0$'
! stdout 'example\.com/retract/incompatible@v2\.0\.0\+incompatible'

go mod graph -go=1.17
cmp stdout graph-1.17.txt

cmp go.mod go.mod.orig


# Setting -go=1.16 should report the graph as viewed by Go 1.16,
# but should not edit the go.mod file.

go mod graph -go=1.16
cp stdout graph-1.16.txt
stdout '^example\.com/m example\.com/retract/incompatible@v1\.0\.0$'
stdout '^example\.net/lazy@v0\.1\.0 example.com/retract/incompatible@v1\.0\.0$'
stdout '^example.net/requireincompatible@v0.1.0 example.com/retract/incompatible@v2\.0\.0\+incompatible$'

cmp go.mod go.mod.orig


# If we actually update the go.mod file to the requested go version,
# we should get the same selected versions, but the roots of the graph
# may be updated.
#
# TODO(#45551): The roots should not be updated.

go mod edit -go=1.16
go mod graph
! stdout '^example\.com/m example\.com/retract/incompatible@v1\.0\.0$'
stdout '^example\.net/lazy@v0.1.0 example.com/retract/incompatible@v1\.0\.0$'
stdout '^example.net/requireincompatible@v0.1.0 example.com/retract/incompatible@v2\.0\.0\+incompatible$'
	# TODO(#45551): cmp stdout graph-1.16.txt


# Unsupported go versions should be rejected, since we don't know
# what versions they would report.
! go mod graph -go=1.99999999999
stderr '^invalid value "1\.99999999999" for flag -go: maximum supported Go version is '$goversion'\nusage: go mod graph \[-go=version\]\nRun ''go help mod graph'' for details.$'


-- go.mod --
// Module m indirectly imports a package from
// example.com/retract/incompatible. Its selected version of
// that module is lower under Go 1.17 semantics than under Go 1.16.
module example.com/m

go 1.17

replace (
	example.net/lazy v0.1.0 => ./lazy
	example.net/requireincompatible v0.1.0 => ./requireincompatible
)

require (
	example.com/retract/incompatible v1.0.0 // indirect
	example.net/lazy v0.1.0
)
-- lazy/go.mod --
// Module lazy requires example.com/retract/incompatible v1.0.0.
//
// When viewed from the outside it also has a transitive dependency
// on v2.0.0+incompatible, but in lazy mode that transitive dependency
// is pruned out.
module example.net/lazy

go 1.17

exclude example.com/retract/incompatible v2.0.0+incompatible

require (
	example.com/retract/incompatible v1.0.0
	example.net/requireincompatible v0.1.0
)
-- requireincompatible/go.mod --
module example.net/requireincompatible

go 1.15

require example.com/retract/incompatible v2.0.0+incompatible