Commit Graph

94 Commits (master)

Author SHA1 Message Date
Grégoire Paris 89086b0757
Document consequences of calling t.FailNow()
These comments are adapted from t.FailNow()'s own documentation.

Closes #1701
2025-03-19 20:50:44 +01:00
Bracken f9ccf14f6f
Merge branch 'master' into generate-better-comments-for-require-package 2024-10-23 23:36:08 +01:00
Simon Schulte 3b2754b72f remove failure note on require-comments 2024-10-15 13:54:51 +02:00
Pål Sivertsen f844b269df Review: Expand NotErrorAs func docs
https://github.com/stretchr/testify/pull/1129#discussion_r1787490770
2024-10-04 12:43:45 +02:00
Pål Sivertsen dc100b1be3 Review: Drop doc line and fix typo
Review feedback:
https://github.com/stretchr/testify/pull/1129#discussion_r1786495803
2024-10-04 12:43:45 +02:00
Pal Sivertsen 3380867632 Add NotErrorAs assertion
The library already had assertions for `ErrorIs`, `NotErrorIs` and
`ErrorAs`. This commit adds the `NotErrorAs` assertion which is the
inverse of `ErrorAs`.
2024-10-04 12:43:45 +02:00
Simon Schulte bc04bb85a2
Merge branch 'master' into generate-better-comments-for-require-package 2024-06-17 09:16:44 +02:00
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
Simon Schulte f71de4a756 updated message 2024-06-13 18:02:19 +02:00
Simon Schulte 592e4e3c00
Merge branch 'stretchr:master' into generate-better-comments-for-require-package 2024-06-13 18:01:22 +02:00
Simon Schulte 044c46a89f
Update require.go.tmpl
Co-authored-by: Olivier Mengué <dolmen@cpan.org>
2024-06-13 15:40:29 +02:00
Maria Ines Parnisari 84619f5c3c
fix: grammar in godoc for NotErrorIs(f) functions (#1607)
Grammar fixes in doc: _asserts that at none_ -> _asserts that none_

$ grep 'that at none' */*.go
assert/assertion_format.go:// NotErrorIsf asserts that at none of the errors in err's chain matches target.
assert/assertion_forward.go:// NotErrorIs asserts that at none of the errors in err's chain matches target.
assert/assertion_forward.go:// NotErrorIsf asserts that at none of the errors in err's chain matches target.
assert/assertions.go:// NotErrorIs asserts that at none of the errors in err's chain matches target.
require/require.go:// NotErrorIs asserts that at none of the errors in err's chain matches target.
require/require.go:// NotErrorIsf asserts that at none of the errors in err's chain matches target.
require/require_forward.go:// NotErrorIs asserts that at none of the errors in err's chain matches target.
require/require_forward.go:// NotErrorIsf asserts that at none of the errors in err's chain matches target.
2024-06-13 14:57:39 +02:00
Simon Schulte 9326036bf5 Generate better comments for require package
The comments for the require package were just copied over
from the assert package when generating the functions.
This could lead to confusion because
1. The code-examples were showing examples using the
assert package instead of the require package
2. The function-documentation was not mentioning that
the functions were calling `t.FailNow()` which is some
critical information when using this package.
2024-06-13 06:52:14 +02:00
hendry.wiranto 7af3ed34c2 feat: new assertion NotElementsMatch 2024-05-28 21:36:34 +07:00
Bracken Dawson 32766084e4
Correctly document EqualValues behavior 2024-04-29 13:49:40 +01:00
Jonathan Crowther 4ec7678c61 Correct the EventuallyWithT and EventuallyWithTf example 2024-04-12 14:19:10 -04:00
Olivier Mengué 85fabe7c5c assert: make tHelper a type alias
The tHelper interface is defined only for internal usage. We don't need
a "hard" type for it as we don't define methods on it. Let's make is
just a alias to the anonymous interface it represents.

Note: we are already using type aliases elswhere, and type aliases were
introduced a long time ago in Go 1.9.
2024-03-03 18:29:24 +01:00
Bracken 5b6926d686
Merge pull request #1385 from hslatman/not-implements
Add `NotImplements` and variants
2024-02-28 16:02:08 +00:00
Justin Chadwell 5105b61304 Add map support doc comments to Subset and NotSubset
Signed-off-by: Justin Chadwell <me@jedevc.com>
2023-10-31 00:24:17 +01:00
Herman Slatman 4e56e1ee06 Add `NotImplements` and variants 2023-10-16 14:27:51 +02:00
Olivier Mengué 486eb6f08c
Merge pull request #1406 from dolmen-go/use-std-header-for-generated-code
codegen: use standard header for generated files
2023-07-22 08:51:09 +02:00
Oleksandr Redko 37814a1755 docs: Fix typos in tests and comments 2023-07-06 13:14:39 +03:00
Olivier Mengué 5ca0755b51 codegen: use standard header for generated files
Use the standard header in generated Go sources.
See https://go.dev/s/generatedcode.
2023-07-02 21:06:15 +02:00
Harald Nordgren 4c93d8f201
EqualExportedValues: Handle nested pointer, slice and map fields (#1379)
* EqualExportedValues: Handle pointer and slice fields

* Update assert/assertions.go

Co-authored-by: Michael Pu <michael.pu123@gmail.com>

* Reduce redundant calls to 'copyExportedFields'

* Update comments

* Add support for maps

* Update Go version support to 1.19 and onward

* Re-generate after rebasing

---------

Co-authored-by: Michael Pu <michael.pu123@gmail.com>
2023-05-11 07:42:04 +10:00
Tobias Krischer 4b2f4d2bcf
add EventuallyWithT assertion (#1264)
* add EventuallyWithT assertion

* Change "EventuallyWithT" condition acceptance to no-errors raised

This change updates the "EventuallyWithT" assertion variants (regular, formatted,
requirement) to consider a condition as "met" if no assertion errors were raised
in a tick.

This allows to write easier conditions which simply contain assertions, without
needing to return a bool. The equivalent of a condition returning true in the
previous implementation would be a a condition with a single "assert.True(..)" call.

* Declare the "Collect.Copy(T)" method as a testing helper

* run go generate

---------

Co-authored-by: Arik Kfir <arik@kfirs.com>
2023-05-10 06:58:49 +10:00
Michael Pu c5fc9d6b6b
Compare public elements of struct (#1309)
* Implement checking only exported fields

Co-authored-by: Anthony Chang <anthony-chang@users.noreply.github.com>

* Update comment

* Run go generate

* Make compatiable with Go 1.16.5

* Fix go generate files

* Fix white space changes

* Fix whitespace changes

* Fix whitespace changes in gogenerate files

---------

Co-authored-by: Anthony Chang <anthony-chang@users.noreply.github.com>
2023-03-14 22:01:35 +10:00
Ruan Moolman 2fab6dffcf
Add WithinTimeRange method (#1188)
* Add WithinTimeRange method

* Run ./.ci.generate.sh

* Rename WithinTimeRange to WithinRange

* Rename WithinRange expected parameter to actual

* Capitalise start parameter at start of error message

* Improve WithinRange example
2022-06-28 21:14:39 +10:00
Alun Evans 6990a05d54 Add ErrorContains 2021-01-16 12:32:05 +11:00
Masaya Hayashi dc8af7208c add generated code for positive/negative assertion 2020-11-03 21:37:46 +11:00
alexpantyukhin c74c0d3a7f add fnctions into requres 2020-08-14 20:45:51 +10:00
Pal Sivertsen 95a9d909e9 Add wrapper functions for errors Is and As funcs
This commit adds wrapper functions for Is and As functions from the
errors package.
2020-07-20 20:40:44 +10:00
Boyan e2b269ecc5 This reverts commit 2adb7b54b7. 2020-06-05 20:47:15 +10:00
Boyan 656132404a This reverts commit 484fff1ace. 2020-06-05 20:47:15 +10:00
Ivo van der Wijk 004e3cb722 commit generated files 2020-05-27 08:39:56 +10:00
Ivo van der Wijk ac1463f956 Implement NotEqualValues 2020-05-27 08:39:56 +10:00
Matt Gorzka e72b029e2a new regex 2020-05-14 20:01:26 +10:00
gohargasparyan 484fff1ace didn't notice should run go generate 2020-05-04 07:47:34 +10:00
gohargasparyan 2adb7b54b7 correct missing parameters in require and require_forward 2020-05-04 07:47:34 +10:00
Martijn 28b7455875 Ran go generate ./... 2020-04-06 07:42:56 +10:00
Torkel Rogstad 17a1e1d4bf Add Never assertion
Never asserts that a conditon isn't met within a given timeframe.
2020-01-29 09:11:59 +11:00
Boyan Soubachov 22d5528225 Fix InDelta docstring
* Fixed the docstring for the InDelta function.
2019-12-23 07:31:11 -07:00
Boyan Soubachov 7b3a490010 Rename 2019-12-12 12:41:57 -07:00
Boyan Soubachov 937e12391f Added negative dir and file tests
* Added NotFileExists test
* Added NotDirExists test
* Cleaned-up some comment formatting
2019-12-12 12:41:57 -07:00
Leigh McCulloch 9a14481b90 Add go generated files 2019-12-10 08:32:02 -07:00
Leigh McCulloch 7c5ac23b81 Make _codegen its own module so that its dependencies do not pollute the root modules dependency graph 2019-12-09 10:12:49 -07:00
Boyan Soubachov 37e2176163 Rerun go generate
* Added generated code for new assert & require tests
2019-12-03 09:34:43 -07:00
Boyan d2e1501cff Remove hand editing of generated code 2019-11-04 07:28:29 -07:00
Boyan db3bc60f5a Typo fix for require.NotSamef 2019-11-04 07:28:29 -07:00
Boyan 7088056203 Add NotSame
* Added NotSame test for the assert package
* Added NotSame test for the require package
* Included formatted variants of NotSame for both assert and require
2019-11-04 07:28:29 -07:00
Nobuhiro MIKI 0224ef258e Add YAMLEq to assert that two YAML strings are equivalent 2019-07-11 17:50:32 -06:00