]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: convert some testcases to the script framework
authorMichael Matloob <matloob@golang.org>
Thu, 26 Dec 2019 21:06:49 +0000 (16:06 -0500)
committerMichael Matloob <matloob@golang.org>
Mon, 6 Jan 2020 17:32:58 +0000 (17:32 +0000)
This change converts TestFatalInBenchmarkCauseNonZeroExitStatus,
TestBenchmarkLabels and TestWildCardsDoNotLookInUselessDirectories
to the script framework so they can run in parallel. These tests
used the testdata directory so they didn't call tg.parallel, because
they couldn't be sure the testdata directory wasn't being
modified while they were being run.

The tests are converted to the script framework instead of being modified
because the script framework tests are easier to read and are self-contained.

Also remove the directory src/cmd/go/testdata/src/badc. The testcase
that used it, "TestDisallowedCSourceFiles" was deleted in
golang.org/cl/19613.

Updates #17751

Change-Id: I0b9b417ae1a9b148067a3e5f8531229f3414f104
Reviewed-on: https://go-review.googlesource.com/c/go/+/212620
Run-TryBot: Michael Matloob <matloob@golang.org>
Reviewed-by: Jay Conrod <jayconrod@google.com>
src/cmd/go/go_test.go
src/cmd/go/testdata/script/README
src/cmd/go/testdata/script/list_wildcard_skip_nonmatching.txt [new file with mode: 0644]
src/cmd/go/testdata/script/test_benchmark_fatal.txt [new file with mode: 0644]
src/cmd/go/testdata/script/test_benchmark_labels.txt [new file with mode: 0644]
src/cmd/go/testdata/src/badc/x.c [deleted file]
src/cmd/go/testdata/src/badc/x.go [deleted file]
src/cmd/go/testdata/src/badpkg/x.go [deleted file]
src/cmd/go/testdata/src/bench/x_test.go [deleted file]
src/cmd/go/testdata/src/benchfatal/x_test.go [deleted file]

index 5494fd1adc45702d9dad209122f4e97a0781c0cf..6a47c09bdeb08e367298c9bfd24007edcc82ec10 100644 (file)
@@ -638,7 +638,7 @@ func (tg *testgoData) grepStderrNot(match, msg string) {
 }
 
 // grepBothNot looks for a regular expression in the test run's
-// standard output or stand error and fails, logging msg, if it is
+// standard output or standard error and fails, logging msg, if it is
 // found.
 func (tg *testgoData) grepBothNot(match, msg string) {
        tg.t.Helper()
@@ -1196,15 +1196,6 @@ func TestAccidentalGitCheckout(t *testing.T) {
        }
 }
 
