Commit Graph

385 Commits (suite-1501-fix-TestSubtestPanic)

Author SHA1 Message Date
Craig Davison 331c520966 Improve readability 2023-10-31 15:54:18 +01:00
Craig Davison 5f48c62606 address some review comments 2023-10-31 15:54:18 +01:00
Craig Davison b7c378d6bd captureTestingT.checkResultAndErrMsg 2023-10-31 15:54:18 +01:00
Craig Davison 002647e9f8 TestErrorIs/TestNotErrorIs: check error contents 2023-10-31 15:54:18 +01: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
Harald Nordgren fc1dee9921 Deprecate EqualExportedValues 2023-10-24 09:21:34 +02:00
Zachary Becker 4ae48e988c Combine switch cases, difference wrapped in if statement 2023-10-16 00:55:57 +02:00
Zachary Becker 2f7efa2451 Fix bug where array is treated as slice in EqualExportedValues 2023-10-16 00:55:57 +02:00
hidu ce5c2b684b assert: fix httpCode and HTTPBody occur panic when http.Handler read body 2023-10-15 23:34:32 +02:00
Grzegorz Burzyński 89920137cd collect errors from condition in defer 2023-10-13 08:53:17 +02:00
Grzegorz Burzyński 4ed68e1bca fix: make EventuallyWithT concurrency safe 2023-10-13 08:53:17 +02:00
tscales 34763e0df3 assert: ObjectsAreEqual: use time.Equal for time.Time type 2023-10-10 17:14:01 +02:00
Oleksandr Redko 1ee798c140 Remove canConvert because Go 1.16 is dropped from support 2023-10-10 14:28:34 +02:00
Olivier Mengué 9e58631a03 assert: reverse return values of internal getLen()
Reverse order of return values of internal function getLen() to be more
consistent with stdlib (ex: os.LookupEnv).

