Skip to content

Commit 217001b

Browse files
authored
Merge pull request #59 from cockroachdb/fatal-msg
log position on fatal
2 parents a021364 + dd9fc3a commit 217001b

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

datadriven.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,10 +332,15 @@ func runDirective(t testing.TB, r *testDataReader, f func(testing.TB, *TestData)
332332

333333
d := &r.data
334334
actual := func() string {
335+
fReturned := false
335336
defer func() {
336337
if r := recover(); r != nil {
337338
t.Logf("\npanic during %s:\n%s\n", d.Pos, d.Input)
338339
panic(r)
340+
} else if !fReturned {
341+
// t.Fatal calls runtime.Goexit() which runs the defers but there is no
342+
// panic to recover.
343+
t.Logf("\nfatal during %s:\n%s\n", d.Pos, d.Input)
339344
}
340345
}()
341346

@@ -356,6 +361,7 @@ func runDirective(t testing.TB, r *testDataReader, f func(testing.TB, *TestData)
356361
}()
357362

358363
actual := f(t, d)
364+
fReturned = true
359365
if actual != "" && !strings.HasSuffix(actual, "\n") {
360366
actual += "\n"
361367
}
@@ -802,6 +808,9 @@ func (td TestData) Logf(tb testing.TB, format string, args ...interface{}) {
802808

803809
// Fatalf wraps a fatal testing error with test file position information, so
804810
// that it's easy to locate the source of the error.
811+
//
812+
// Note: tb.Fatalf can also be used directly; the test file position information
813+
// will be logged.
805814
func (td TestData) Fatalf(tb testing.TB, format string, args ...interface{}) {
806815
tb.Helper()
807816
tb.Fatalf("%s: %s", td.Pos, fmt.Sprintf(format, args...))

0 commit comments

Comments
 (0)