@@ -293,13 +293,12 @@ type goTest struct {
293
293
ldflags string // If non-empty, build with -ldflags=X
294
294
buildmode string // If non-empty, -buildmode flag
295
295
296
- dir string // If non-empty, run in GOROOT/src-relative directory dir
297
296
env []string // Environment variables to add, as KEY=VAL. KEY= unsets a variable
298
297
299
298
runOnHost bool // When cross-compiling, run this test on the host instead of guest
300
299
301
300
// 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 .
303
302
pkgs []string // Multiple packages to test
304
303
pkg string // A single package to test
305
304
@@ -410,7 +409,7 @@ func (opts *goTest) buildArgs(t *tester) (goCmd string, build, run, pkgs, testFl
410
409
pkgs = append (pkgs [:len (pkgs ):len (pkgs )], opts .pkg )
411
410
}
412
411
if len (pkgs ) == 0 {
413
- pkgs = [] string { "." }
412
+ panic ( "no packages" )
414
413
}
415
414
416
415
runOnHost := opts .runOnHost && (goarch != gohostarch || goos != gohostos )
@@ -427,15 +426,7 @@ func (opts *goTest) buildArgs(t *tester) (goCmd string, build, run, pkgs, testFl
427
426
if opts .goroot != "" {
428
427
thisGoroot = opts .goroot
429
428
}
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" )
439
430
setupCmd = func (cmd * exec.Cmd ) {
440
431
setDir (cmd , dir )
441
432
if len (opts .env ) != 0 {
@@ -810,10 +801,10 @@ func (t *tester) registerTests() {
810
801
811
802
if t .cgoEnabled && ! t .iOS () {
812
803
// 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 })
815
806
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 })
817
808
}
818
809
}
819
810
if t .cgoEnabled {
@@ -825,29 +816,29 @@ func (t *tester) registerTests() {
825
816
// recompile the entire standard library. If make.bash ran with
826
817
// special -gcflags, that's not true.
827
818
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 })
829
820
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 })
832
823
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 })
834
825
}
835
826
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 })
837
828
}
838
829
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 })
840
831
}
841
832
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 })
843
834
}
844
835
if goos == "linux" || (goos == "freebsd" && goarch == "amd64" ) {
845
836
// because Pdeathsig of syscall.SysProcAttr struct used in cmd/cgo/internal/testsanitizers is only
846
837
// 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 })
848
839
}
849
840
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 })
851
842
}
852
843
}
853
844
@@ -867,7 +858,7 @@ func (t *tester) registerTests() {
867
858
fmt .Sprintf ("test:%d_%d" , shard , nShards ),
868
859
"../test" ,
869
860
& goTest {
870
- dir : "internal/testdir" ,
861
+ pkg : "internal/testdir" ,
871
862
testFlags : []string {fmt .Sprintf ("-shard=%d" , shard ), fmt .Sprintf ("-shards=%d" , nShards )},
872
863
runOnHost : true ,
873
864
},
@@ -880,7 +871,7 @@ func (t *tester) registerTests() {
880
871
// To help developers avoid trybot-only failures, we try to run on typical developer machines
881
872
// which is darwin,linux,windows/amd64 and darwin/arm64.
882
873
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" }})
884
875
}
885
876
}
886
877
@@ -909,7 +900,7 @@ func (rtPreFunc) isRegisterTestOpt() {}
909
900
910
901
// registerTest registers a test that runs the given goTest.
911
902
//
912
- // If heading is "", it uses test.dir as the heading.
903
+ // If heading is "", it uses test.pkg as the heading.
913
904
func (t * tester ) registerTest (name , heading string , test * goTest , opts ... registerTestOpt ) {
914
905
var preFunc func (* distTest ) bool
915
906
for _ , opt := range opts {
@@ -922,7 +913,10 @@ func (t *tester) registerTest(name, heading string, test *goTest, opts ...regist
922
913
panic ("duplicate registered test name " + name )
923
914
}
924
915
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
926
920
}
927
921
t .tests = append (t .tests , distTest {
928
922
name : name ,
@@ -1077,7 +1071,7 @@ func (t *tester) supportedBuildmode(mode string) bool {
1077
1071
func (t * tester ) registerCgoTests () {
1078
1072
cgoTest := func (name string , subdir , linkmode , buildmode string , opts ... registerTestOpt ) * goTest {
1079
1073
gt := & goTest {
1080
- dir : "cmd/cgo/internal/" + subdir ,
1074
+ pkg : "cmd/cgo/internal/" + subdir ,
1081
1075
buildmode : buildmode ,
1082
1076
ldflags : "-linkmode=" + linkmode ,
1083
1077
}
0 commit comments