Commit Graph

9 Commits (b074924938f86d417f1c9a845c7e8b0784d7f937)

Author SHA1 Message Date
Vladimir Kochnev b074924938
assert: collect.FailNow() should not panic (#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 https://github.com/stretchr/testify/issues/1396
Fixes https://github.com/stretchr/testify/issues/1457
2024-06-13 22:09:51 +02:00
Alun Evans 6990a05d54 Add ErrorContains 2021-01-16 12:32:05 +11:00
Ivo van der Wijk ac1463f956 Implement NotEqualValues 2020-05-27 08:39:56 +10:00
Nobuhiro MIKI 0224ef258e Add YAMLEq to assert that two YAML strings are equivalent 2019-07-11 17:50:32 -06:00
Cory Bennett c679ae2cc0 add function aliases for common assert and requires function signatures to make table driven tests easier 2018-03-19 22:34:59 +00:00
Julian Cooper 7f6cb13c5c split JSONEq tests into individual assertions from one monolithic test 2015-10-13 13:36:47 -07:00
Julian Cooper 930ea90dbd Added assertion/requirement that checks if two JSON strings represent equivalent objects 2015-09-23 10:34:52 -07:00
Will Faught 8512261d41 Add Zero and NotZero assertions and requirements
Zero returns true if the value equals the value's type's zero value.

NotZero returns the opposite of Zero.
2015-08-24 15:53:36 -07:00
Anatoly Scheglov f6376e8a31 add the 'require' package 2014-07-16 17:30:01 +04:00