// [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:
+// func TestTimeConsuming(t *testing.T) {
+// if testing.Short() {
+// t.Skip("skipping test in short mode.")
+// }
+// ...
+// }
+//
// Functions of the form
// func BenchmarkXxx(*testing.B)
// are considered benchmarks, and are executed by the "go test" command when
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.
c.failed = true
}
-// Failed returns whether the function has failed.
+// Failed reports whether the function has failed.
func (c *common) Failed() bool {
c.mu.RLock()
defer c.mu.RUnlock()
if t.Failed() {
fmt.Printf(format, "FAIL", t.name, tstr, t.output)
} else if *chatty {
- fmt.Printf(format, "PASS", t.name, tstr, t.output)
+ if t.Skipped() {
+ fmt.Printf(format, "SKIP", t.name, tstr, t.output)
+ } else {
+ fmt.Printf(format, "PASS", t.name, tstr, t.output)
+ }
}
}
+// 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 function as having been skipped and stops its execution.
+// Execution will continue at the next test or benchmark. See also, t.FailNow.
+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 function 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 {