Skip to content

testing: add stacktrace to Fatalf and similar #30973

@bep

Description

@bep

Currently, when you have failed test, the filename+linenumber you get is where the assertion failed. This is suboptimal in situations where you do your assertions in some common test helper, e.g. assertMyCustomFormat(...).

I have created myself a function to work around this problem (see below), but it would be great if Go could do this out of the box. It would make the test failure output a little more wordy, but it is a time saver.

func Fatalf(t testing.TB, format string, args ...interface{}) {
	trace := stackTrace()
	format = format + "\n%s"
	args = append(args, trace)
	t.Fatalf(format, args...)
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions