...
1env GO111MODULE=off # Relative imports only work in GOPATH mode.
2
3[short] skip
4
5# Imports should be resolved relative to the source file.
6go build testdata/local/easy.go
7exec ./easy$GOEXE
8stdout '^easysub\.Hello'
9
10# Ignored files should be able to import the package built from
11# non-ignored files in the same directory.
12go build -o easysub$GOEXE testdata/local/easysub/main.go
13exec ./easysub$GOEXE
14stdout '^easysub\.Hello'
15
16# Files in relative-imported packages should be able to
17# use relative imports themselves.
18go build testdata/local/hard.go
19exec ./hard$GOEXE
20stdout '^sub\.Hello'
21
22# Explicit source files listed on the command line should not install without
23# GOBIN set, since individual source files aren't part of the containing GOPATH.
24! go install testdata/local/easy.go
25stderr '^go: no install location for \.go files listed on command line \(GOBIN not set\)$'
26
27[GOOS:windows] stop # Windows does not allow the ridiculous directory name we're about to use.
28
29env BAD_DIR_NAME='#$%:, &()*;<=>?\^{}'
30
31mkdir -p testdata/$BAD_DIR_NAME/easysub
32mkdir -p testdata/$BAD_DIR_NAME/sub/sub
33
34cp testdata/local/easy.go testdata/$BAD_DIR_NAME/easy.go
35cp testdata/local/easysub/easysub.go testdata/$BAD_DIR_NAME/easysub/easysub.go
36cp testdata/local/easysub/main.go testdata/$BAD_DIR_NAME/easysub/main.go
37cp testdata/local/hard.go testdata/$BAD_DIR_NAME/hard.go
38cp testdata/local/sub/sub.go testdata/$BAD_DIR_NAME/sub/sub.go
39cp testdata/local/sub/sub/subsub.go testdata/$BAD_DIR_NAME/sub/sub/subsub.go
40
41# Imports should be resolved relative to the source file.
42go build testdata/$BAD_DIR_NAME/easy.go
43exec ./easy$GOEXE
44stdout '^easysub\.Hello'
45
46# Ignored files should be able to import the package built from
47# non-ignored files in the same directory.
48go build -o easysub$GOEXE testdata/$BAD_DIR_NAME/easysub/main.go
49exec ./easysub$GOEXE
50stdout '^easysub\.Hello'
51
52# Files in relative-imported packages should be able to
53# use relative imports themselves.
54go build testdata/$BAD_DIR_NAME/hard.go
55exec ./hard$GOEXE
56stdout '^sub\.Hello'
57
58# Explicit source files listed on the command line should not install without
59# GOBIN set, since individual source files aren't part of the containing GOPATH.
60! go install testdata/$BAD_DIR_NAME/easy.go
61stderr '^go: no install location for \.go files listed on command line \(GOBIN not set\)$'
62
63-- testdata/local/easy.go --
64package main
65
66import "./easysub"
67
68func main() {
69 easysub.Hello()
70}
71-- testdata/local/easysub/easysub.go --
72package easysub
73
74import "fmt"
75
76func Hello() {
77 fmt.Println("easysub.Hello")
78}
79-- testdata/local/easysub/main.go --
80// +build ignore
81
82package main
83
84import "."
85
86func main() {
87 easysub.Hello()
88}
89-- testdata/local/hard.go --
90package main
91
92import "./sub"
93
94func main() {
95 sub.Hello()
96}
97-- testdata/local/sub/sub.go --
98package sub
99
100import (
101 "fmt"
102
103 subsub "./sub"
104)
105
106func Hello() {
107 fmt.Println("sub.Hello")
108 subsub.Hello()
109}
110-- testdata/local/sub/sub/subsub.go --
111package subsub
112
113import "fmt"
114
115func Hello() {
116 fmt.Println("subsub.Hello")
117}
View as plain text