testing: add Skip/Skipf
testing: 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

R=adg, rsc, r, n13m3y3r
CC=golang-dev, minux.ma
https://codereview.appspot.com/6501094

scirelli/scirelli-go,webfd/go-zh,glycerine/jeaten-go-arrayof-structof,scirelli/scirelli-go,glycerine/jeaten-go-arrayof-structof,bryanxu/go-zh,scirelli/scirelli-go,d0f/go-zh,bryanxu/go-zh,glycerine/jeaten-go-arrayof-structof,glycerine/jeaten-go-arrayof-structof,mhennings/marcohennings-go,mhennings/marcohennings-go,webfd/go-zh,mhennings/marcohennings-go,rdp/rogerpack2005-golang,d0f/go-zh,mhennings/marcohennings-go,rdp/rogerpack2005-golang,sanjosh/sanjos100-tipc,webfd/go-zh,sanjosh/sanjos100-tipc,sanjosh/sanjos100-tipc,bryanxu/go-zh,sanjosh/sanjos100-tipc,bryanxu/go-zh,bryanxu/go-zh,bryanxu/go-zh,d0f/go-zh,rdp/rogerpack2005-golang,scirelli/scirelli-go,webfd/go-zh,webfd/go-zh,rdp/rogerpack2005-golang,sanjosh/sanjos100-tipc,mhennings/marcohennings-go,d0f/go-zh,scirelli/scirelli-go,webfd/go-zh,rdp/rogerpack2005-golang,webfd/go-zh,rdp/rogerpack2005-golang,sanjosh/sanjos100-tipc,scirelli/scirelli-go,scirelli/scirelli-go,webfd/go-zh,mhennings/marcohennings-go,bryanxu/go-zh,glycerine/jeaten-go-arrayof-structof,mhennings/marcohennings-go,sanjosh/sanjos100-tipc,glycerine/jeaten-go-arrayof-structof,rdp/rogerpack2005-golang,sanjosh/sanjos100-tipc,d0f/go-zh,rdp/rogerpack2005-golang,glycerine/jeaten-go-arrayof-structof,scirelli/scirelli-go,mhennings/marcohennings-go,d0f/go-zh,bryanxu/go-zh,d0f/go-zh,glycerine/jeaten-go-arrayof-structof,d0f/go-zh