1 cd foo
2
3 # Testing an explicit source file should use the same import visibility as the
4 # package in the same directory.
5 go list -test -deps
6 go list -test -deps foo_test.go
7
8 # If the file is inside the main module's vendor directory, it should have
9 # visibility based on the vendor-relative import path.
10 mkdir vendor/example.com/foo
11 cp foo_test.go vendor/example.com/foo
12 go list -test -deps vendor/example.com/foo/foo_test.go
13
14 # If the file is outside the main module entirely, it should be treated as outside.
15 cp foo_test.go ../foo_test.go
16 ! go list -test -deps ../foo_test.go
17 stderr 'use of internal package'
18
19 -- foo/go.mod --
20 module example.com/foo
21 go 1.12
22 require example.com/internal v0.0.0
23 replace example.com/internal => ../internal
24
25 -- foo/internal.go --
26 package foo
27 import _ "example.com/internal"
28
29 -- foo/foo_test.go --
30 package foo_test
31
32 import (
33 "testing"
34 "example.com/internal"
35 )
36
37 func TestHacksEnabled(t *testing.T) {
38 if !internal.Hacks {
39 t.Fatal("hacks not enabled")
40 }
41 }
42
43 -- internal/go.mod --
44 module example.com/internal
45
46 -- internal/internal.go --
47 package internal
48 const Hacks = true
49
View as plain text