-
Notifications
You must be signed in to change notification settings - Fork 259
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
Add t.Helper
calls, test helpers linter
#1534
Conversation
555642f
to
6920f07
Compare
6920f07
to
2db0b8c
Compare
How does Do you believe that all functions being marked as "helper" will log with sufficient context that we don't need them in the log output? |
I believe it checks functions that use a
I think so, yes. For example, for our functional tests, we have
But |
My only concern is if there are valid cases where we will want a "helper" function to show up in the log output (e.g. if it is significant enough to have non-obvious control flow). If we add a linter it could be noisy and annoying in this case.
So really our test code context looks something like this:
Currently we are getting context of I certainly don't feel that this is a bad change though. If you've looked and believe this will help, I'm up to take it in. |
We can always override the linter adhoc ( Also, we can always add more context to the errors/logs so that we can distinguish where in This was motivated by the go (testing) wiki, but mostly my frustration with being unable to pinpoint where a test failed. I am not wed to it, but I do think this will help parsing error logs. |
Add `t.Helper()` calls to testing helpers so the correct test name and line number is shown during logs [ref](https://pkg.go.dev/testing#B.Helper). Add [`thelper`](https://github.com/kulti/thelper) linter to settings to make sure testing helpers correctly call `t.Helper`. Renamed `t testing.TB` to `tb testing.TB` to satisfy `thelper`. Signed-off-by: Hamza El-Saawy <hamzaelsaawy@microsoft.com>
2db0b8c
to
b43a764
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To be honest I don't really like when our helper functions directly call t.Fatal
instead of returning an error and letting the caller handle that. It also causes problems if that helper is called in a goroutine. I feel t.Fatal
should only be called by the Test function itself with all the error context.
But I am not sure if everyone agrees with that and so this is a good change fix the error logs.
I sorta agree, ideally the caller should handle it, but then testing code gets really repetitive with all the error handling, especially since the only path would be to call |
Add `t.Helper()` calls to testing helpers so the correct test name and line number is shown during logs [ref](https://pkg.go.dev/testing#B.Helper). Add [`thelper`](https://github.com/kulti/thelper) linter to settings to make sure testing helpers correctly call `t.Helper`. Renamed `t testing.TB` to `tb testing.TB` to satisfy `thelper`. Signed-off-by: Hamza El-Saawy <hamzaelsaawy@microsoft.com>
Add `t.Helper()` calls to testing helpers so the correct test name and line number is shown during logs [ref](https://pkg.go.dev/testing#B.Helper). Add [`thelper`](https://github.com/kulti/thelper) linter to settings to make sure testing helpers correctly call `t.Helper`. Renamed `t testing.TB` to `tb testing.TB` to satisfy `thelper`. Signed-off-by: Hamza El-Saawy <hamzaelsaawy@microsoft.com>
Add
t.Helper()
calls to testing helpers so the correct test name and line number is shown during logsref.
This allows logs to show the line number within a test that raised the error, rather than the line within the helper funciton that emitted the log (eg,
runpodsandbox_test.go:89
instead ofhelper_sandbox_test.go:43
)t.Log
,t.Error
, and co. use the call stack to track which function issued the logging statement. Therefore, even if a helper function does not log or fail, it should still callt.Helper
in case its callee's do.Add
thelper
linter to settings to make sure testing helpers correctly callt.Helper
.Renamed
t testing.TB
totb testing.TB
to satisfythelper
.Signed-off-by: Hamza El-Saawy hamzaelsaawy@microsoft.com