From 78a36f7724ef22980005962b8457188e3668542b Mon Sep 17 00:00:00 2001 From: Dan Kegel Date: Thu, 13 Jan 2022 22:20:02 -0800 Subject: [PATCH] testing: nudge functions closer to upstream order, to make diffing easier. No functional change. --- src/testing/testing.go | 86 ++++++++++++++++++------------------- src/testing/testing_test.go | 18 ++++++++ 2 files changed, 59 insertions(+), 45 deletions(-) create mode 100644 src/testing/testing_test.go diff --git a/src/testing/testing.go b/src/testing/testing.go index fc4e7fdf..ec5d2d44 100644 --- a/src/testing/testing.go +++ b/src/testing/testing.go @@ -56,6 +56,23 @@ type common struct { name string // Name of test or benchmark. } +// Short reports whether the -test.short flag is set. +func Short() bool { + return flagShort +} + +// CoverMode reports what the test coverage mode is set to. +// +// Test coverage is not supported; this returns the empty string. +func CoverMode() string { + return "" +} + +// Verbose reports whether the -test.v flag is set. +func Verbose() bool { + return flagVerbose +} + // TB is the interface common to T and B. type TB interface { Error(args ...interface{}) @@ -204,11 +221,6 @@ func (c *common) Helper() { // Unimplemented. } -// Parallel is not implemented, it is only provided for compatibility. -func (c *common) Parallel() { - // Unimplemented. -} - // Cleanup registers a function to be called when the test (or subtest) and all its // subtests complete. Cleanup functions will be called in last added, // first called order. @@ -232,6 +244,17 @@ func (c *common) runCleanup() { } } +// Parallel is not implemented, it is only provided for compatibility. +func (c *common) Parallel() { + // Unimplemented. +} + +// InternalTest is a reference to a test that should be called during a test suite run. +type InternalTest struct { + Name string + F func(*T) +} + func tRunner(t *T, fn func(t *T)) { defer func() { t.runCleanup() @@ -276,12 +299,6 @@ func (t *T) Run(name string, f func(t *T)) bool { return !sub.failed } -// InternalTest is a reference to a test that should be called during a test suite run. -type InternalTest struct { - Name string - F func(*T) -} - // M is a test suite. type M struct { // tests is a list of the test names to execute @@ -291,6 +308,19 @@ type M struct { deps testDeps } +type testDeps interface { + MatchString(pat, str string) (bool, error) +} + +func MainStart(deps interface{}, tests []InternalTest, benchmarks []InternalBenchmark, examples []InternalExample) *M { + Init() + return &M{ + Tests: tests, + Benchmarks: benchmarks, + deps: deps.(testDeps), + } +} + // Run the test suite. func (m *M) Run() int { @@ -351,23 +381,6 @@ func (m *M) Run() int { return failures } -// Short reports whether the -test.short flag is set. -func Short() bool { - return flagShort -} - -// Verbose reports whether the -test.v flag is set. -func Verbose() bool { - return flagVerbose -} - -// CoverMode reports what the test coverage mode is set to. -// -// Test coverage is not supported; this returns the empty string. -func CoverMode() string { - return "" -} - // AllocsPerRun returns the average number of allocations during calls to f. // Although the return value has type float64, it will always be an integral // value. @@ -381,23 +394,6 @@ func AllocsPerRun(runs int, f func()) (avg float64) { return 0 } -func TestMain(m *M) { - os.Exit(m.Run()) -} - -type testDeps interface { - MatchString(pat, s string) (bool, error) -} - -func MainStart(deps interface{}, tests []InternalTest, benchmarks []InternalBenchmark, examples []InternalExample) *M { - Init() - return &M{ - Tests: tests, - Benchmarks: benchmarks, - deps: deps.(testDeps), - } -} - type InternalExample struct { Name string F func() diff --git a/src/testing/testing_test.go b/src/testing/testing_test.go new file mode 100644 index 00000000..45e44683 --- /dev/null +++ b/src/testing/testing_test.go @@ -0,0 +1,18 @@ +// Copyright 2014 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package testing_test + +import ( + "os" + "testing" +) + +// This is exactly what a test would do without a TestMain. +// It's here only so that there is at least one package in the +// standard library with a TestMain, so that code is executed. + +func TestMain(m *testing.M) { + os.Exit(m.Run()) +}