-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Mat Ryer
authored and
Mat Ryer
committed
Nov 14, 2014
1 parent
70e131d
commit 668c682
Showing
3 changed files
with
108 additions
and
47 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package is | ||
|
||
import ( | ||
"bytes" | ||
"fmt" | ||
"runtime" | ||
"strings" | ||
) | ||
|
||
// decorate prefixes the string with the file and line of the call site | ||
// and inserts the final newline if needed and indentation tabs for formatting. | ||
// this function was copied from the testing framework. | ||
func decorate(s string) string { | ||
_, file, line, ok := runtime.Caller(4) // decorate + log + public function. | ||
if ok { | ||
// Truncate file name at last file name separator. | ||
if index := strings.LastIndex(file, "/"); index >= 0 { | ||
file = file[index+1:] | ||
} else if index = strings.LastIndex(file, "\\"); index >= 0 { | ||
file = file[index+1:] | ||
} | ||
} else { | ||
file = "???" | ||
line = 1 | ||
} | ||
buf := new(bytes.Buffer) | ||
// Every line is indented at least one tab. | ||
buf.WriteByte('\t') | ||
fmt.Fprintf(buf, "%s:%d: ", file, line) | ||
lines := strings.Split(s, "\n") | ||
if l := len(lines); l > 1 && lines[l-1] == "" { | ||
lines = lines[:l-1] | ||
} | ||
for i, line := range lines { | ||
if i > 0 { | ||
// Second and subsequent lines are indented an extra tab. | ||
buf.WriteString("\n\t\t") | ||
} | ||
buf.WriteString(line) | ||
} | ||
buf.WriteByte('\n') | ||
return buf.String() | ||
} |
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
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