Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(11)

Delta Between Two Patch Sets: src/pkg/testing/testing.go

Issue 10264045: code review 10264045: cmd/go: write coverage to file, add percentage statistic (Closed)
Left Patch Set: Created 11 years, 9 months ago
Right Patch Set: diff -r f1e1d5d02b1c https://code.google.com/p/go Created 11 years, 9 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « src/pkg/testing/cover.go ('k') | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 // Copyright 2009 The Go Authors. All rights reserved. 1 // Copyright 2009 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style 2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file. 3 // license that can be found in the LICENSE file.
4 4
5 // Package testing provides support for automated testing of Go packages. 5 // Package testing provides support for automated testing of Go packages.
6 // It is intended to be used in concert with the ``go test'' command, which auto mates 6 // It is intended to be used in concert with the ``go test'' command, which auto mates
7 // execution of any function of the form 7 // execution of any function of the form
8 // func TestXxx(*testing.T) 8 // func TestXxx(*testing.T)
9 // where Xxx can be any alphanumeric string (but the first letter must not be in 9 // where Xxx can be any alphanumeric string (but the first letter must not be in
10 // [a-z]) and serves to identify the test routine. 10 // [a-z]) and serves to identify the test routine.
11 // These TestXxx routines should be declared within the package they are testing . 11 // These TestXxx routines should be declared within the package they are testing .
12 // 12 //
13 // Tests and benchmarks may be skipped if not applicable like this: 13 // Tests and benchmarks may be skipped if not applicable like this:
14 // func TestTimeConsuming(t *testing.T) { 14 // func TestTimeConsuming(t *testing.T) {
15 // if testing.Short() { 15 // if testing.Short() {
16 // t.Skip("skipping test in short mode.") 16 // t.Skip("skipping test in short mode.")
17 // } 17 // }
18 // ... 18 // ...
19 // } 19 // }
20 // 20 //
21 // Benchmarks 21 // Benchmarks
22 // 22 //
23 // Functions of the form 23 // Functions of the form
24 // func BenchmarkXxx(*testing.B) 24 // func BenchmarkXxx(*testing.B)
25 // are considered benchmarks, and are executed by the "go test" command when 25 // are considered benchmarks, and are executed by the "go test" command when
26 // the -test.bench flag is provided. Benchmarks are run sequentially. 26 // its -bench flag is provided. Benchmarks are run sequentially.
27 // 27 //
28 // For a description of the testing flags, see 28 // For a description of the testing flags, see
29 // http://golang.org/cmd/go/#Description_of_testing_flags. 29 // http://golang.org/cmd/go/#hdr-Description_of_testing_flags.
30 // 30 //
31 // A sample benchmark function looks like this: 31 // A sample benchmark function looks like this:
32 // func BenchmarkHello(b *testing.B) { 32 // func BenchmarkHello(b *testing.B) {
33 // for i := 0; i < b.N; i++ { 33 // for i := 0; i < b.N; i++ {
34 // fmt.Sprintf("hello") 34 // fmt.Sprintf("hello")
35 // } 35 // }
36 // } 36 // }
37 // 37 //
38 // The benchmark function must run the target code b.N times. 38 // The benchmark function must run the target code b.N times.
39 // The benchmark package will vary b.N until the benchmark function lasts 39 // The benchmark package will vary b.N until the benchmark function lasts
(...skipping 473 matching lines...) Expand 10 before | Expand all | Expand 10 after
513 if err != nil { 513 if err != nil {
514 fmt.Fprintf(os.Stderr, "testing: %s\n", err) 514 fmt.Fprintf(os.Stderr, "testing: %s\n", err)
515 os.Exit(2) 515 os.Exit(2)
516 } 516 }
517 if err = pprof.Lookup("block").WriteTo(f, 0); err != nil { 517 if err = pprof.Lookup("block").WriteTo(f, 0); err != nil {
518 fmt.Fprintf(os.Stderr, "testing: can't write %s: %s\n", *blockProfile, err) 518 fmt.Fprintf(os.Stderr, "testing: can't write %s: %s\n", *blockProfile, err)
519 os.Exit(2) 519 os.Exit(2)
520 } 520 }
521 f.Close() 521 f.Close()
522 } 522 }
523 » coverReport() 523 » if *cover != "" {
524 » » coverReport()
525 » }
524 } 526 }
525 527
526 // toOutputDir returns the file name relocated, if required, to outputDir. 528 // toOutputDir returns the file name relocated, if required, to outputDir.
527 // Simple implementation to avoid pulling in path/filepath. 529 // Simple implementation to avoid pulling in path/filepath.
528 func toOutputDir(path string) string { 530 func toOutputDir(path string) string {
529 if *outputDir == "" || path == "" { 531 if *outputDir == "" || path == "" {
530 return path 532 return path
531 } 533 }
532 if runtime.GOOS == "windows" { 534 if runtime.GOOS == "windows" {
533 // On Windows, it's clumsy, but we can be almost always correct 535 // On Windows, it's clumsy, but we can be almost always correct
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
579 for _, val := range strings.Split(*cpuListStr, ",") { 581 for _, val := range strings.Split(*cpuListStr, ",") {
580 cpu, err := strconv.Atoi(val) 582 cpu, err := strconv.Atoi(val)
581 if err != nil || cpu <= 0 { 583 if err != nil || cpu <= 0 {
582 fmt.Fprintf(os.Stderr, "testing: invalid value % q for -test.cpu", val) 584 fmt.Fprintf(os.Stderr, "testing: invalid value % q for -test.cpu", val)
583 os.Exit(1) 585 os.Exit(1)
584 } 586 }
585 cpuList = append(cpuList, cpu) 587 cpuList = append(cpuList, cpu)
586 } 588 }
587 } 589 }
588 } 590 }
LEFTRIGHT

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b