aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/go/testdata/script/mod_tagged_import_cycle.txt
blob: 0491acb8723a55093a3c84b8f23c16e806d4445a (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
102
103
104
105
106
# Because 'go mod' subcommands ignore build constraints, they can encounter
# package-import cycles that are not possible in an ordinary build. This test
# verifies that such cycles are handled even when they cross module boundaries.

# First, verify that the import graph depends on build tags as expected.
go list -deps example.com/left
stdout '^example.com/right$'
go list -deps example.com/right
! stdout left

env GOFLAGS=-tags=mirror
go list -deps example.com/left
! stdout right
go list -deps example.com/right
stdout '^example.com/left$'
env GOFLAGS=''

# 'go mod why' should be agnostic to build tags.
go mod why example.com/left
stdout '^example.com/chiral$\n^example.com/left$'
go mod why example.com/right
stdout '^example.com/chiral$\n^example.com/right$'

env GOFLAGS='-tags=mirror'
go mod why example.com/left
stdout '^example.com/chiral$\n^example.com/left$'
go mod why example.com/right
stdout '^example.com/chiral$\n^example.com/right$'
env GOFLAGS=''

# 'go mod tidy' should successfully handle the cycle.
env GOFLAGS=-mod=readonly
go mod tidy

# 'go mod vendor' should copy in both packages without crashing.
go mod vendor
exists vendor/example.com/left/default.go
exists vendor/example.com/left/mirror.go
exists vendor/example.com/right/default.go
exists vendor/example.com/right/mirror.go

-- go.mod --
module example.com/chiral

go 1.14

require (
	example.com/left v0.1.0
	example.com/right v0.1.0
)

replace (
	example.com/left => ./left
	example.com/right => ./right
)
-- chiral.go --
// Package chiral imports packages in an order that depends on build tags.
package chiral
-- default.go --
// +build !mirror

package chiral

import _ "example.com/left"
-- mirror.go --
// +build mirror

package chiral

import _ "example.com/right"
-- left/go.mod --
module example.com/left

go 1.14

require example.com/right v0.1.0

replace example.com/right v0.1.0 => ../right
-- left/default.go --
// +build !mirror

package left

import _ "example.com/right"
-- left/mirror.go --
// +build mirror

package left
-- right/go.mod --
module example.com/right

go 1.14

require example.com/left v0.1.0

replace example.com/left v0.1.0 => ../left
-- right/default.go --
// +build !mirror

package right
-- right/mirror.go --
// +build mirror

package right

import _ "example.com/left"