Skip to content

Instantly share code, notes, and snippets.

@bmatsuo
Created January 10, 2012 05:58
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bmatsuo/1587297 to your computer and use it in GitHub Desktop.
Save bmatsuo/1587297 to your computer and use it in GitHub Desktop.
Golang "testing" file:line prefix
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") }
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