Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

testing: add stacktrace to Fatalf and similar #30973

Closed
bep opened this issue Mar 21, 2019 · 2 comments
Closed

testing: add stacktrace to Fatalf and similar #30973

bep opened this issue Mar 21, 2019 · 2 comments

Comments

@bep
Copy link
Contributor

bep commented Mar 21, 2019

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...)
}
@mvdan
Copy link
Member

mvdan commented Mar 21, 2019

If you write helper funcs like assertMyCustomFormat, why not use t.Helper()?

@bep
Copy link
Contributor Author

bep commented Mar 21, 2019

If you write helper funcs like assertMyCustomFormat, why not use t.Helper()?

Because I didn't know about it ...

Thanks!

@bep bep closed this as completed Mar 21, 2019
@golang golang locked and limited conversation to collaborators Mar 20, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants