testing: t.Fail should report the line on which the failure occurred #26720
Comments
It would be nice to do better here but what you seem to suggest seems impossible. At the time that the goroutine calls But it does seem possible to have |
Taking a look at this at the contributor workshop in London... Will update again with more info |
Change https://golang.org/cl/127596 mentions this issue: |
Hello @ianlancetaylor is there a chance of a code review on the cl in https://go-review.googlesource.com/c/127596/ or pointing who would be the right person to do a code review? This being my first one I'd like to know I've got it "right" |
I had some code that looked like this:
I know the above code is buggy because its calling
t.Error
from a goroutine that lasts longer than the test goroutine and sot.Error
will panic int.Fail
. However, the original test was complex and no one saw this coming.The issue I was having is that the error call is never reported.
t.Error
panics and then this is recovered and logged but the individual test within which this happened is not marked as failed. Only the parent test is marked as failed. This made the test very hard to debug as there would be no line on which the failure occurred.So if you run this code, you'll get:
Which made me scratch my head for quite a while.
I want to repeat that I know this is a violation of the docs and so maybe shouldn't be fixed but at the same time, I think that it would be much easier to detect such failures if
t.Fail
reported the line number at which it was called. This would have made the above issue easy to debug and I can imagine a line number reported byt.Fail
to be useful in other scenarios as well.The text was updated successfully, but these errors were encountered: