Skip to content

Commit fcda964

Browse files
committed
Fix import paths for tests.
Vendor an importable copy of internal/testenv.
1 parent 1955044 commit fcda964

File tree

5 files changed

+109
-4
lines changed

5 files changed

+109
-4
lines changed

cmd/go/go_test.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010
"fmt"
1111
"go/build"
1212
"go/format"
13-
"internal/testenv"
1413
"io"
1514
"io/ioutil"
1615
"os"
@@ -22,6 +21,8 @@ import (
2221
"strings"
2322
"testing"
2423
"time"
24+
25+
"github.com/gophergala2016/cmd-go-js/internal/testenv"
2526
)
2627

2728
var (

cmd/go/note_test.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@
55
package main_test
66

77
import (
8-
main "cmd/go"
98
"runtime"
109
"testing"
10+
11+
main "github.com/gophergala2016/cmd-go-js/cmd/go"
1112
)
1213

1314
func TestNoteReading(t *testing.T) {

cmd/go/vcs_test.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@
55
package main
66

77
import (
8-
"internal/testenv"
98
"testing"
9+
10+
"github.com/gophergala2016/cmd-go-js/internal/testenv"
1011
)
1112

1213
// Test that RepoRootForImportPath creates the correct RepoRoot for a given importPath.

cmd/go/vendor_test.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,12 @@ package main_test
99
import (
1010
"bytes"
1111
"fmt"
12-
"internal/testenv"
1312
"path/filepath"
1413
"regexp"
1514
"strings"
1615
"testing"
16+
17+
"github.com/gophergala2016/cmd-go-js/internal/testenv"
1718
)
1819

1920
func TestVendorImports(t *testing.T) {

internal/testenv/testenv.go

+101
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
// Copyright 2015 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
// Package testenv provides information about what functionality
6+
// is available in different testing environments run by the Go team.
7+
//
8+
// It is an internal package because these details are specific
9+
// to the Go team's test setup (on build.golang.org) and not
10+
// fundamental to tests in general.
11+
package testenv
12+
13+
import (
14+
"os"
15+
"runtime"
16+
"strings"
17+
"testing"
18+
)
19+
20+
// Builder reports the name of the builder running this test
21+
// (for example, "linux-amd64" or "windows-386-gce").
22+
// If the test is not running on the build infrastructure,
23+
// Builder returns the empty string.
24+
func Builder() string {
25+
return os.Getenv("GO_BUILDER_NAME")
26+
}
27+
28+
// HasGoBuild reports whether the current system can build programs with ``go build''
29+
// and then run them with os.StartProcess or exec.Command.
30+
func HasGoBuild() bool {
31+
switch runtime.GOOS {
32+
case "android", "nacl":
33+
return false
34+
case "darwin":
35+
if strings.HasPrefix(runtime.GOARCH, "arm") {
36+
return false
37+
}
38+
}
39+
return true
40+
}
41+
42+
// MustHaveGoBuild checks that the current system can build programs with ``go build''
43+
// and then run them with os.StartProcess or exec.Command.
44+
// If not, MustHaveGoBuild calls t.Skip with an explanation.
45+
func MustHaveGoBuild(t *testing.T) {
46+
if !HasGoBuild() {
47+
t.Skipf("skipping test: 'go build' not available on %s/%s", runtime.GOOS, runtime.GOARCH)
48+
}
49+
}
50+
51+
// HasGoRun reports whether the current system can run programs with ``go run.''
52+
func HasGoRun() bool {
53+
// For now, having go run and having go build are the same.
54+
return HasGoBuild()
55+
}
56+
57+
// MustHaveGoRun checks that the current system can run programs with ``go run.''
58+
// If not, MustHaveGoRun calls t.Skip with an explanation.
59+
func MustHaveGoRun(t *testing.T) {
60+
if !HasGoRun() {
61+
t.Skipf("skipping test: 'go run' not available on %s/%s", runtime.GOOS, runtime.GOARCH)
62+
}
63+
}
64+
65+
// HasExec reports whether the current system can start new processes
66+
// using os.StartProcess or (more commonly) exec.Command.
67+
func HasExec() bool {
68+
switch runtime.GOOS {
69+
case "nacl":
70+
return false
71+
case "darwin":
72+
if strings.HasPrefix(runtime.GOARCH, "arm") {
73+
return false
74+
}
75+
}
76+
return true
77+
}
78+
79+
// MustHaveExec checks that the current system can start new processes
80+
// using os.StartProcess or (more commonly) exec.Command.
81+
// If not, MustHaveExec calls t.Skip with an explanation.
82+
func MustHaveExec(t *testing.T) {
83+
if !HasExec() {
84+
t.Skipf("skipping test: cannot exec subprocess on %s/%s", runtime.GOOS, runtime.GOARCH)
85+
}
86+
}
87+
88+
// HasExternalNetwork reports whether the current system can use
89+
// external (non-localhost) networks.
90+
func HasExternalNetwork() bool {
91+
return !testing.Short()
92+
}
93+
94+
// MustHaveExternalNetwork checks that the current system can use
95+
// external (non-localhost) networks.
96+
// If not, MustHaveExternalNetwork calls t.Skip with an explanation.
97+
func MustHaveExternalNetwork(t *testing.T) {
98+
if testing.Short() {
99+
t.Skipf("skipping test: no external network in -short mode")
100+
}
101+
}

0 commit comments

Comments
 (0)