mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
testing: move Skip into *common
Move Skip and friends into *common so benchmarks can also be skipped. R=golang-dev, gustav.paul, rsc CC=golang-dev https://golang.org/cl/7379046
This commit is contained in:
parent
e822860756
commit
d31dd089e6
1 changed files with 40 additions and 40 deletions
|
|
@ -10,7 +10,7 @@
|
||||||
// [a-z]) and serves to identify the test routine.
|
// [a-z]) and serves to identify the test routine.
|
||||||
// These TestXxx routines should be declared within the package they are testing.
|
// These TestXxx routines should be declared within the package they are testing.
|
||||||
//
|
//
|
||||||
// Tests may be skipped if not applicable like this:
|
// Tests and benchmarks may be skipped if not applicable like this:
|
||||||
// func TestTimeConsuming(t *testing.T) {
|
// func TestTimeConsuming(t *testing.T) {
|
||||||
// if testing.Short() {
|
// if testing.Short() {
|
||||||
// t.Skip("skipping test in short mode.")
|
// t.Skip("skipping test in short mode.")
|
||||||
|
|
@ -130,9 +130,10 @@ var (
|
||||||
// common holds the elements common between T and B and
|
// common holds the elements common between T and B and
|
||||||
// captures common methods such as Errorf.
|
// captures common methods such as Errorf.
|
||||||
type common struct {
|
type common struct {
|
||||||
mu sync.RWMutex // guards output and failed
|
mu sync.RWMutex // guards output and failed
|
||||||
output []byte // Output generated by test or benchmark.
|
output []byte // Output generated by test or benchmark.
|
||||||
failed bool // Test or benchmark has failed.
|
failed bool // Test or benchmark has failed.
|
||||||
|
skipped bool // Test of benchmark has been skipped.
|
||||||
|
|
||||||
start time.Time // Time test or benchmark started
|
start time.Time // Time test or benchmark started
|
||||||
duration time.Duration
|
duration time.Duration
|
||||||
|
|
@ -190,7 +191,6 @@ type T struct {
|
||||||
common
|
common
|
||||||
name string // Name of test.
|
name string // Name of test.
|
||||||
startParallel chan bool // Parallel tests will wait on this.
|
startParallel chan bool // Parallel tests will wait on this.
|
||||||
skipped bool // Test has been skipped.
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fail marks the function as having failed but continues execution.
|
// Fail marks the function as having failed but continues execution.
|
||||||
|
|
@ -277,6 +277,41 @@ func (c *common) Fatalf(format string, args ...interface{}) {
|
||||||
c.FailNow()
|
c.FailNow()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Skip is equivalent to Log followed by SkipNow.
|
||||||
|
func (c *common) Skip(args ...interface{}) {
|
||||||
|
c.log(fmt.Sprintln(args...))
|
||||||
|
c.SkipNow()
|
||||||
|
}
|
||||||
|
|
||||||
|
// Skipf is equivalent to Logf followed by SkipNow.
|
||||||
|
func (c *common) Skipf(format string, args ...interface{}) {
|
||||||
|
c.log(fmt.Sprintf(format, args...))
|
||||||
|
c.SkipNow()
|
||||||
|
}
|
||||||
|
|
||||||
|
// SkipNow marks the test as having been skipped and stops its execution.
|
||||||
|
// Execution will continue at the next test or benchmark. See also FailNow.
|
||||||
|
// SkipNow must be called from the goroutine running the test, not from
|
||||||
|
// other goroutines created during the test. Calling SkipNow does not stop
|
||||||
|
// those other goroutines.
|
||||||
|
func (c *common) SkipNow() {
|
||||||
|
c.skip()
|
||||||
|
runtime.Goexit()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *common) skip() {
|
||||||
|
c.mu.Lock()
|
||||||
|
defer c.mu.Unlock()
|
||||||
|
c.skipped = true
|
||||||
|
}
|
||||||
|
|
||||||
|
// Skipped reports whether the test was skipped.
|
||||||
|
func (c *common) Skipped() bool {
|
||||||
|
c.mu.RLock()
|
||||||
|
defer c.mu.RUnlock()
|
||||||
|
return c.skipped
|
||||||
|
}
|
||||||
|
|
||||||
// Parallel signals that this test is to be run in parallel with (and only with)
|
// Parallel signals that this test is to be run in parallel with (and only with)
|
||||||
// other parallel tests.
|
// other parallel tests.
|
||||||
func (t *T) Parallel() {
|
func (t *T) Parallel() {
|
||||||
|
|
@ -346,41 +381,6 @@ func (t *T) report() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Skip is equivalent to Log followed by SkipNow.
|
|
||||||
func (t *T) Skip(args ...interface{}) {
|
|
||||||
t.log(fmt.Sprintln(args...))
|
|
||||||
t.SkipNow()
|
|
||||||
}
|
|
||||||
|
|
||||||
// Skipf is equivalent to Logf followed by SkipNow.
|
|
||||||
func (t *T) Skipf(format string, args ...interface{}) {
|
|
||||||
t.log(fmt.Sprintf(format, args...))
|
|
||||||
t.SkipNow()
|
|
||||||
}
|
|
||||||
|
|
||||||
// SkipNow marks the test as having been skipped and stops its execution.
|
|
||||||
// Execution will continue at the next test or benchmark. See also FailNow.
|
|
||||||
// SkipNow must be called from the goroutine running the test, not from
|
|
||||||
// other goroutines created during the test. Calling SkipNow does not stop
|
|
||||||
// those other goroutines.
|
|
||||||
func (t *T) SkipNow() {
|
|
||||||
t.skip()
|
|
||||||
runtime.Goexit()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (t *T) skip() {
|
|
||||||
t.mu.Lock()
|
|
||||||
defer t.mu.Unlock()
|
|
||||||
t.skipped = true
|
|
||||||
}
|
|
||||||
|
|
||||||
// Skipped reports whether the test was skipped.
|
|
||||||
func (t *T) Skipped() bool {
|
|
||||||
t.mu.RLock()
|
|
||||||
defer t.mu.RUnlock()
|
|
||||||
return t.skipped
|
|
||||||
}
|
|
||||||
|
|
||||||
func RunTests(matchString func(pat, str string) (bool, error), tests []InternalTest) (ok bool) {
|
func RunTests(matchString func(pat, str string) (bool, error), tests []InternalTest) (ok bool) {
|
||||||
ok = true
|
ok = true
|
||||||
if len(tests) == 0 && !haveExamples {
|
if len(tests) == 0 && !haveExamples {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue