Skip to content

Commit c6d281e

Browse files
committed
cmd/go: convert some tests in vendor_test to the script framework
Part of converting all tests to script framework to improve test parallelism. Updates #36320 Updates #17751 Change-Id: I601e0fcee32b8c5bf2107b520d1dfbe12a19ad3f Reviewed-on: https://go-review.googlesource.com/c/go/+/213223 Reviewed-by: Jay Conrod <jayconrod@google.com>
1 parent 2cfc5e2 commit c6d281e

37 files changed

+476
-428
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Build
2+
go build vend/x
3+
! stdout .
4+
! stderr .
5+
6+
-- vend/dir1/dir1.go --
7+
package dir1
8+
-- vend/subdir/bad.go --
9+
package subdir
10+
11+
import _ "r"
12+
-- vend/subdir/good.go --
13+
package subdir
14+
15+
import _ "p"
16+
-- vend/vendor/p/p.go --
17+
package p
18+
-- vend/vendor/q/q.go --
19+
package q
20+
-- vend/vendor/vend/dir1/dir2/dir2.go --
21+
package dir2
22+
-- vend/x/invalid/invalid.go --
23+
package invalid
24+
25+
import "vend/x/invalid/vendor/foo"
26+
-- vend/x/vendor/p/p/p.go --
27+
package p
28+
29+
import _ "notfound"
30+
-- vend/x/vendor/p/p.go --
31+
package p
32+
-- vend/x/vendor/r/r.go --
33+
package r
34+
-- vend/x/x.go --
35+
package x
36+
37+
import _ "p"
38+
import _ "q"
39+
import _ "r"
40+
import _ "vend/dir1" // not vendored
41+
import _ "vend/dir1/dir2" // vendored
+94
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
[short] skip
2+
3+
cd $GOPATH/src/v
4+
go run m.go
5+
go test
6+
go list -f '{{.Imports}}'
7+
stdout 'v/vendor/vendor.org/p'
8+
go list -f '{{.TestImports}}'
9+
stdout 'v/vendor/vendor.org/p'
10+
go get -d
11+
go get -t -d
12+
13+
[!net] stop
14+
[!exec:git] stop
15+
16+
cd $GOPATH/src
17+
18+
# Update
19+
go get 'github.com/rsc/go-get-issue-11864'
20+
go get -u 'github.com/rsc/go-get-issue-11864'
21+
exists github.com/rsc/go-get-issue-11864/vendor
22+
23+
# get -u
24+
rm $GOPATH
25+
mkdir $GOPATH/src
26+
go get -u 'github.com/rsc/go-get-issue-11864'
27+
exists github.com/rsc/go-get-issue-11864/vendor
28+
29+
# get -t -u
30+
rm $GOPATH
31+
mkdir $GOPATH/src
32+
go get -t -u 'github.com/rsc/go-get-issue-11864/...'
33+
exists github.com/rsc/go-get-issue-11864/vendor
34+
35+
# Submodules
36+
rm $GOPATH
37+
mkdir $GOPATH/src
38+
go get -d 'github.com/rsc/go-get-issue-12612'
39+
go get -u -d 'github.com/rsc/go-get-issue-12612'
40+
exists github.com/rsc/go-get-issue-12612/vendor/golang.org/x/crypto/.git
41+
42+
# Bad vendor (bad/imp)
43+
rm $GOPATH
44+
mkdir $GOPATH/src
45+
! go get -t -u 'github.com/rsc/go-get-issue-18219/bad/imp'
46+
stderr 'must be imported as'
47+
! exists github.com/rsc/go-get-issue-11864/vendor
48+
49+
# Bad vendor (bad/imp2)
50+
rm $GOPATH
51+
mkdir $GOPATH/src
52+
! go get -t -u 'github.com/rsc/go-get-issue-18219/bad/imp2'
53+
stderr 'must be imported as'
54+
! exists github.com/rsc/go-get-issue-11864/vendor
55+
56+
# Bad vendor (bad/imp3)
57+
rm $GOPATH
58+
mkdir $GOPATH/src
59+
! go get -t -u 'github.com/rsc/go-get-issue-18219/bad/imp3'
60+
stderr 'must be imported as'
61+
! exists github.com/rsc/go-get-issue-11864/vendor
62+
63+
# Bad vendor (bad/...)
64+
rm $GOPATH
65+
mkdir $GOPATH/src
66+
! go get -t -u 'github.com/rsc/go-get-issue-18219/bad/...'
67+
stderr 'must be imported as'
68+
! exists github.com/rsc/go-get-issue-11864/vendor
69+
70+
-- v/m.go --
71+
package main
72+
73+
import (
74+
"fmt"
75+
"vendor.org/p"
76+
)
77+
78+
func main() {
79+
fmt.Println(p.C)
80+
}
81+
-- v/m_test.go --
82+
package main
83+
import (
84+
"fmt"
85+
"testing"
86+
"vendor.org/p"
87+
)
88+
89+
func TestNothing(t *testing.T) {
90+
fmt.Println(p.C)
91+
}
92+
-- v/vendor/vendor.org/p/p.go --
93+
package p
94+
const C = 1
+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Run
2+
cd vend/hello
3+
go run hello.go
4+
stdout 'hello, world'
5+
6+
-- vend/hello/hello.go --
7+
package main
8+
9+
import (
10+
"fmt"
11+
"strings" // really ../vendor/strings
12+
)
13+
14+
func main() {
15+
fmt.Printf("%s\n", strings.Msg)
16+
}
17+
-- vend/hello/hello_test.go --
18+
package main
19+
20+
import (
21+
"strings" // really ../vendor/strings
22+
"testing"
23+
)
24+
25+
func TestMsgInternal(t *testing.T) {
26+
if strings.Msg != "hello, world" {
27+
t.Fatalf("unexpected msg: %v", strings.Msg)
28+
}
29+
}
30+
-- vend/vendor/strings/msg.go --
31+
package strings
32+
33+
var Msg = "hello, world"
+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# Test
2+
cd vend/hello
3+
go test -v
4+
stdout TestMsgInternal
5+
stdout TestMsgExternal
6+
7+
-- vend/hello/hello.go --
8+
package main
9+
10+
import (
11+
"fmt"
12+
"strings" // really ../vendor/strings
13+
)
14+
15+
func main() {
16+
fmt.Printf("%s\n", strings.Msg)
17+
}
18+
-- vend/hello/hello_test.go --
19+
package main
20+
21+
import (
22+
"strings" // really ../vendor/strings
23+
"testing"
24+
)
25+
26+
func TestMsgInternal(t *testing.T) {
27+
if strings.Msg != "hello, world" {
28+
t.Fatalf("unexpected msg: %v", strings.Msg)
29+
}
30+
}
31+
-- vend/hello/hellox_test.go --
32+
package main_test
33+
34+
import (
35+
"strings" // really ../vendor/strings
36+
"testing"
37+
)
38+
39+
func TestMsgExternal(t *testing.T) {
40+
if strings.Msg != "hello, world" {
41+
t.Fatalf("unexpected msg: %v", strings.Msg)
42+
}
43+
}
44+
-- vend/vendor/strings/msg.go --
45+
package strings
46+
47+
var Msg = "hello, world"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
[!windows] [short] stop 'this test only applies to Windows'
2+
3+
go build run_go.go
4+
exec ./run_go$GOEXE $GOPATH $GOPATH/src/vend/hello
5+
stdout 'hello, world'
6+
7+
-- run_go.go --
8+
package main
9+
10+
import (
11+
"fmt"
12+
"os"
13+
"os/exec"
14+
"path/filepath"
15+
"strings"
16+
)
17+
18+
func changeVolume(s string, f func(s string) string) string {
19+
vol := filepath.VolumeName(s)
20+
return f(vol) + s[len(vol):]
21+
}
22+
23+
func main() {
24+
gopath := changeVolume(os.Args[1], strings.ToLower)
25+
dir := changeVolume(os.Args[2], strings.ToUpper)
26+
cmd := exec.Command("go", "run", "hello.go")
27+
cmd.Dir = dir
28+
cmd.Env = append(os.Environ(), "GOPATH="+gopath)
29+
cmd.Stdout = os.Stdout
30+
cmd.Stderr = os.Stderr
31+
if err := cmd.Run(); err != nil {
32+
fmt.Fprintln(os.Stderr, err)
33+
os.Exit(1)
34+
}
35+
}
36+
37+
-- vend/hello/hello.go --
38+
package main
39+
40+
import (
41+
"fmt"
42+
"strings" // really ../vendor/strings
43+
)
44+
45+
func main() {
46+
fmt.Printf("%s\n", strings.Msg)
47+
}
48+
-- vend/vendor/strings/msg.go --
49+
package strings
50+
51+
var Msg = "hello, world"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
# Imports
2+
go list -f '{{.ImportPath}} {{.Imports}}' 'vend/...' 'vend/vendor/...' 'vend/x/vendor/...'
3+
cmp stdout want_vendor_imports.txt
4+
5+
-- want_vendor_imports.txt --
6+
vend [vend/vendor/p r]
7+
vend/dir1 []
8+
vend/hello [fmt vend/vendor/strings]
9+
vend/subdir [vend/vendor/p r]
10+
vend/x [vend/x/vendor/p vend/vendor/q vend/x/vendor/r vend/dir1 vend/vendor/vend/dir1/dir2]
11+
vend/x/invalid [vend/x/invalid/vendor/foo]
12+
vend/vendor/p []
13+
vend/vendor/q []
14+
vend/vendor/strings []
15+
vend/vendor/vend/dir1/dir2 []
16+
vend/x/vendor/p []
17+
vend/x/vendor/p/p [notfound]
18+
vend/x/vendor/r []
19+
-- vend/bad.go --
20+
package vend
21+
22+
import _ "r"
23+
-- vend/dir1/dir1.go --
24+
package dir1
25+
-- vend/good.go --
26+
package vend
27+
28+
import _ "p"
29+
-- vend/hello/hello.go --
30+
package main
31+
32+
import (
33+
"fmt"
34+
"strings" // really ../vendor/strings
35+
)
36+
37+
func main() {
38+
fmt.Printf("%s\n", strings.Msg)
39+
}
40+
-- vend/hello/hello_test.go --
41+
package main
42+
43+
import (
44+
"strings" // really ../vendor/strings
45+
"testing"
46+
)
47+
48+
func TestMsgInternal(t *testing.T) {
49+
if strings.Msg != "hello, world" {
50+
t.Fatalf("unexpected msg: %v", strings.Msg)
51+
}
52+
}
53+
-- vend/hello/hellox_test.go --
54+
package main_test
55+
56+
import (
57+
"strings" // really ../vendor/strings
58+
"testing"
59+
)
60+
61+
func TestMsgExternal(t *testing.T) {
62+
if strings.Msg != "hello, world" {
63+
t.Fatalf("unexpected msg: %v", strings.Msg)
64+
}
65+
}
66+
-- vend/subdir/bad.go --
67+
package subdir
68+
69+
import _ "r"
70+
-- vend/subdir/good.go --
71+
package subdir
72+
73+
import _ "p"
74+
-- vend/vendor/p/p.go --
75+
package p
76+
-- vend/vendor/q/q.go --
77+
package q
78+
-- vend/vendor/strings/msg.go --
79+
package strings
80+
81+
var Msg = "hello, world"
82+
-- vend/vendor/vend/dir1/dir2/dir2.go --
83+
package dir2
84+
-- vend/x/invalid/invalid.go --
85+
package invalid
86+
87+
import "vend/x/invalid/vendor/foo"
88+
-- vend/x/vendor/p/p/p.go --
89+
package p
90+
91+
import _ "notfound"
92+
-- vend/x/vendor/p/p.go --
93+
package p
94+
-- vend/x/vendor/r/r.go --
95+
package r
96+
-- vend/x/x.go --
97+
package x
98+
99+
import _ "p"
100+
import _ "q"
101+
import _ "r"
102+
import _ "vend/dir1" // not vendored
103+
import _ "vend/dir1/dir2" // vendored
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Missing package error message
2+
! go build vend/x/vendor/p/p
3+
4+
-- vend/x/vendor/p/p/p.go --
5+
package p
6+
7+
import _ "notfound"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Wrong import path
2+
! go build vend/x/invalid
3+
stderr 'must be imported as foo'
4+
5+
-- vend/x/invalid/invalid.go --
6+
package invalid
7+
8+
import "vend/x/invalid/vendor/foo"
9+

0 commit comments

Comments
 (0)