Assert now supports core dumps.

This commit is contained in:
Kyle Isom 2016-04-28 14:14:48 -07:00
parent a01b7ae657
commit 8ec54bb0b3
1 changed files with 14 additions and 1 deletions

View File

@ -3,6 +3,9 @@
//
// The T variants operating on *testing.T values; instead of killing
// the program, they call the Fatal method.
//
// If GOTRACEBACK is set to enable coredumps, assertions will generate
// coredumps.
package assert
import (
@ -20,6 +23,14 @@ func die(what string, a ...string) {
_, file, line, ok := runtime.Caller(2)
if !ok {
panic(what)
}
if os.Getenv("GOTRACEBACK") == "crash" {
s := strings.Join(a, ", ")
if len(s) > 0 {
s = ": " + s
}
panic(what + s)
} else {
fmt.Fprintf(os.Stderr, "%s", what)
if len(a) > 0 {
@ -28,7 +39,9 @@ func die(what string, a ...string) {
} else {
fmt.Fprintf(os.Stderr, "\n")
}
fmt.Fprintf(os.Stderr, "\t%s line %d\n", file, line)
os.Exit(1)
}
}