From 8ec54bb0b32e3dc5c757881272de07145bc8eafb Mon Sep 17 00:00:00 2001 From: Kyle Isom Date: Thu, 28 Apr 2016 14:14:48 -0700 Subject: [PATCH] Assert now supports core dumps. --- assert/assert.go | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/assert/assert.go b/assert/assert.go index b42f25b..1b3edc6 100644 --- a/assert/assert.go +++ b/assert/assert.go @@ -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,15 +23,25 @@ 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 { s := strings.Join(a, ", ") - fmt.Fprintln(os.Stderr, ":"+s) + fmt.Fprintln(os.Stderr, ": "+s) } else { fmt.Fprintf(os.Stderr, "\n") } + fmt.Fprintf(os.Stderr, "\t%s line %d\n", file, line) + os.Exit(1) } }