-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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 support for testing.T.Run() metadata to ParseError() #1262
Comments
The issue is that the line number is always the same for all sub tests. It'll not change. So I'm not sure how helpful the fix will be. For example if I add more strings to the test table it'll be like:
They are all on the same line and therefore quickfix will not jump between these cases. I assume in your case each sub case has a different error message, so you wan't to see which case fails, rather then jumping to the error itself ? |
So I've looked into this more, but it's not easy and it's a limitation of the package m
import "testing"
func TestEven(t *testing.T) {
for _, v := range []string{"a", "b"} {
t.Run("sub-case "+v, func(t *testing.T) {
t.Errorf("this is a sub error")
t.Errorf("this is a sub error 2")
})
}
t.Errorf("this is normal error")
} Here if you run
So now a question. How are you going to distinguish the line Here you can clearly see that the line I'm not sure how to fix without changing the way |
An improvement would be this proposal which is not implemented yet. It would solve a lot of our problems: golang/go#2981 |
I've posted this on twitter already but will post here too for visibility. It looks like the sub errors are prefixed with 4 spaces and a tab, whereas the normal errors are prefixed with just a tab. My terminal seems to line the text up, but when viewing it in a vim buffer with It might be a fairly hacky way to tell the difference, but it's at least possible. |
Add an option to prepend the test name to test errors and log messages. Fixes fatih#1262
Add an option to prepend the test name to test errors and log messages. Fixes fatih#1262
Add an option to prepend the test name to test errors and log messages. Fixes fatih#1262
Add an option to prepend the test name to test errors and log messages. Fixes fatih#1262
prepend test name to test errors Add an option to prepend the test name to test errors and log messages. Fixes #1262
Table-driven tests iterate over a table of inputs to permute a single test to cover multiple sub-cases. To accomplish table-drive tests, tests use t.Run() to execute tests; the pattern is:
In this pattern, testing produces output that includes
subcase_name
in the FAIL: message:The output of these tests causes
ParseError()
to misbehave in interesting ways.Behavior
On the command line:
Note that
testing.T.Run()
is adding the test name to the FAIL message.ParseError()
adds the context for every error except for the first, including when there is only a single error. It may be undesirable that the context is added in the first case, but exclusion of the test name metadata makes errors untraceable. Copied from within nvim:If there are many sub-cases, it is not possible to tell which sub-case caused the first failure -- including when only a single sub-case fails.
Ideally,
ParseErrors()
would:foobar_test.go|8|sub-case_b this is an error
Steps to reproduce:
:GoTest
Configuration
I can provide if necessary; however, I'm pretty sure this is because
ParseErrors()
was not written with this use case oftesting
in mind.The text was updated successfully, but these errors were encountered: