LGTM On Wed, Dec 19, 2012 at 2:46 PM, <adg@golang.org> wrote: > Reviewers: golang-dev_googlegroups.com, > ...
12 years, 4 months ago
(2012-12-19 23:04:31 UTC)
#2
LGTM
On Wed, Dec 19, 2012 at 2:46 PM, <adg@golang.org> wrote:
> Reviewers: golang-dev_googlegroups.com,
>
> Message:
> Hello golang-dev@googlegroups.com,
>
> I'd like you to review this change to
> https://code.google.com/p/go
>
>
> Description:
> testing: only capture stdout when running examples
>
> Fixes issue 4550.
>
> Please review this at
https://codereview.appspot.**com/6973048/<https://codereview.appspot.com/6973...
>
> Affected files:
> M src/cmd/go/doc.go
> M src/cmd/go/test.go
> M src/pkg/testing/example.go
>
>
> Index: src/cmd/go/doc.go
> ==============================**==============================**=======
> --- a/src/cmd/go/doc.go
> +++ b/src/cmd/go/doc.go
> @@ -76,7 +76,13 @@
> do not delete it when exiting.
> -x
> print the commands.
> + -race
> + enable data race detection.
> + Currently supported only on linux/amd64,
> + darwin/amd64 and windows/amd64.
>
> + -ccflags 'arg list'
> + arguments to pass on each 5c, 6c, or 8c compiler invocation
> -compiler name
> name of compiler to use, as in runtime.Compiler (gccgo or
> gc)
> -gccgoflags 'arg list'
> @@ -121,6 +127,7 @@
> DIR(.exe) from go build
> DIR.test(.exe) from go test -c
> MAINFILE(.exe) from go build MAINFILE.go
> + *.so from SWIG
>
> In the list, DIR represents the final path element of the
> directory, and MAINFILE is the base name of any Go source
> @@ -276,10 +283,10 @@
>
code.google.com/p/goauth2/**oauth<http://code.google.com/p/goauth2/oauth>
> code.google.com/p/sqlite
>
> -The -f flag specifies an alternate format for the list,
> -using the syntax of package template. The default output
> -is equivalent to -f '{{.ImportPath}}'. The struct
> -being passed to the template is:
> +The -f flag specifies an alternate format for the list, using the
> +syntax of package template. The default output is equivalent to -f
> +'{{.ImportPath}}'. One extra template function is available, "join",
> +which calls strings.Join. The struct being passed to the template is:
>
> type Package struct {
> Dir string // directory containing package sources
> @@ -679,6 +686,9 @@
> Run benchmarks matching the regular expression.
> By default, no benchmarks run.
>
> + -test.benchmem
> + Print memory allocation statistics for benchmarks.
> +
> -test.cpuprofile cpu.out
> Write a CPU profile to the specified file before exiting.
>
> @@ -694,6 +704,18 @@
> garbage collector, provided the test can run in the available
> memory without garbage collection.
>
> + -test.blockprofile block.out
> + Write a goroutine blocking profile to the specified file
> + when all tests are complete.
> +
> + -test.blockprofilerate n
> + Control the detail provided in goroutine blocking profiles by
> setting
> + runtime.BlockProfileRate to n. See 'godoc runtime
> BlockProfileRate'.
> + The profiler aims to sample, on average, one blocking event
> every
> + n nanoseconds the program spends blocked. By default,
> + if -test.blockprofile is set without this flag, all blocking
> events
> + are recorded, equivalent to -test.blockprofilerate=1.
> +
> -test.parallel n
> Allow parallel execution of test functions that call
> t.Parallel.
> The value of this flag is the maximum number of tests to run
> Index: src/cmd/go/test.go
> ==============================**==============================**=======
> --- a/src/cmd/go/test.go
> +++ b/src/cmd/go/test.go
> @@ -175,8 +175,8 @@
>
> func BenchmarkXXX(b *testing.B) { ... }
>
> -An example function is similar to a test function but, instead of using
> *testing.T
> -to report success or failure, prints output to os.Stdout and os.Stderr.
> +An example function is similar to a test function but, instead of using
> +*testing.T to report success or failure, prints output to os.Stdout.
> That output is compared against the function's "Output:" comment, which
> must be the last comment in the function body (see example below). An
> example with no such comment, or with no text after "Output:" is compiled
> Index: src/pkg/testing/example.go
> ==============================**==============================**=======
> --- a/src/pkg/testing/example.go
> +++ b/src/pkg/testing/example.go
> @@ -24,7 +24,7 @@
>
> var eg InternalExample
>
> - stdout, stderr := os.Stdout, os.Stderr
> + stdout := os.Stdout
>
> for _, eg = range examples {
> matched, err := matchString(*match, eg.Name)
> @@ -39,19 +39,19 @@
> fmt.Printf("=== RUN: %s\n", eg.Name)
> }
>
> - // capture stdout and stderr
> + // capture stdout
> r, w, err := os.Pipe()
> if err != nil {
> fmt.Fprintln(os.Stderr, err)
> os.Exit(1)
> }
> - os.Stdout, os.Stderr = w, w
> + os.Stdout = w
> outC := make(chan string)
> go func() {
> buf := new(bytes.Buffer)
> _, err := io.Copy(buf, r)
> if err != nil {
> - fmt.Fprintf(stderr, "testing: copying
> pipe: %v\n", err)
> + fmt.Fprintf(os.Stderr, "testing: copying
> pipe: %v\n", err)
> os.Exit(1)
> }
> outC <- buf.String()
> @@ -62,9 +62,9 @@
> eg.F()
> dt := time.Now().Sub(t0)
>
> - // close pipe, restore stdout/stderr, get output
> + // close pipe, restore stdout, get output
> w.Close()
> - os.Stdout, os.Stderr = stdout, stderr
> + os.Stdout = stdout
> out := <-outC
>
> // report any errors
>
>
>
Issue 6973048: code review 6973048: testing: only capture stdout when running examples
(Closed)
Created 12 years, 4 months ago by adg
Modified 12 years, 4 months ago
Reviewers: rsc
Base URL:
Comments: 0