Descriptiontesting: add Skip/Skipf
This proposal adds two methods to *testing.T, Skip(string) and Skipf(format, args...). The intent is to replace the existing log and return idiom which currently has 97 cases in the standard library. A simple example of Skip would be:
func TestSomethingLong(t *testing.T) {
if testing.Short() {
t.Skip("skipping test in short mode.")
// not reached
}
... time consuming work
}
Additionally tests can be skipped anywhere a *testing.T is present. An example adapted from the go.crypto/ssh/test package would be:
// setup performs some before test action and returns a func()
// which should be defered by the caller for cleanup.
func setup(t *testing.T) func() {
...
cmd := exec.Command("sshd", "-f", configfile, "-i")
if err := cmd.Run(); err != nil {
t.Skipf("could not execute mock ssh server: %v", err)
}
...
return func() {
// stop subprocess and cleanup
}
}
func TestDialMockServer(t *testing.T) {
cleanup := setup(t)
defer cleanup()
...
}
In verbose mode tests that are skipped are now reported as a SKIP, rather than PASS.
Link to discussion: https://groups.google.com/d/topic/golang-nuts/BqorNARzt4U/discussion
Patch Set 1 #Patch Set 2 : diff -r 91c1c2d6e2ff https://code.google.com/p/go #Patch Set 3 : diff -r 9dacae220eca https://code.google.com/p/go #
Total comments: 1
Patch Set 4 : diff -r 9dacae220eca https://code.google.com/p/go #Patch Set 5 : diff -r 9dacae220eca https://code.google.com/p/go #Patch Set 6 : diff -r 073d912321cc https://code.google.com/p/go #Patch Set 7 : diff -r 073d912321cc https://code.google.com/p/go #
Total comments: 2
Patch Set 8 : diff -r 9439d60e0f96 https://go.googlecode.com/hg/ #Patch Set 9 : diff -r 9439d60e0f96 https://go.googlecode.com/hg/ #Patch Set 10 : diff -r 9439d60e0f96 https://go.googlecode.com/hg/ #MessagesTotal messages: 12
|