Skip to content

Commit 3cf8e8e

Browse files
committed
cmd/dist: put cgo tests under a "Testing cgo" heading
Currently the cgo tests mostly use their package name as a heading, which means we get a large number of test sections that each have a single test package in them. Unify them all under "Testing cgo" to reduce output noise. This leaves just the cmd/api test without a heading, so we give it a heading and require that all tests have a heading. Change-Id: I24cd9a96eb35bbc3ff9335ca8a382ec2426306c1 Reviewed-on: https://go-review.googlesource.com/c/go/+/494497 Reviewed-by: Dmitri Shuralyov <[email protected]> Run-TryBot: Austin Clements <[email protected]> Reviewed-by: Dmitri Shuralyov <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: Bryan Mills <[email protected]>
1 parent 65306bc commit 3cf8e8e

File tree

1 file changed

+24
-26
lines changed

1 file changed

+24
-26
lines changed

src/cmd/dist/test.go

+24-26
Original file line numberDiff line numberDiff line change
@@ -785,42 +785,43 @@ func (t *tester) registerTests() {
785785
t.registerRaceTests()
786786
}
787787

788+
const cgoHeading = "Testing cgo"
788789
if t.cgoEnabled && !t.iOS() {
789790
// Disabled on iOS. golang.org/issue/15919
790-
t.registerTest("cgo_teststdio", "", &goTest{pkg: "cmd/cgo/internal/teststdio", timeout: 5 * time.Minute})
791-
t.registerTest("cgo_testlife", "", &goTest{pkg: "cmd/cgo/internal/testlife", timeout: 5 * time.Minute})
791+
t.registerTest("cgo_teststdio", cgoHeading, &goTest{pkg: "cmd/cgo/internal/teststdio", timeout: 5 * time.Minute})
792+
t.registerTest("cgo_testlife", cgoHeading, &goTest{pkg: "cmd/cgo/internal/testlife", timeout: 5 * time.Minute})
792793
if goos != "android" {
793-
t.registerTest("cgo_testfortran", "", &goTest{pkg: "cmd/cgo/internal/testfortran", timeout: 5 * time.Minute})
794+
t.registerTest("cgo_testfortran", cgoHeading, &goTest{pkg: "cmd/cgo/internal/testfortran", timeout: 5 * time.Minute})
794795
}
795796
}
796797
if t.cgoEnabled {
797-
t.registerCgoTests()
798+
t.registerCgoTests(cgoHeading)
798799
}
799800

800801
// Don't run these tests with $GO_GCFLAGS because most of them
801802
// assume that they can run "go install" with no -gcflags and not
802803
// recompile the entire standard library. If make.bash ran with
803804
// special -gcflags, that's not true.
804805
if t.cgoEnabled && gogcflags == "" {
805-
t.registerTest("cgo_testgodefs", "", &goTest{pkg: "cmd/cgo/internal/testgodefs", timeout: 5 * time.Minute})
806+
t.registerTest("cgo_testgodefs", cgoHeading, &goTest{pkg: "cmd/cgo/internal/testgodefs", timeout: 5 * time.Minute})
806807

807-
t.registerTest("cgo_testso", "", &goTest{pkg: "cmd/cgo/internal/testso", timeout: 600 * time.Second})
808-
t.registerTest("cgo_testsovar", "", &goTest{pkg: "cmd/cgo/internal/testsovar", timeout: 600 * time.Second})
808+
t.registerTest("cgo_testso", cgoHeading, &goTest{pkg: "cmd/cgo/internal/testso", timeout: 600 * time.Second})
809+
t.registerTest("cgo_testsovar", cgoHeading, &goTest{pkg: "cmd/cgo/internal/testsovar", timeout: 600 * time.Second})
809810
if t.supportedBuildmode("c-archive") {
810-
t.registerTest("cgo_testcarchive", "", &goTest{pkg: "cmd/cgo/internal/testcarchive", timeout: 5 * time.Minute})
811+
t.registerTest("cgo_testcarchive", cgoHeading, &goTest{pkg: "cmd/cgo/internal/testcarchive", timeout: 5 * time.Minute})
811812
}
812813
if t.supportedBuildmode("c-shared") {
813-
t.registerTest("cgo_testcshared", "", &goTest{pkg: "cmd/cgo/internal/testcshared", timeout: 5 * time.Minute})
814+
t.registerTest("cgo_testcshared", cgoHeading, &goTest{pkg: "cmd/cgo/internal/testcshared", timeout: 5 * time.Minute})
814815
}
815816
if t.supportedBuildmode("shared") {
816-
t.registerTest("cgo_testshared", "", &goTest{pkg: "cmd/cgo/internal/testshared", timeout: 600 * time.Second})
817+
t.registerTest("cgo_testshared", cgoHeading, &goTest{pkg: "cmd/cgo/internal/testshared", timeout: 600 * time.Second})
817818
}
818819
if t.supportedBuildmode("plugin") {
819-
t.registerTest("cgo_testplugin", "", &goTest{pkg: "cmd/cgo/internal/testplugin", timeout: 600 * time.Second})
820+
t.registerTest("cgo_testplugin", cgoHeading, &goTest{pkg: "cmd/cgo/internal/testplugin", timeout: 600 * time.Second})
820821
}
821-
t.registerTest("cgo_testsanitizers", "", &goTest{pkg: "cmd/cgo/internal/testsanitizers", timeout: 5 * time.Minute})
822+
t.registerTest("cgo_testsanitizers", cgoHeading, &goTest{pkg: "cmd/cgo/internal/testsanitizers", timeout: 5 * time.Minute})
822823
if t.hasBash() && goos != "android" && !t.iOS() && gohostos != "windows" {
823-
t.registerTest("cgo_errors", "", &goTest{pkg: "cmd/cgo/internal/testerrors", timeout: 5 * time.Minute})
824+
t.registerTest("cgo_errors", cgoHeading, &goTest{pkg: "cmd/cgo/internal/testerrors", timeout: 5 * time.Minute})
824825
}
825826
}
826827

