-
Notifications
You must be signed in to change notification settings - Fork 0
IDEA: Handle panics and make condition result explicit #1
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
Conversation
| } | ||
|
|
||
| func (c *CollectT) failed() bool { | ||
| func (c *CollectT) Failed() bool { |
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.
This should be OK to expose, since it is a very std. method and provides utility in tests where you want to reason on the collect status.
If not desired, I can track tests errors in another variable.
See new(assert.CollectT) further below, where I use it.
| select { | ||
| case <-timer.C: | ||
| return Fail(t, "Condition never satisfied", msgAndArgs...) | ||
| return Fail(t, ResultTimeout, msgAndArgs...) |
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.
same message as before
| // We can stop here and now, and mark test as finally failed with | ||
| // the same error message as the timeout case. | ||
| return Fail(t, "Condition never satisfied", msgAndArgs...) | ||
| return FailNow(t, v, msgAndArgs...) |
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.
two new messages, since these are two new ways of aborting the eventually
|
|
||
| func TestFailInsideEventuallyViaCommandLine(t *testing.T) { | ||
| t.Setenv("TestFailInsideEventually", "1") | ||
| cmd := exec.Command("go", "test", "-v", "-race", "-count=1", "-run", "^TestFailInsideEventually$") |
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.
Another clean alternative would be to store the log output from the always failing test as test fixure. And only analyze the fixure here.
The fixure can be create are part of the code gen.
I am not sure we can easily extend MockT to reproduce this.
2774c83 to
80bd5f0
Compare
Summary
Catch all possible results, incl. panics, that can happen to a condition inside the
Eventuallyimplementation and use a corresponding error message.This Demo PR in my contrib repo is an alternative implementation to stretchr#1809.
Changes
t.Errorfgo testtest to better analyze the failed test logs for thetesting.TlogMotivation
Related issues
Eventuallyon failed condition stretchr/testify#1809Eventuallyhangs on failed/abortedconditionstretchr/testify#1810