Skip to content

Commit c308e9b

Browse files
committed
cmd/dist: drop goTest.dir
At this point all tests are regular packages in std or cmd, so we no longer need goTest.dir. Change-Id: I46a0c7b4464b0738e9959e41bf840ba1b73e3590 Reviewed-on: https://go-review.googlesource.com/c/go/+/494194 Run-TryBot: Austin Clements <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: Dmitri Shuralyov <[email protected]> Reviewed-by: Dmitri Shuralyov <[email protected]>
1 parent b679e31 commit c308e9b

File tree

1 file changed

+23
-29
lines changed

1 file changed

+23
-29
lines changed

src/cmd/dist/test.go

Lines changed: 23 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -293,13 +293,12 @@ type goTest struct {
293293
ldflags string // If non-empty, build with -ldflags=X
294294
buildmode string // If non-empty, -buildmode flag
295295

296-
dir string // If non-empty, run in GOROOT/src-relative directory dir
297296
env []string // Environment variables to add, as KEY=VAL. KEY= unsets a variable
298297

299298
runOnHost bool // When cross-compiling, run this test on the host instead of guest
300299

301300
// We have both pkg and pkgs as a convenience. Both may be set, in which
302-
// case they will be combined. If both are empty, the default is ".".
301+
// case they will be combined. At least one must be set.
303302
pkgs []string // Multiple packages to test
304303
pkg string // A single package to test
305304

@@ -410,7 +409,7 @@ func (opts *goTest) buildArgs(t *tester) (goCmd string, build, run, pkgs, testFl
410409
pkgs = append(pkgs[:len(pkgs):len(pkgs)], opts.pkg)
411410
}
412411
if len(pkgs) == 0 {
413-
pkgs = []string{"."}
412+
panic("no packages")
414413
}
415414

416415
runOnHost := opts.runOnHost && (goarch != gohostarch || goos != gohostos)
@@ -427,15 +426,7 @@ func (opts *goTest) buildArgs(t *tester) (goCmd string, build, run, pkgs, testFl
427426
if opts.goroot != "" {
428427
thisGoroot = opts.goroot
429428
}
430-
var dir string
431-
if opts.dir != "" {
432-
if filepath.IsAbs(opts.dir) {
433-
panic("dir must be relative, got: " + opts.dir)
434-
}
435-
dir = filepath.Join(thisGoroot, "src", opts.dir)
436-
} else {
437-
dir = filepath.Join(thisGoroot, "src")
438-
}
429+
dir := filepath.Join(thisGoroot, "src")
439430
setupCmd = func(cmd *exec.Cmd) {
440431
setDir(cmd, dir)
441432
if len(opts.env) != 0 {
@@ -810,10 +801,10 @@ func (t *tester) registerTests() {
810801

811802
if t.cgoEnabled && !t.iOS() {
812803
// Disabled on iOS. golang.org/issue/15919
813-
t.registerTest("cgo_teststdio", "", &goTest{dir: "cmd/cgo/internal/teststdio", timeout: 5 * time.Minute})
814-
t.registerTest("cgo_testlife", "", &goTest{dir: "cmd/cgo/internal/testlife", timeout: 5 * time.Minute})
804+
t.registerTest("cgo_teststdio", "", &goTest{pkg: "cmd/cgo/internal/teststdio", timeout: 5 * time.Minute})
805+
t.registerTest("cgo_testlife", "", &goTest{pkg: "cmd/cgo/internal/testlife", timeout: 5 * time.Minute})
815806
if goos != "android" {
816-
t.registerTest("cgo_testfortran", "", &goTest{dir: "cmd/cgo/internal/testfortran", timeout: 5 * time.Minute})
807+
t.registerTest("cgo_testfortran", "", &goTest{pkg: "cmd/cgo/internal/testfortran", timeout: 5 * time.Minute})
817808
}
818809
}
819810
if t.cgoEnabled {
@@ -825,29 +816,29 @@ func (t *tester) registerTests() {
825816
// recompile the entire standard library. If make.bash ran with
826817
// special -gcflags, that's not true.
827818
if t.cgoEnabled && gogcflags == "" {
828-
t.registerTest("cgo_testgodefs", "", &goTest{dir: "cmd/cgo/internal/testgodefs", timeout: 5 * time.Minute})
819+
t.registerTest("cgo_testgodefs", "", &goTest{pkg: "cmd/cgo/internal/testgodefs", timeout: 5 * time.Minute})
829820

830-
t.registerTest("cgo_testso", "", &goTest{dir: "cmd/cgo/internal/testso", timeout: 600 * time.Second})
831-
t.registerTest("cgo_testsovar", "", &goTest{dir: "cmd/cgo/internal/testsovar", timeout: 600 * time.Second})
821+
t.registerTest("cgo_testso", "", &goTest{pkg: "cmd/cgo/internal/testso", timeout: 600 * time.Second})
822+
t.registerTest("cgo_testsovar", "", &goTest{pkg: "cmd/cgo/internal/testsovar", timeout: 600 * time.Second})
832823
if t.supportedBuildmode("c-archive") {
833-
t.registerTest("cgo_testcarchive", "", &goTest{dir: "cmd/cgo/internal/testcarchive", timeout: 5 * time.Minute})
824+
t.registerTest("cgo_testcarchive", "", &goTest{pkg: "cmd/cgo/internal/testcarchive", timeout: 5 * time.Minute})
834825
}
835826
if t.supportedBuildmode("c-shared") {
836-
t.registerTest("cgo_testcshared", "", &goTest{dir: "cmd/cgo/internal/testcshared", timeout: 5 * time.Minute})
827+
t.registerTest("cgo_testcshared", "", &goTest{pkg: "cmd/cgo/internal/testcshared", timeout: 5 * time.Minute})
837828
}
838829
if t.supportedBuildmode("shared") {
839-
t.registerTest("cgo_testshared", "", &goTest{dir: "cmd/cgo/internal/testshared", timeout: 600 * time.Second})
830+
t.registerTest("cgo_testshared", "", &goTest{pkg: "cmd/cgo/internal/testshared", timeout: 600 * time.Second})
840831
}
841832
if t.supportedBuildmode("plugin") {
842-
t.registerTest("cgo_testplugin", "", &goTest{dir: "cmd/cgo/internal/testplugin", timeout: 600 * time.Second})
833+
t.registerTest("cgo_testplugin", "", &goTest{pkg: "cmd/cgo/internal/testplugin", timeout: 600 * time.Second})
843834
}
844835
if goos == "linux" || (goos == "freebsd" && goarch == "amd64") {
845836
// because Pdeathsig of syscall.SysProcAttr struct used in cmd/cgo/internal/testsanitizers is only
846837
// supported on Linux and FreeBSD.
847-
t.registerTest("cgo_testsanitizers", "", &goTest{dir: "cmd/cgo/internal/testsanitizers", timeout: 5 * time.Minute})
838+
t.registerTest("cgo_testsanitizers", "", &goTest{pkg: "cmd/cgo/internal/testsanitizers", timeout: 5 * time.Minute})
848839
}
849840
if t.hasBash() && goos != "android" && !t.iOS() && gohostos != "windows" {
850-
t.registerTest("cgo_errors", "", &goTest{dir: "cmd/cgo/internal/testerrors", timeout: 5 * time.Minute})
841+
t.registerTest("cgo_errors", "", &goTest{pkg: "cmd/cgo/internal/testerrors", timeout: 5 * time.Minute})
851842
}
852843
}
853844

@@ -867,7 +858,7 @@ func (t *tester) registerTests() {
867858
fmt.Sprintf("test:%d_%d", shard, nShards),
868859
"../test",
869860
&goTest{
870-
dir: "internal/testdir",
861+
pkg: "internal/testdir",
871862
testFlags: []string{fmt.Sprintf("-shard=%d", shard), fmt.Sprintf("-shards=%d", nShards)},
872863
runOnHost: true,
873864
},
@@ -880,7 +871,7 @@ func (t *tester) registerTests() {
880871
// To help developers avoid trybot-only failures, we try to run on typical developer machines
881872
// which is darwin,linux,windows/amd64 and darwin/arm64.
882873
if goos == "darwin" || ((goos == "linux" || goos == "windows") && goarch == "amd64") {
883-
t.registerTest("api", "", &goTest{dir: "cmd/api", timeout: 5 * time.Minute, testFlags: []string{"-check"}})
874+
t.registerTest("api", "", &goTest{pkg: "cmd/api", timeout: 5 * time.Minute, testFlags: []string{"-check"}})
884875
}
885876
}
886877

@@ -909,7 +900,7 @@ func (rtPreFunc) isRegisterTestOpt() {}
909900

910901
// registerTest registers a test that runs the given goTest.
911902
//
912-
// If heading is "", it uses test.dir as the heading.
903+
// If heading is "", it uses test.pkg as the heading.
913904
func (t *tester) registerTest(name, heading string, test *goTest, opts ...registerTestOpt) {
914905
var preFunc func(*distTest) bool
915906
for _, opt := range opts {
@@ -922,7 +913,10 @@ func (t *tester) registerTest(name, heading string, test *goTest, opts ...regist
922913
panic("duplicate registered test name " + name)
923914
}
924915
if heading == "" {
925-
heading = test.dir
916+
if test.pkg == "" {
917+
panic("either heading or test.pkg must be set")
918+
}
919+
heading = test.pkg
926920
}
927921
t.tests = append(t.tests, distTest{
928922
name: name,
@@ -1077,7 +1071,7 @@ func (t *tester) supportedBuildmode(mode string) bool {
10771071
func (t *tester) registerCgoTests() {
10781072
cgoTest := func(name string, subdir, linkmode, buildmode string, opts ...registerTestOpt) *goTest {
10791073
gt := &goTest{
1080-
dir: "cmd/cgo/internal/" + subdir,
1074+
pkg: "cmd/cgo/internal/" + subdir,
10811075
buildmode: buildmode,
10821076
ldflags: "-linkmode=" + linkmode,
10831077
}

0 commit comments

Comments
 (0)