Reduce calls to reflect.Type in implementation of mock.IsType by
extracting the type early.
This also avoids to keep alive references to the argument value.
Deprecate mock.AnythingOfTypeArgument which should never have been
publicly exposed.
AnythingOfTypeArgument is now a type alias to the private
anythingOfTypeArgument and is marked as Deprecated in godoc.
The AnythingOfType constructor is still available.
The aim is to completely remove that alias.
* 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>
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>
* 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>
Like `assert.IsType(...)`, `mock.IsType` is used to check that the
type of an argument is the expected type. This is an alternative
to `AnythingOfType`.
Go tip contains following commmit, that inlines function with single
call bodies.
13baf4b2cd
`(*Call).On()` is the exact target for the improvement in Go repo. Due to
the inlining, assert.CallerInfo() can't not detect the file and line
number of the call to `(*Mock).On()` from `(*Call).On()`. Thus, the test
fails.
Adding the compiler directive `go:noinline` prevent this effect and make
mock package works with go tip as before.