@@ -13,50 +13,27 @@ import (
13
13
"io/ioutil"
14
14
"os"
15
15
"os/exec"
16
- "runtime"
17
16
"testing"
18
17
)
19
18
20
- const (
21
- testbin = "testgetgo"
22
- )
23
-
24
- var (
25
- exeSuffix string // ".exe" on Windows
26
- )
27
-
28
- func init () {
29
- if runtime .GOOS == "windows" {
30
- exeSuffix = ".exe"
19
+ func TestMain (m * testing.M ) {
20
+ if os .Getenv ("GO_GETGO_TEST_IS_GETGO" ) != "" {
21
+ main ()
22
+ os .Exit (0 )
31
23
}
32
- }
33
24
34
- // TestMain creates a getgo command for testing purposes and
35
- // deletes it after the tests have been run.
36
- func TestMain (m * testing.M ) {
37
25
if os .Getenv ("GOGET_INTEGRATION" ) == "" {
38
26
fmt .Fprintln (os .Stderr , "main_test: Skipping integration tests with GOGET_INTEGRATION unset" )
39
27
return
40
28
}
41
29
42
- args := []string {"build" , "-tags" , testbin , "-o" , testbin + exeSuffix }
43
- out , err := exec .Command ("go" , args ... ).CombinedOutput ()
44
- if err != nil {
45
- fmt .Fprintf (os .Stderr , "building %s failed: %v\n %s" , testbin , err , out )
46
- os .Exit (2 )
47
- }
48
-
49
30
// Don't let these environment variables confuse the test.
50
31
os .Unsetenv ("GOBIN" )
51
32
os .Unsetenv ("GOPATH" )
52
33
os .Unsetenv ("GIT_ALLOW_PROTOCOL" )
53
34
os .Unsetenv ("PATH" )
54
35
55
- r := m .Run ()
56
-
57
- os .Remove (testbin + exeSuffix )
58
-
59
- os .Exit (r )
36
+ os .Exit (m .Run ())
60
37
}
61
38
62
39
func createTmpHome (t * testing.T ) string {
@@ -72,12 +49,18 @@ func createTmpHome(t *testing.T) string {
72
49
// doRun runs the test getgo command, recording stdout and stderr and
73
50
// returning exit status.
74
51
func doRun (t * testing.T , args ... string ) error {
52
+ exe , err := os .Executable ()
53
+ if err != nil {
54
+ t .Fatal (err )
55
+ }
56
+ t .Helper ()
57
+
58
+ t .Logf ("running getgo %v" , args )
75
59
var stdout , stderr bytes.Buffer
76
- t .Logf ("running %s %v" , testbin , args )
77
- cmd := exec .Command ("./" + testbin + exeSuffix , args ... )
60
+ cmd := exec .Command (exe , args ... )
78
61
cmd .Stdout = & stdout
79
62
cmd .Stderr = & stderr
80
- cmd .Env = os .Environ ()
63
+ cmd .Env = append ( os .Environ (), "GO_GETGO_TEST_IS_GETGO=1" )
81
64
status := cmd .Run ()
82
65
if stdout .Len () > 0 {
83
66
t .Log ("standard output:" )
0 commit comments