Skip to content
This repository has been archived by the owner on Sep 17, 2018. It is now read-only.

Commit

Permalink
cmd/go: drop -example, apply -run to examples
Browse files Browse the repository at this point in the history
Once more, with feeling.

R=golang-dev, gri
CC=golang-dev
http://codereview.appspot.com/5698080
  • Loading branch information
robpike committed Feb 27, 2012
1 parent 7814420 commit c8e4475
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 16 deletions.
5 changes: 0 additions & 5 deletions src/cmd/go/test.go
Expand Up @@ -99,11 +99,6 @@ directory containing the package sources, has its own flags:
Run benchmarks matching the regular expression.
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
Write a CPU profile to the specified file before exiting.
Expand Down
2 changes: 0 additions & 2 deletions src/cmd/go/testflag.go
Expand Up @@ -28,7 +28,6 @@ var usageMessage = `Usage of go test:
-benchtime=1: passes -test.benchtime to test
-cpu="": passes -test.cpu to test
-cpuprofile="": passes -test.cpuprofile to test
-example="": passes -test.example to test
-memprofile="": passes -test.memprofile to test
-memprofilerate=0: passes -test.memprofilerate to test
-parallel=0: passes -test.parallel to test
Expand Down Expand Up @@ -68,7 +67,6 @@ var testFlagDefn = []*testFlagSpec{
{name: "benchtime", passToTest: true},
{name: "cpu", passToTest: true},
{name: "cpuprofile", passToTest: true},
{name: "example", passToTest: true},
{name: "memprofile", passToTest: true},
{name: "memprofilerate", passToTest: true},
{name: "parallel", passToTest: true},
Expand Down
10 changes: 2 additions & 8 deletions src/pkg/testing/example.go
Expand Up @@ -6,36 +6,30 @@ package testing

import (
"bytes"
"flag"
"fmt"
"io"
"os"
"strings"
"time"
)

var matchExamples = flag.String("test.example", "", "regular expression to select examples to run")

type InternalExample struct {
Name string
F func()
Output string
}

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

var eg InternalExample

stdout, stderr := os.Stdout, os.Stderr

for _, eg = range examples {
matched, err := matchString(*matchExamples, eg.Name)
matched, err := matchString(*match, eg.Name)
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)
}
if !matched {
Expand Down
2 changes: 1 addition & 1 deletion src/pkg/testing/testing.go
Expand Up @@ -99,7 +99,7 @@ var (

// Report as tests are run; default is silent for success.
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")
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")
Expand Down

0 comments on commit c8e4475

Please sign in to comment.