Last active
December 10, 2015 18:28
-
-
Save donovanhide/4474425 to your computer and use it in GitHub Desktop.
Patch for testing.go to align multi-line log output of tests. Makes it easier to read and copy and paste
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- a/src/pkg/testing/testing.go Sun Dec 30 12:01:53 2012 -0500 | |
+++ b/src/pkg/testing/testing.go Mon Jan 07 11:43:25 2013 +0000 | |
@@ -91,6 +91,7 @@ | |
"strings" | |
"sync" | |
"time" | |
+ "unicode/utf8" | |
) | |
var ( | |
@@ -157,21 +158,23 @@ | |
line = 1 | |
} | |
buf := new(bytes.Buffer) | |
- fmt.Fprintf(buf, "%s:%d: ", file, line) | |
+ source := fmt.Sprintf("%s:%d: ", file, line) | |
+ buf.WriteString(source) | |
lines := strings.Split(s, "\n") | |
if l := len(lines); l > 1 && lines[l-1] == "" { | |
lines = lines[:l-1] | |
} | |
+ | |
+ // Round up the number of tabs required and add one to match first line | |
+ tabs := ((utf8.RuneCountInString(source) + 7) / 8) + 1 | |
+ align := "\n" + strings.Repeat("\t", tabs) | |
for i, line := range lines { | |
- if i > 0 { | |
- buf.WriteByte('\n') | |
- } | |
- // Every line is indented at least one tab. | |
- buf.WriteByte('\t') | |
- if i > 0 { | |
- // Second and subsequent lines are indented an extra tab. | |
- buf.WriteByte('\t') | |
+ switch { | |
+ case i == 0: | |
+ buf.WriteByte('\t') // First line is indented at least one tab | |
+ case i > 0: | |
+ buf.WriteString(align) // Subsequent lines are aligned with the first | |
} | |
buf.WriteString(line) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment