1
0
mirror of https://github.com/golang/go synced 2024-11-17 21:44:43 -07:00

cmd/go: convert TestListTests to the script framework

The original test has four subtests. I think it's okay to just have
one corresponding script test instead of having four different
tests.

Part of converting all tests to script framework to improve
test parallelism.

Updates #36320
Updates #17751

Change-Id: I97bc2cbb3ad5a297d7457476b8c831ee6e0f49b2
Reviewed-on: https://go-review.googlesource.com/c/go/+/213126
Reviewed-by: Jay Conrod <jayconrod@google.com>
This commit is contained in:
Michael Matloob 2020-01-02 15:24:21 -05:00
parent 8df6a5d9ad
commit 7b65f1d7bb
5 changed files with 65 additions and 63 deletions

View File

@ -3856,24 +3856,6 @@ func main() {}`)
}))
}
func TestListTests(t *testing.T) {
tooSlow(t)
var tg *testgoData
testWith := func(listName, expected string) func(*testing.T) {
return func(t *testing.T) {
tg = testgo(t)
defer tg.cleanup()
tg.run("test", "./testdata/src/testlist/...", fmt.Sprintf("-list=%s", listName))
tg.grepStdout(expected, fmt.Sprintf("-test.list=%s returned %q, expected %s", listName, tg.getStdout(), expected))
}
}
t.Run("Test", testWith("Test", "TestSimple"))
t.Run("Bench", testWith("Benchmark", "BenchmarkSimple"))
t.Run("Example1", testWith("Example", "ExampleSimple"))
t.Run("Example2", testWith("Example", "ExampleWithEmptyOutput"))
}
func TestBuildmodePIE(t *testing.T) {
if testing.Short() && testenv.Builder() == "" {
t.Skipf("skipping in -short mode on non-builder")

View File

@ -0,0 +1,65 @@
[short] skip
cd $WORK
# Test
go test './gopath/src/testlist/...' -list=Test
stdout TestSimple
# Benchmark
go test './gopath/src/testlist/...' -list=Benchmark
stdout BenchmarkSimple
# Examples
go test './gopath/src/testlist/...' -list=Example
stdout ExampleSimple
stdout ExampleWithEmptyOutput
-- testlist/bench_test.go --
package testlist
import (
"fmt"
"testing"
)
func BenchmarkSimplefunc(b *testing.B) {
b.StopTimer()
b.StartTimer()
for i := 0; i < b.N; i++ {
_ = fmt.Sprint("Test for bench")
}
}
-- testlist/example_test.go --
package testlist
import (
"fmt"
)
func ExampleSimple() {
fmt.Println("Test with Output.")
// Output: Test with Output.
}
func ExampleWithEmptyOutput() {
fmt.Println("")
// Output:
}
func ExampleNoOutput() {
_ = fmt.Sprint("Test with no output")
}
-- testlist/test_test.go --
package testlist
import (
"fmt"
"testing"
)
func TestSimple(t *testing.T) {
_ = fmt.Sprint("Test simple")
}

View File

@ -1,14 +0,0 @@
package testlist
import (
"fmt"
"testing"
)
func BenchmarkSimplefunc(b *testing.B) {
b.StopTimer()
b.StartTimer()
for i := 0; i < b.N; i++ {
_ = fmt.Sprint("Test for bench")
}
}

View File

@ -1,21 +0,0 @@
package testlist
import (
"fmt"
)
func ExampleSimple() {
fmt.Println("Test with Output.")
// Output: Test with Output.
}
func ExampleWithEmptyOutput() {
fmt.Println("")
// Output:
}
func ExampleNoOutput() {
_ = fmt.Sprint("Test with no output")
}

View File

@ -1,10 +0,0 @@
package testlist
import (
"fmt"
"testing"
)
func TestSimple(t *testing.T) {
_ = fmt.Sprint("Test simple")
}