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 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

This comment has been minimized.

Copy link
Member

@mvdan mvdan commented Mar 21, 2019

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

@bep

This comment has been minimized.

Copy link
Contributor Author

@bep 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 Mar 21, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.