-func TestWildcardsDoNotLookInUselessDirectories(t *testing.T) {
-       tg := testgo(t)
-       defer tg.cleanup()
-       tg.setenv("GOPATH", filepath.Join(tg.pwd(), "testdata"))
-       tg.runFail("list", "...")
-       tg.grepBoth("badpkg", "go list ... failure does not mention badpkg")
-       tg.run("list", "m...")
-}
-
 func TestRelativeImportsGoTest(t *testing.T) {
        tg := testgo(t)
        defer tg.cleanup()
@@ -3525,15 +3516,6 @@ func TestIssue17119(t *testing.T) {
        tg.grepBothNot("duplicate load|internal error", "internal error")
 }
 
-func TestFatalInBenchmarkCauseNonZeroExitStatus(t *testing.T) {
-       tg := testgo(t)
-       defer tg.cleanup()
-       // TODO: tg.parallel()
-       tg.runFail("test", "-run", "^$", "-bench", ".", "./testdata/src/benchfatal")
-       tg.grepBothNot("^ok", "test passed unexpectedly")
-       tg.grepBoth("FAIL.*benchfatal", "test did not run everything")
-}
-
 func TestBinaryOnlyPackages(t *testing.T) {
        tooSlow(t)
 
@@ -3726,18 +3708,6 @@ func TestMatchesOnlyBenchmarkIsOK(t *testing.T) {
        tg.grepBoth(okPattern, "go test did not say ok")
 }
 
-func TestBenchmarkLabels(t *testing.T) {
-       tg := testgo(t)
-       defer tg.cleanup()
-       tg.parallel()
-       tg.setenv("GOPATH", filepath.Join(tg.pwd(), "testdata"))
-       tg.run("test", "-run", "^$", "-bench", ".", "bench")
-       tg.grepStdout(`(?m)^goos: `+runtime.GOOS, "go test did not print goos")
-       tg.grepStdout(`(?m)^goarch: `+runtime.GOARCH, "go test did not print goarch")
-       tg.grepStdout(`(?m)^pkg: bench`, "go test did not say pkg: bench")
-       tg.grepBothNot(`(?s)pkg:.*pkg:`, "go test said pkg multiple times")
-}
-
 func TestBenchmarkLabelsOutsideGOPATH(t *testing.T) {
        tg := testgo(t)
        defer tg.cleanup()
index 2782a097079877fca8eb0bc1bd14af48b5af5cbd..7dba6b394c9b628396f4211cc0b71dcc58d60b5b 100644 (file)
@@ -40,7 +40,7 @@ Scripts also have access to these other environment variables:
        goversion=<current Go version; for example, 1.12>
        :=<OS-specific path list separator>
 
-The scripts supporting files are unpacked relative to $GOPATH/src (aka $WORK/gopath/src)
+The scripts' supporting files are unpacked relative to $GOPATH/src (aka $WORK/gopath/src)
 and then the script begins execution in that directory as well. Thus the example above runs
 in $WORK/gopath/src with GOPATH=$WORK/gopath and $WORK/gopath/src/hello.go
 containing the listed contents.
diff --git a/src/cmd/go/testdata/script/list_wildcard_skip_nonmatching.txt b/src/cmd/go/testdata/script/list_wildcard_skip_nonmatching.txt
new file mode 100644 (file)
index 0000000..02159d0
--- /dev/null
@@ -0,0 +1,13 @@
+# Test that wildcards don't look in useless directories.
+
+# First make sure that badpkg fails the list of '...'.
+! go list ...
+stderr badpkg 
+
+# Check that the list of 'm...' succeeds. That implies badpkg was skipped.
+go list m...
+
+-- m/x.go --
+package m
+-- badpkg/x.go --
+pkg badpkg
\ No newline at end of file
diff --git a/src/cmd/go/testdata/script/test_benchmark_fatal.txt b/src/cmd/go/testdata/script/test_benchmark_fatal.txt
new file mode 100644 (file)
index 0000000..1e20c4e
--- /dev/null
@@ -0,0 +1,15 @@
+# Test that calling t.Fatal in a benchmark causes a non-zero exit status.
+
+! go test -run '^$' -bench . benchfatal
+! stdout ^ok
+! stderr ^ok
+stdout FAIL.*benchfatal
+
+-- benchfatal/x_test.go --
+package benchfatal
+
+import "testing"
+
+func BenchmarkThatCallsFatal(b *testing.B) {
+       b.Fatal("called by benchmark")
+}
diff --git a/src/cmd/go/testdata/script/test_benchmark_labels.txt b/src/cmd/go/testdata/script/test_benchmark_labels.txt
new file mode 100644 (file)
index 0000000..affab6b
--- /dev/null
@@ -0,0 +1,19 @@
+# Tests that go test -bench prints out goos, goarch, and pkg.
+
+# Check for goos, goarch, and pkg.
+go test -run ^$ -bench . bench
+stdout '^goos: '$GOOS
+stdout '^goarch: '$GOARCH
+stdout '^pkg: bench'
+
+# Check go test does not print pkg multiple times
+! stdout 'pkg:.*pkg: '
+! stderr 'pkg:.*pkg:'
+
+-- bench/x_test.go --
+package bench
+
+import "testing"
+
+func Benchmark(b *testing.B) {
+}
diff --git a/src/cmd/go/testdata/src/badc/x.c b/src/cmd/go/testdata/src/badc/x.c
deleted file mode 100644 (file)
index f6cbf69..0000000
+++ /dev/null
@@ -1 +0,0 @@
-// C code!
diff --git a/src/cmd/go/testdata/src/badc/x.go b/src/cmd/go/testdata/src/badc/x.go
deleted file mode 100644 (file)
index bfa1de2..0000000
+++ /dev/null
@@ -1 +0,0 @@
-package badc
diff --git a/src/cmd/go/testdata/src/badpkg/x.go b/src/cmd/go/testdata/src/badpkg/x.go
deleted file mode 100644 (file)
index dda35e8..0000000
+++ /dev/null
@@ -1 +0,0 @@
-pkg badpkg
diff --git a/src/cmd/go/testdata/src/bench/x_test.go b/src/cmd/go/testdata/src/bench/x_test.go
deleted file mode 100644 (file)
index 32cabf8..0000000
+++ /dev/null
@@ -1,6 +0,0 @@
-package bench
-
-import "testing"
-
-func Benchmark(b *testing.B) {
-}
diff --git a/src/cmd/go/testdata/src/benchfatal/x_test.go b/src/cmd/go/testdata/src/benchfatal/x_test.go
deleted file mode 100644 (file)
index 8d3a5de..0000000
+++ /dev/null
@@ -1,7 +0,0 @@
-package benchfatal
-
-import "testing"
-
-func BenchmarkThatCallsFatal(b *testing.B) {
-       b.Fatal("called by benchmark")
-}