1 [short] skip
2
3 # Install an echo command because Windows doesn't have it.
4 env GOBIN=$WORK/tmp/bin
5 go install echo.go
6 env PATH=$GOBIN${:}$PATH
7
8 # Test go generate handles a simple command
9 go generate ./generate/simple.go
10 stdout 'Success'
11
12 # Test go generate handles a command alias
13 go generate './generate/alias.go'
14 stdout 'Now is the time for all good men'
15
16 # Test go generate's variable substitution
17 go generate './generate/substitution.go'
18 stdout $GOARCH' substitution.go:7 pabc xyzp/substitution.go/123'
19
20 # Test go generate's run and skip flags
21 go generate -run y.s './generate/flag.go'
22 stdout 'yes' # flag.go should select yes
23 ! stdout 'no' # flag.go should not select no
24
25 go generate -skip th..sand './generate/flag.go'
26 stdout 'yes' # flag.go should select yes
27 ! stdout 'no' # flag.go should not select no
28
29 go generate -run . -skip th..sand './generate/flag.go'
30 stdout 'yes' # flag.go should select yes
31 ! stdout 'no' # flag.go should not select no
32
33 # Test go generate provides the right "$GOPACKAGE" name in an x_test
34 go generate './generate/env_test.go'
35 stdout 'main_test'
36
37 # Test go generate provides the right "$PWD"
38 go generate './generate/env_pwd.go'
39 stdout $WORK'[/\\]gopath[/\\]src[/\\]generate'
40
41 -- echo.go --
42 package main
43
44 import (
45 "fmt"
46 "os"
47 "strings"
48 )
49
50 func main() {
51 fmt.Println(strings.Join(os.Args[1:], " "))
52 fmt.Println()
53 }
54 -- generate/simple.go --
55 // Copyright 2014 The Go Authors. All rights reserved.
56 // Use of this source code is governed by a BSD-style
57 // license that can be found in the LICENSE file.
58
59 // Simple test for go generate.
60
61 // We include a build tag that go generate should ignore.
62
63 // +build ignore
64
65 //go:generate echo Success
66
67 package p
68 -- generate/alias.go --
69 // Copyright 2014 The Go Authors. All rights reserved.
70 // Use of this source code is governed by a BSD-style
71 // license that can be found in the LICENSE file.
72
73 // Test that go generate handles command aliases.
74
75 //go:generate -command run echo Now is the time
76 //go:generate run for all good men
77
78 package p
79 -- generate/substitution.go --
80 // Copyright 2014 The Go Authors. All rights reserved.
81 // Use of this source code is governed by a BSD-style
82 // license that can be found in the LICENSE file.
83
84 // Test go generate variable substitution.
85
86 //go:generate echo $GOARCH $GOFILE:$GOLINE ${GOPACKAGE}abc xyz$GOPACKAGE/$GOFILE/123
87
88 package p
89 -- generate/flag.go --
90 // Copyright 2015 The Go Authors. All rights reserved.
91 // Use of this source code is governed by a BSD-style
92 // license that can be found in the LICENSE file.
93
94 // Test -run flag
95
96 //go:generate echo oh yes my man
97 //go:generate echo no, no, a thousand times no
98
99 package p
100 -- generate/env_test.go --
101 package main_test
102
103 //go:generate echo $GOPACKAGE
104 -- generate/env_pwd.go --
105 package p
106
107 //go:generate echo $PWD
108
View as plain text