summaryrefslogtreecommitdiff
path: root/src/lib/testing.go
diff options
context:
space:
mode:
authorRob Pike <r@golang.org>2008-11-20 18:10:46 -0800
committerRob Pike <r@golang.org>2008-11-20 18:10:46 -0800
commit1941a40b4f27e4df425553c2d65e0c7946cda85f (patch)
tree503280510ec697a3ffa9b34286cf019e82a453a1 /src/lib/testing.go
parentb5470d946e86ac61f98bb41f63767ec9248af7a4 (diff)
downloadgolang-1941a40b4f27e4df425553c2d65e0c7946cda85f.tar.gz
automatically add tabs after newlines
R=gri DELTA=12 (10 added, 0 deleted, 2 changed) OCL=19758 CL=19758
Diffstat (limited to 'src/lib/testing.go')
-rw-r--r--src/lib/testing.go14
1 files changed, 12 insertions, 2 deletions
diff --git a/src/lib/testing.go b/src/lib/testing.go
index 3a95d61d7..0bcdcffcd 100644
--- a/src/lib/testing.go
+++ b/src/lib/testing.go
@@ -14,6 +14,16 @@ func init() {
flag.Bool("chatty", false, &chatty, "chatty");
}
+// Insert tabs after newlines - but not the last one
+func Tabify(s string) string {
+ for i := 0; i < len(s) - 1; i++ { // -1 because if last char is newline, don't bother
+ if s[i] == '\n' {
+ return s[0:i+1] + "\t" + Tabify(s[i+1:len(s)]);
+ }
+ }
+ return s
+}
+
export type T struct {
errors string;
failed bool;
@@ -31,11 +41,11 @@ func (t *T) FailNow() {
}
func (t *T) Log(args ...) {
- t.errors += "\t" + fmt.sprintln(args);
+ t.errors += "\t" + Tabify(fmt.sprintln(args));
}
func (t *T) Logf(format string, args ...) {
- t.errors += fmt.sprintf("\t" + format, args);
+ t.errors += Tabify(fmt.sprintf("\t" + format, args));
l := len(t.errors);
if l > 0 && t.errors[l-1] != '\n' {
t.errors += "\n"