Commit a47d2b1
assert: collect.FailNow() should not panic (stretchr#1481)
## Summary
`collect.FailNow()` should exit goroutine without a panic to be usable
with `require` package.
## Changes
`collect.FailNow()` just does `runtime.Goexit()` instead of `panic()`.
For example `FailNow()` from `testing` package [behaves
similarly](https://cs.opensource.google/go/go/+/refs/tags/go1.21.2:src/testing/testing.go;l=973).
## Motivation
I just want `require` package to be usable with `EventuallyWithT` e.g. I
want this example to pass but it panics:
```go
package main
import (
"testing"
"time"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestRequireEventuallyWithT(t *testing.T) {
state := 0
require.EventuallyWithT(t, func(c *assert.CollectT) {
defer func() { state += 1 }()
require.True(c, state == 2)
}, 100*time.Millisecond, 10*time.Millisecond)
}
```
See https://go.dev/play/p/Oqd95IT7qxQ
## Related issues
Fixes stretchr#1396
Fixes stretchr#14571 parent 3cf5303 commit a47d2b1
3 files changed
Lines changed: 66 additions & 13 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1956 | 1956 | | |
1957 | 1957 | | |
1958 | 1958 | | |
| 1959 | + | |
| 1960 | + | |
| 1961 | + | |
1959 | 1962 | | |
1960 | 1963 | | |
1961 | 1964 | | |
| |||
1964 | 1967 | | |
1965 | 1968 | | |
1966 | 1969 | | |
1967 | | - | |
1968 | | - | |
1969 | | - | |
| 1970 | + | |
| 1971 | + | |
| 1972 | + | |
| 1973 | + | |
1970 | 1974 | | |
1971 | 1975 | | |
1972 | 1976 | | |
| |||
1979 | 1983 | | |
1980 | 1984 | | |
1981 | 1985 | | |
| 1986 | + | |
| 1987 | + | |
| 1988 | + | |
| 1989 | + | |
| 1990 | + | |
| 1991 | + | |
| 1992 | + | |
| 1993 | + | |
| 1994 | + | |
| 1995 | + | |
1982 | 1996 | | |
1983 | 1997 | | |
1984 | 1998 | | |
| |||
2003 | 2017 | | |
2004 | 2018 | | |
2005 | 2019 | | |
2006 | | - | |
| 2020 | + | |
2007 | 2021 | | |
2008 | 2022 | | |
2009 | 2023 | | |
| |||
2023 | 2037 | | |
2024 | 2038 | | |
2025 | 2039 | | |
2026 | | - | |
| 2040 | + | |
2027 | 2041 | | |
2028 | 2042 | | |
2029 | 2043 | | |
2030 | | - | |
2031 | | - | |
| 2044 | + | |
| 2045 | + | |
2032 | 2046 | | |
2033 | 2047 | | |
2034 | 2048 | | |
2035 | | - | |
| 2049 | + | |
2036 | 2050 | | |
2037 | 2051 | | |
2038 | 2052 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2923 | 2923 | | |
2924 | 2924 | | |
2925 | 2925 | | |
2926 | | - | |
| 2926 | + | |
2927 | 2927 | | |
2928 | | - | |
2929 | | - | |
2930 | | - | |
2931 | | - | |
| 2928 | + | |
| 2929 | + | |
2932 | 2930 | | |
2933 | 2931 | | |
2934 | 2932 | | |
2935 | 2933 | | |
| 2934 | + | |
2936 | 2935 | | |
2937 | 2936 | | |
2938 | 2937 | | |
| |||
2970 | 2969 | | |
2971 | 2970 | | |
2972 | 2971 | | |
| 2972 | + | |
| 2973 | + | |
| 2974 | + | |
| 2975 | + | |
| 2976 | + | |
| 2977 | + | |
| 2978 | + | |
| 2979 | + | |
| 2980 | + | |
| 2981 | + | |
| 2982 | + | |
2973 | 2983 | | |
2974 | 2984 | | |
2975 | 2985 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| 8 | + | |
| 9 | + | |
8 | 10 | | |
9 | 11 | | |
10 | 12 | | |
| |||
681 | 683 | | |
682 | 684 | | |
683 | 685 | | |
| 686 | + | |
| 687 | + | |
| 688 | + | |
| 689 | + | |
| 690 | + | |
| 691 | + | |
| 692 | + | |
| 693 | + | |
| 694 | + | |
| 695 | + | |
| 696 | + | |
| 697 | + | |
| 698 | + | |
| 699 | + | |
| 700 | + | |
| 701 | + | |
| 702 | + | |
| 703 | + | |
| 704 | + | |
| 705 | + | |
| 706 | + | |
| 707 | + | |
| 708 | + | |
| 709 | + | |
| 710 | + | |
| 711 | + | |
| 712 | + | |
0 commit comments