1 env GO111MODULE=off
2 env GODEBUG=gocachetest=1
3
4 [!compiler:gc] skip
5 [short] skip # clears cache, rebuilds too much
6
7 # Set up fresh GOCACHE.
8 env GOCACHE=$WORK/gocache
9 mkdir $GOCACHE
10
11 # Building a trivial non-main package should run compiler the first time.
12 go build -x -gcflags=-m lib.go
13 stderr 'compile( |\.exe"?)'
14 stderr 'lib.go:2.* can inline f'
15
16 # ... but not the second, even though it still prints the compiler output.
17 go build -x -gcflags=-m lib.go
18 ! stderr 'compile( |\.exe"?)'
19 stderr 'lib.go:2.* can inline f'
20
21 # Building a trivial main package should run the compiler and linker the first time.
22 go build -x -gcflags=-m -ldflags='-v -w' main.go
23 stderr 'compile( |\.exe"?)'
24 stderr 'main.go:2.* can inline main' # from compiler
25 stderr 'link(\.exe"?)? -'
26 stderr '\d+ symbols' # from linker
27
28 # ... but not the second, even though it still prints the compiler and linker output.
29 go build -x -gcflags=-m -ldflags='-v -w' main.go
30 ! stderr 'compile( |\.exe"?)'
31 stderr 'main.go:2.* can inline main' # from compiler
32 ! stderr 'link(\.exe"?)? -'
33 stderr '\d+ symbols' # from linker
34
35 # Running a test should run the compiler, linker, and the test the first time.
36 go test -v -x -gcflags=-m -ldflags=-v p
37 stderr 'compile( |\.exe"?)'
38 stderr 'p_test.go:.*can inline Test' # from compile of p_test
39 stderr 'testmain\.go:.*inlin' # from compile of testmain
40 stderr 'link(\.exe"?)? -'
41 stderr '\d+ symbols' # from linker
42 stderr 'p\.test( |\.exe"?)'
43 stdout 'TEST' # from test
44
45 # ... but not the second, even though it still prints the compiler, linker, and test output.
46 go test -v -x -gcflags=-m -ldflags=-v p
47 ! stderr 'compile( |\.exe"?)'
48 stderr 'p_test.go:.*can inline Test' # from compile of p_test
49 stderr 'testmain\.go:.*inlin' # from compile of testmain
50 ! stderr 'link(\.exe"?)? -'
51 stderr '\d+ symbols' # from linker
52 ! stderr 'p\.test( |\.exe"?)'
53 stdout 'TEST' # from test
54
55
56 -- lib.go --
57 package p
58 func f(x *int) *int { return x }
59
60 -- main.go --
61 package main
62 func main() {}
63
64 -- p/p_test.go --
65 package p
66 import "testing"
67 func Test(t *testing.T) {println("TEST")}
68
View as plain text