Old: func (any) (ok bool, length int)
New: func (any) (length int, ok bool)
2023-08-08 11:01:35 +02:00
Olivier Mengué 7a796b8f87 assert: simplify getLen() implementation 2023-08-08 11:01:35 +02:00
Olivier Mengué 81667ad920 assert: fix flaky TestNeverTrue
Fix flaky TestNeverTrue: use a channel to make a synchronized list of
return values to avoid a race condition.
2023-07-31 19:06:57 +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
Olivier Mengué af4d8a66cf
Merge pull request #1320 from lesichkovm/patch-1
Fix adding ? when no values passed
2023-07-11 22:52:16 +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
Ed 9f0f17fe64 Correct spelling/grammar 2023-05-26 10:38:59 +01: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
wwade 437071b948
assert: fix error message formatting for NotContains (#1362)
* assert: rename and refactor TestContainsFailMessage

I've renamed it to TestContainsNotContains and added a test case
structure so that I can use this test to validate the failure messages
from both Contains and NotContains,

There are no functional changes here, strictly refactoring. A new test
case will be added in a subsequent change.

* assert: fix error message formatting for NotContains

It was using "%s" to format the s and contains arguments, but these
could be any type that supports iteration such as a map. In this case
of NotContains failing against a map, it would print something like:

   "map[one:%!s(int=1)]" should not contain "one"

Fix this using "%#v" as was already done for Contains and added test
cases covering both the "len()" / iterable failure messages as well as
the Contains/NotContains failure case.

The new message for this example map would be something like:

    map[string]int{"one":1} should not contain "one"
2023-05-05 14:05:51 +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
Daniel White f36bfe3c33
Fix Subset/NotSubset when map is missing keys from the subset (#1261)
`MapIndex` returns a zero `reflect.Value` if the map value does not
exist. This now aligns more closely with `InDeltaMapValues` by
checking `reflect/Value.IsValid`.

The use of `recover()` was hiding this error by setting the result of
the test to be "false" despite the test suite passing. This led to
flapping tests where they would succeed if the panic occurred on a
missing key before comparing key values that didn't match!

I've ensured the test suite now asserts on the expected error message
and added another example where the subset has keys not found on the
map under test.
2023-02-25 22:46:30 +10:00
Artem V. Navrotskiy 0ab3ce1249
Fix `CallerInfo()` source file paths (#1288) 2023-01-03 20:57:11 +10:00
Milan Lesichkov c029f419b8
Fix adding ? when no values passed 2022-12-22 10:45:24 +00:00
sunpeng 9acc22213e
fix: fix bug for check unsafe.Pointer isNil (#1319) 2022-12-20 19:39:16 +10:00
Stavros Ntentos 181cea6eab
impr: `CallerInfo` should print full paths to the terminal (#1201)
* impr: `CallerInfo` should print full paths to the terminal

I am proposing this simple change, which changes this output
```
--- FAIL: TestABC (0.00s)
    --- FAIL: TestABC/C (0.00s)
        /this/is/a/path/to/file_test.go:258:
            	Error Trace:	file_test.go:258
            	            				file_test.go:748
            	Error:      	Not equal:
...
```
to this:
```
--- FAIL: TestABC (0.00s)
    --- FAIL: TestABC/C (0.00s)
        /this/is/a/path/to/file_test.go:258:
            	Error Trace:	/this/is/a/path/to/file_test.go:258
            	            				/this/is/a/path/to/file_test.go:748
            	Error:      	Not equal:
...
```

With the latter output, it is much more straightforward to find the file
you are looking for, even though in the displayed case, the file is the same.

However, for VSCodium, the case is a little more helpful, since VSCodium's
terminal is smart enough to recognize the output, and make links out of that input.

Signed-off-by: Stavros Ntentos <133706+stdedos@users.noreply.github.com>

* test: fix the tests that depended on the previous behavior

Signed-off-by: Stavros Ntentos <133706+stdedos@users.noreply.github.com>

Co-authored-by: Stavros Ntentos <11300730-stavros-relex@users.noreply.gitlab.com>
2022-06-29 20:56:06 +10:00
Oladapo Ajala 66eef0ef3a
fix: assert.MapSubset (or just support maps in assert.Subset) (#1178)
* WIP: added map key value check in subset

* upgraded subset & notsubset to check handle maps
2022-06-28 21:24:53 +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
Ryan Leung c31ea0312f
Support comparing byte slice (#1202)
* support comparing byte slice

Signed-off-by: Ryan Leung <rleungx@gmail.com>

* address the comment

Signed-off-by: Ryan Leung <rleungx@gmail.com>
2022-06-21 14:54:58 +10:00
Adam Luzsi 840cb80149
arrays value types in a zero-initialized state are considered empty (#1126)
* fix .Empty assertion with Array types

* refactor .Empty assertion for array types
2022-06-20 20:44:27 +10:00
cuishuang 35864782d2 assert: fix typo
Signed-off-by: cuishuang <imcusg@gmail.com>
2022-05-04 20:29:57 +10:00
RmbRT 083ff1c044 Fixed didPanic to now detect panic(nil).
Previously, the function would not detect panic(nil) calls.
In didPanic, removed the anonymous function call, instead,
added named return values. Added extra test cases for the
panic(nil) call.
2022-03-16 07:08:43 +10:00
Torkel Rogstad 1e36bfe104 Use cross Go version compatible build tag syntax 2022-02-15 20:26:04 +10:00
Torkel Rogstad e798dc2763 Add docs on 1.17 build tags 2022-02-15 20:26:04 +10:00
Torkel Rogstad 83198c2c50 assert: guard CanConvert call in backward compatible wrapper 2022-02-15 20:26:04 +10:00
Torkel Rogstad 087b655c75 assert: allow comparing time.Time 2022-02-15 20:26:04 +10:00
Ilia Kravets 7bcf74e94f fix msgAndArgs forwarding 2022-02-10 20:09:05 +10:00
Ilia Kravets c29de71342 add tests for correct msgAndArgs forwarding
len(msgAndArgs)>1 should lead to fmt.Sprintf()
2022-02-10 20:09:05 +10:00
Menno ab6dc32628 fix linting errors in /assert package 2021-08-24 21:55:23 +10:00
Menno edff5a049b fix funtion name 2021-08-24 21:55:23 +10:00
Menno 5c61ef97ae fix potential nil-pointer dereference
the fix gracefully fails the assertion instead of panicking unresolved.
2021-08-24 21:55:23 +10:00
Menno fd9e1fb0e1 Fix NaN similarity checks
Plus minor alignments in code.
2021-07-09 20:35:46 +10:00
Harald Nordgren dc5c261377 Make sure time.Time comparison produces a helpful diff. closes #989 2021-04-27 21:16:43 +10:00
Alun Evans 6990a05d54 Add ErrorContains 2021-01-16 12:32:05 +11:00
Yongxin Wang bf646ea5b3 add test to check that Helper is called 2021-01-15 21:06:28 +11:00
Yongxin Wang 6f81fdf1db fix the output source file in test output 2021-01-15 21:06:28 +11:00