aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/go/testdata/script/mod_internal.txt
blob: 687269d18f6f33e05ce4572423d2d7cfa4efb8be (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
env GO111MODULE=on
[short] skip

# golang.org/x/internal should be importable from other golang.org/x modules.
go mod edit -module=golang.org/x/anything
go get -d .

# ...and their tests...
go test
stdout PASS

# ...but that should not leak into other modules.
go get -d ./baddep
! go build ./baddep
stderr golang.org[/\\]notx[/\\]useinternal
stderr 'use of internal package golang.org/x/.* not allowed'

# Internal packages in the standard library should not leak into modules.
go get -d ./fromstd
! go build ./fromstd
stderr 'use of internal package internal/testenv not allowed'

# Dependencies should be able to use their own internal modules...
go mod edit -module=golang.org/notx
go get -d ./throughdep

# ... but other modules should not, even if they have transitive dependencies.
go get -d .
! go build .
stderr 'use of internal package golang.org/x/.* not allowed'

# And transitive dependencies still should not leak.
go get -d ./baddep
! go build ./baddep
stderr golang.org[/\\]notx[/\\]useinternal
stderr 'use of internal package golang.org/x/.* not allowed'

# Replacing an internal module should keep it internal to the same paths.
go mod edit -module=golang.org/notx
go mod edit -replace golang.org/x/internal=./replace/golang.org/notx/internal
go get -d ./throughdep

go get -d ./baddep
! go build ./baddep
stderr golang.org[/\\]notx[/\\]useinternal
stderr 'use of internal package golang.org/x/.* not allowed'

go mod edit -replace golang.org/x/internal=./vendor/golang.org/x/internal
go get -d ./throughdep

go get -d ./baddep
! go build ./baddep
stderr golang.org[/\\]notx[/\\]useinternal
stderr 'use of internal package golang.org/x/.* not allowed'

-- go.mod --
module TBD
go 1.12
-- useinternal.go --
package useinternal
import _ "golang.org/x/internal/subtle"

-- useinternal_test.go --
package useinternal_test
import (
	"testing"
	_ "golang.org/x/internal/subtle"
)

func Test(*testing.T) {}

-- throughdep/useinternal.go --
package throughdep
import _ "golang.org/x/useinternal"

-- baddep/useinternal.go --
package baddep
import _ "golang.org/notx/useinternal"

-- fromstd/useinternal.go --
package fromstd
import _ "internal/testenv"

-- replace/golang.org/notx/internal/go.mod --
module golang.org/x/internal

-- replace/golang.org/notx/internal/subtle/subtle.go --
package subtle
// Ha ha! Nothing here!

-- vendor/golang.org/x/internal/go.mod --
module golang.org/x/internal

-- vendor/golang.org/x/internal/subtle/subtle.go --
package subtle
// Ha ha! Nothing here!