blob: 7ee1f83471c631f4b5f41bab1105bdefa76c5973 (
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
107
108
109
110
111
112
113
114
115
116
117
|
env GO111MODULE=off # Relative imports only work in GOPATH mode.
[short] skip
# Imports should be resolved relative to the source file.
go build testdata/local/easy.go
exec ./easy$GOEXE
stdout '^easysub\.Hello'
# Ignored files should be able to import the package built from
# non-ignored files in the same directory.
go build -o easysub$GOEXE testdata/local/easysub/main.go
exec ./easysub$GOEXE
stdout '^easysub\.Hello'
# Files in relative-imported packages should be able to
# use relative imports themselves.
go build testdata/local/hard.go
exec ./hard$GOEXE
stdout '^sub\.Hello'
# Explicit source files listed on the command line should not install without
# GOBIN set, since individual source files aren't part of the containing GOPATH.
! go install testdata/local/easy.go
stderr '^go install: no install location for \.go files listed on command line \(GOBIN not set\)$'
[windows] stop # Windows does not allow the ridiculous directory name we're about to use.
env BAD_DIR_NAME='#$%:, &()*;<=>?\^{}'
mkdir -p testdata/$BAD_DIR_NAME/easysub
mkdir -p testdata/$BAD_DIR_NAME/sub/sub
cp testdata/local/easy.go testdata/$BAD_DIR_NAME/easy.go
cp testdata/local/easysub/easysub.go testdata/$BAD_DIR_NAME/easysub/easysub.go
cp testdata/local/easysub/main.go testdata/$BAD_DIR_NAME/easysub/main.go
cp testdata/local/hard.go testdata/$BAD_DIR_NAME/hard.go
cp testdata/local/sub/sub.go testdata/$BAD_DIR_NAME/sub/sub.go
cp testdata/local/sub/sub/subsub.go testdata/$BAD_DIR_NAME/sub/sub/subsub.go
# Imports should be resolved relative to the source file.
go build testdata/$BAD_DIR_NAME/easy.go
exec ./easy$GOEXE
stdout '^easysub\.Hello'
# Ignored files should be able to import the package built from
# non-ignored files in the same directory.
go build -o easysub$GOEXE testdata/$BAD_DIR_NAME/easysub/main.go
exec ./easysub$GOEXE
stdout '^easysub\.Hello'
# Files in relative-imported packages should be able to
# use relative imports themselves.
go build testdata/$BAD_DIR_NAME/hard.go
exec ./hard$GOEXE
stdout '^sub\.Hello'
# Explicit source files listed on the command line should not install without
# GOBIN set, since individual source files aren't part of the containing GOPATH.
! go install testdata/$BAD_DIR_NAME/easy.go
stderr '^go install: no install location for \.go files listed on command line \(GOBIN not set\)$'
-- testdata/local/easy.go --
package main
import "./easysub"
func main() {
easysub.Hello()
}
-- testdata/local/easysub/easysub.go --
package easysub
import "fmt"
func Hello() {
fmt.Println("easysub.Hello")
}
-- testdata/local/easysub/main.go --
// +build ignore
package main
import "."
func main() {
easysub.Hello()
}
-- testdata/local/hard.go --
package main
import "./sub"
func main() {
sub.Hello()
}
-- testdata/local/sub/sub.go --
package sub
import (
"fmt"
subsub "./sub"
)
func Hello() {
fmt.Println("sub.Hello")
subsub.Hello()
}
-- testdata/local/sub/sub/subsub.go --
package subsub
import "fmt"
func Hello() {
fmt.Println("subsub.Hello")
}
|