Created
January 10, 2012 05:58
-
-
Save bmatsuo/1587297 to your computer and use it in GitHub Desktop.
Golang "testing" file:line prefix
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
package main | |
import ( | |
"fmt" | |
"path/filepath" | |
"runtime" | |
"testing" | |
) | |
func flushTestConnections() {} | |
func closeTestConnections() {} | |
func die(t *testing.T, v ...interface{}) { | |
flushTestConnections() | |
closeTestConnections() | |
t.LogLine(false) | |
defer t.LogLine(true) | |
_, file, ln, _ := runtime.Caller(1) | |
t.Fatalf("%s:%d: %s", filepath.Base(file), ln, fmt.Sprint(v...)) | |
} | |
func TestDie(t *testing.T) { die(t, "now the line number makes sense") } |
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
package main | |
import "testing" | |
func flushTestConnections() {} | |
func closeTestConnections() {} | |
func die(t *testing.T, v ...interface{}) { | |
flushTestConnections() | |
closeTestConnections() | |
t.Fatal(v...) | |
} | |
func TestDie(t *testing.T) { die(t, "line number doesn't make sense") } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment