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

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

Issue 13469045: code review 13469045: testing: strip per-line whitespace during example outpu... (Closed)
Left Patch Set: diff -r 5981425e55ce https://code.google.com/p/go Created 10 years, 6 months ago
Right Patch Set: diff -r 24bc2c8febe3 https://code.google.com/p/go Created 10 years, 3 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 | « no previous file | src/pkg/testing/example_test.go » ('j') | 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 5 package testing
6 6
7 import ( 7 import (
8 "bytes" 8 "bytes"
9 "fmt" 9 "fmt"
10 "io" 10 "io"
(...skipping 24 matching lines...) Expand all
35 } 35 }
36 if !runExample(eg) { 36 if !runExample(eg) {
37 ok = false 37 ok = false
38 } 38 }
39 } 39 }
40 40
41 return 41 return
42 } 42 }
43 43
44 // trimLines trims leading and trailing whitespace from all 44 // trimLines trims leading and trailing whitespace from all
45 // lines in s and from s itself. A single \n is used to 45 // lines in s and from s itself. \n is used to separate lines
46 // separate lines in the returned value. 46 // in the returned value.
47 func trimLines(s string) string { 47 func trimLines(s string) string {
48 » // trim space from s before trimming individual lines; 48 » // Trim space from s before trimming individual lines;
49 » // this handles leading/trailing blank lines. 49 » // this removes leading and trailing blank lines.
50 s = strings.TrimSpace(s) 50 s = strings.TrimSpace(s)
51 lines := strings.Split(s, "\n") 51 lines := strings.Split(s, "\n")
52 trimmed := make([]string, len(lines))
53 for i, l := range lines { 52 for i, l := range lines {
54 » » trimmed[i] = strings.TrimSpace(l) 53 » » lines[i] = strings.TrimSpace(l)
55 } 54 }
56 » return strings.Join(trimmed, "\n") 55 » return strings.Join(lines, "\n")
57 } 56 }
58 57
59 func runExample(eg InternalExample) (ok bool) { 58 func runExample(eg InternalExample) (ok bool) {
60 if *chatty { 59 if *chatty {
61 fmt.Printf("=== RUN: %s\n", eg.Name) 60 fmt.Printf("=== RUN: %s\n", eg.Name)
62 } 61 }
63 62
64 // Capture stdout. 63 // Capture stdout.
65 stdout := os.Stdout 64 stdout := os.Stdout
66 r, w, err := os.Pipe() 65 r, w, err := os.Pipe()
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 } 105 }
107 if err != nil { 106 if err != nil {
108 panic(err) 107 panic(err)
109 } 108 }
110 }() 109 }()
111 110
112 // Run example. 111 // Run example.
113 eg.F() 112 eg.F()
114 return 113 return
115 } 114 }
LEFTRIGHT

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