* 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>
* 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>
* 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"
* 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>
`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.
Unset changes len of a `ExpectedCalls` slice during iteration while using index from original slice, and under some conditions it tries to reslice element beyond of the slice boundaries. That causes panic.
The proposed solution uses independent write index to count elements kept in output slice.
Tests (the simplest and more complicated cases) and comments are included.
* 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>
* 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
* Added Go 1.18.1 as a build/supported version
Removed Go 1.15.13 as a build version as it's no longer supported
* Fix mutex passed by value for the Mock struct
* Add mutex initialisation for Mock
Co-authored-by: Boyan Soubachov <bsoubachov@atlassian.com>
Rather than directly adding `1.16`, I thought better to reword to state the minimum version supported... this way the line doesn't have to get updated with every new release, but instead only when dropping releases.
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.