mirror of
https://github.com/golang/go
synced 2024-11-26 10:48:22 -07: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
@ -10,7 +10,7 @@
|
||||
// [a-z]) and serves to identify the test routine.
|
||||
// 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) {
|
||||
// if testing.Short() {
|
||||
// t.Skip("skipping test in short mode.")
|
||||
@ -130,9 +130,10 @@ var (
|
||||
// common holds the elements common between T and B and
|
||||
// captures common methods such as Errorf.
|
||||
type common struct {
|
||||
mu sync.RWMutex // guards output and failed
|
||||
output []byte // Output generated by test or benchmark.
|
||||
failed bool // Test or benchmark has failed.
|
||||
mu sync.RWMutex // guards output and failed
|
||||
output []byte // Output generated by test or benchmark.
|
||||
failed bool // Test or benchmark has failed.
|
||||
skipped bool // Test of benchmark has been skipped.
|
||||
|
||||
start time.Time // Time test or benchmark started
|
||||
duration time.Duration
|
||||
@ -190,7 +191,6 @@ type T struct {
|
||||
common
|
||||
name string // Name of test.
|
||||
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.
|
||||
@ -277,6 +277,41 @@ func (c *common) Fatalf(format string, args ...interface{}) {
|
||||
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)
|
||||
// other parallel tests.
|
||||
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) {
|
||||
ok = true
|
||||
if len(tests) == 0 && !haveExamples {
|
||||
|
Loading…
Reference in New Issue
Block a user