@@ -853,17 +854,20 @@ func (t *tester) registerTests() {
853854
// To help developers avoid trybot-only failures, we try to run on typical developer machines
854855
// which is darwin,linux,windows/amd64 and darwin/arm64.
855856
if goos == "darwin" || ((goos == "linux" || goos == "windows") && goarch == "amd64") {
856-
t.registerTest("api", "", &goTest{pkg: "cmd/api", timeout: 5 * time.Minute, testFlags: []string{"-check"}})
857+
t.registerTest("api", "API check", &goTest{pkg: "cmd/api", timeout: 5 * time.Minute, testFlags: []string{"-check"}})
857858
}
858859
}
859860

860861
// addTest adds an arbitrary test callback to the test list.
861862
//
862-
// name must uniquely identify the test.
863+
// name must uniquely identify the test and heading must be non-empty.
863864
func (t *tester) addTest(name, heading string, fn func(*distTest) error) {
864865
if t.testNames[name] {
865866
panic("duplicate registered test name " + name)
866867
}
868+
if heading == "" {
869+
panic("empty heading")
870+
}
867871
if t.testNames == nil {
868872
t.testNames = make(map[string]bool)
869873
}
@@ -889,7 +893,7 @@ func (rtPreFunc) isRegisterTestOpt() {}
889893

890894
// registerTest registers a test that runs the given goTest.
891895
//
892-
// If heading is "", it uses test.pkg as the heading.
896+
// name must uniquely identify the test and heading must be non-empty.
893897
func (t *tester) registerTest(name, heading string, test *goTest, opts ...registerTestOpt) {
894898
var preFunc func(*distTest) bool
895899
for _, opt := range opts {
@@ -898,12 +902,6 @@ func (t *tester) registerTest(name, heading string, test *goTest, opts ...regist
898902
preFunc = opt.pre
899903
}
900904
}
901-
if heading == "" {
902-
if test.pkg == "" {
903-
panic("either heading or test.pkg must be set")
904-
}
905-
heading = test.pkg
906-
}
907905
t.addTest(name, heading, func(dt *distTest) error {
908906
if preFunc != nil && !preFunc(dt) {
909907
return nil
@@ -1050,7 +1048,7 @@ func (t *tester) supportedBuildmode(mode string) bool {
10501048
return buildModeSupported("gc", mode, goos, goarch)
10511049
}
10521050

1053-
func (t *tester) registerCgoTests() {
1051+
func (t *tester) registerCgoTests(heading string) {
10541052
cgoTest := func(name string, subdir, linkmode, buildmode string, opts ...registerTestOpt) *goTest {
10551053
gt := &goTest{
10561054
pkg: "cmd/cgo/internal/" + subdir,
@@ -1078,7 +1076,7 @@ func (t *tester) registerCgoTests() {
10781076
gt.tags = append(gt.tags, "static")
10791077
}
10801078

1081-
t.registerTest("cgo:"+name, "cmd/cgo/internal/test", gt, opts...)
1079+
t.registerTest("cgo:"+name, heading, gt, opts...)
10821080
return gt
10831081
}
10841082

@@ -1236,7 +1234,7 @@ func (t *tester) runPending(nextTest *distTest) {
12361234
}
12371235
w := worklist[ended]
12381236
dt := w.dt
1239-
if dt.heading != "" && t.lastHeading != dt.heading {
1237+
if t.lastHeading != dt.heading {
12401238
t.lastHeading = dt.heading
12411239
t.out(dt.heading)
12421240
}
@@ -1263,7 +1261,7 @@ func (t *tester) runPending(nextTest *distTest) {
12631261
}
12641262

12651263
if dt := nextTest; dt != nil {
1266-
if dt.heading != "" && t.lastHeading != dt.heading {
1264+
if t.lastHeading != dt.heading {
12671265
t.lastHeading = dt.heading
12681266
t.out(dt.heading)
12691267
}

0 commit comments

Comments
 (0)