cmd/go: drop -example, apply -run to examples

Once more, with feeling.

R=golang-dev, gri
CC=golang-dev
https://golang.org/cl/5698080
This commit is contained in:
Rob Pike 2012-02-28 08:33:06 +11:00
parent 1f5fde0915
commit ec15046a8d
4 changed files with 3 additions and 16 deletions

View file

@ -99,11 +99,6 @@ directory containing the package sources, has its own flags:
Run benchmarks matching the regular expression. Run benchmarks matching the regular expression.
By default, no benchmarks run. By default, no benchmarks run.
-test.example pattern
Run examples matching the regular expression.
By default, all examples run, but if -test.run is set,
no examples are run.
-test.cpuprofile cpu.out -test.cpuprofile cpu.out
Write a CPU profile to the specified file before exiting. Write a CPU profile to the specified file before exiting.

View file

@ -28,7 +28,6 @@ var usageMessage = `Usage of go test:
-benchtime=1: passes -test.benchtime to test -benchtime=1: passes -test.benchtime to test
-cpu="": passes -test.cpu to test -cpu="": passes -test.cpu to test
-cpuprofile="": passes -test.cpuprofile to test -cpuprofile="": passes -test.cpuprofile to test
-example="": passes -test.example to test
-memprofile="": passes -test.memprofile to test -memprofile="": passes -test.memprofile to test
-memprofilerate=0: passes -test.memprofilerate to test -memprofilerate=0: passes -test.memprofilerate to test
-parallel=0: passes -test.parallel to test -parallel=0: passes -test.parallel to test
@ -68,7 +67,6 @@ var testFlagDefn = []*testFlagSpec{
{name: "benchtime", passToTest: true}, {name: "benchtime", passToTest: true},
{name: "cpu", passToTest: true}, {name: "cpu", passToTest: true},
{name: "cpuprofile", passToTest: true}, {name: "cpuprofile", passToTest: true},
{name: "example", passToTest: true},
{name: "memprofile", passToTest: true}, {name: "memprofile", passToTest: true},
{name: "memprofilerate", passToTest: true}, {name: "memprofilerate", passToTest: true},
{name: "parallel", passToTest: true}, {name: "parallel", passToTest: true},

View file

@ -6,7 +6,6 @@ package testing
import ( import (
"bytes" "bytes"
"flag"
"fmt" "fmt"
"io" "io"
"os" "os"
@ -14,8 +13,6 @@ import (
"time" "time"
) )
var matchExamples = flag.String("test.example", "", "regular expression to select examples to run")
type InternalExample struct { type InternalExample struct {
Name string Name string
F func() F func()
@ -23,9 +20,6 @@ type InternalExample struct {
} }
func RunExamples(matchString func(pat, str string) (bool, error), examples []InternalExample) (ok bool) { func RunExamples(matchString func(pat, str string) (bool, error), examples []InternalExample) (ok bool) {
if *match != "" && *matchExamples == "" {
return // Don't run examples if testing is restricted: we're debugging.
}
ok = true ok = true
var eg InternalExample var eg InternalExample
@ -33,9 +27,9 @@ func RunExamples(matchString func(pat, str string) (bool, error), examples []Int
stdout, stderr := os.Stdout, os.Stderr stdout, stderr := os.Stdout, os.Stderr
for _, eg = range examples { for _, eg = range examples {
matched, err := matchString(*matchExamples, eg.Name) matched, err := matchString(*match, eg.Name)
if err != nil { if err != nil {
fmt.Fprintf(os.Stderr, "testing: invalid regexp for -test.example: %s\n", err) fmt.Fprintf(os.Stderr, "testing: invalid regexp for -test.run: %s\n", err)
os.Exit(1) os.Exit(1)
} }
if !matched { if !matched {

View file

@ -99,7 +99,7 @@ var (
// Report as tests are run; default is silent for success. // Report as tests are run; default is silent for success.
chatty = flag.Bool("test.v", false, "verbose: print additional output") chatty = flag.Bool("test.v", false, "verbose: print additional output")
match = flag.String("test.run", "", "regular expression to select tests to run") match = flag.String("test.run", "", "regular expression to select tests and examples to run")
memProfile = flag.String("test.memprofile", "", "write a memory profile to the named file after execution") memProfile = flag.String("test.memprofile", "", "write a memory profile to the named file after execution")
memProfileRate = flag.Int("test.memprofilerate", 0, "if >=0, sets runtime.MemProfileRate") memProfileRate = flag.Int("test.memprofilerate", 0, "if >=0, sets runtime.MemProfileRate")
cpuProfile = flag.String("test.cpuprofile", "", "write a cpu profile to the named file during execution") cpuProfile = flag.String("test.cpuprofile", "", "write a cpu profile to the named file during execution")