Olivier Mengué
3c302f75ae
mock: improve doc ( #1570 )
...
## Summary
Improve API doc of package
[`mock`](https://pkg.go.dev/github.com/stretchr/testify/mock ):
- add godoc links
- indent example code
## Motivation
Readability.
2024-03-10 11:42:04 +01:00
Tom Wright
cab2acc70f
Do not get argument again unnecessarily in Arguments.Error()
2024-03-06 03:03:10 +01:00
Bracken
c719de3088
Merge pull request #1331 from ianrose14/ianrose/assertexpectations-skipped
...
Ensure AssertExpectations does not fail in skipped tests
2024-02-17 17:50:13 +00:00
Ian Rose
1837f62a5f
Ensure AssertExpectations does not fail in skipped tests
2023-10-31 00:00:55 +01:00
Olivier Mengué
307c9344b8
mock: refactor IsType
...
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.
2023-10-16 13:57:23 +02:00
Olivier Mengué
413628c0f4
mock: simplify Arguments.Diff
...
Use a type switch instead of reflect.TypeOf comparisons.
2023-10-16 13:57:23 +02:00
Olivier Mengué
f24f3ba986
mock: deprecate AnythingOfTypeArgument ( #1434 )
...
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.
2023-08-08 11:05:09 +02:00
Anant Vyas
a23f5db224
mock: move regexp compilation outside of Called ( #631 )
...
Co-authored-by: Olivier Mengué <dolmen@cpan.org>
2023-08-01 10:07:29 +02:00
Olivier Mengué
862e41010c
Merge pull request #1360 from hikyaru-suzuki/feature/update_logging_output
...
mock: AssertExpectations log reason only on failure
2023-07-29 05:52: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
Nisheeth Barthwal
b3106d772c
allow testing for functional options ( #1023 )
...
* allow testing for functional options
* add linting docs
* use reflect magic to obtain FunctionalOption name
Co-authored-by: dillonstreator <dillonstreator@gmail.com>
---------
Co-authored-by: dillonstreator <dillonstreator@gmail.com>
2023-05-10 06:55:48 +10:00
鈴木 光
75b9b6dfff
update: log reason output only if failed
2023-03-09 18:49:15 +09:00
lisitsky
2b00d33aec
Fix Call.Unset() panic (issue #1236 ) ( #1250 )
...
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.
2023-01-03 20:44:42 +10:00
Bracken
cf1284f8dd
Allow mock expectations to be ordered ( #1106 )
...
* Allow mock expectations to be ordered
* Only say another call if it has been called before
2022-06-28 22:13:45 +10:00
Edward Raigosa
b5ce165710
fixing panic in calls to assertion with nil m.mutex ( #1212 )
...
* fixing panic in calls to assertion with nil m.mutex
This reverts a change that was made in https://github.com/stretchr/testify/pull/1182
The PR makes m.mutex a pointer which now needs to be checked but it's not checked for nil everywhere.
This should also help with these issues:
- https://github.com/stretchr/testify/issues/1208
- https://github.com/stretchr/testify/issues/1210
* Revert throwing out the lock because other concurrent calls can already have it locked
* fix go vet copy lock by using pointer
* fix obj assignment for passing test
2022-06-24 10:11:59 +10:00
Bracken
c206b2e823
Mock can be deadlocked by a panic ( #1157 )
...
If an argumentMatcher function panics and AssertExpectations is deferred then the test would deadlock.
2022-06-23 19:42:21 +10:00
Paul Dufour
ba1076d8b3
Add .Unset method to mock ( #982 )
...
* Add .Off method to mock
* Update README.md
* Update mock.go
* Update mock_test.go
* Update README.md
* Fix tests
* Add unset test
* remove prints
* fix test
* update readme
2022-06-22 19:31:35 +10:00
Tony Abboud
48391ba5eb
Fix panic in AssertExpectations for mocks without expectations ( #1207 )
...
Co-authored-by: Tony Abboud <tabboud@palantir.com>
2022-06-21 07:08:00 +10:00
Boyan Soubachov
3c33e07c4c
Added Go 1.18.1 as a build/supported version ( #1182 )
...
* 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>
2022-06-14 20:50:25 +10:00
perrydunn
e209ca88af
Improve mock.MatchedBy failed comparison Diff message
2021-08-24 20:26:52 +10:00
neilisaac
6241f9ab99
Add String method to Mock to fix #625
2021-04-27 21:38:32 +10:00
Bo Sunesen
acba37e5db
Only use repeatability if no repeatability left
2021-01-13 20:54:11 +11:00
Bo Sunesen
a5830c56d3
Extract method to evaluate closest match
2021-01-13 20:54:11 +11:00
Bo Sunesen
1962448488
Use Repeatability as tie-breaker for closest match
2021-01-13 20:54:11 +11:00
Yaroslav Kolomiiets
3bf8d0aa5e
callString not to panic on nil
...
Fixes stretchr/testify#936 .
2020-04-29 21:10:54 +10:00
sarathsp06
35d4bf5bd4
panic: add .Panic() to mock.Call
...
Panic mocks a function call that panics with th specfied message
2020-04-27 19:52:16 +10:00
YukinoKamei
dfba5a4e3a
add )
2020-03-30 15:55:14 +11:00
Christian Muehlhaeuser
8bb674980e
Simplify code
...
- Direct boolean comparisons
- Don't use Sprintf when we can use the String() function
2020-03-06 14:36:53 +11:00
Ogoyukin
9f1c28b404
The mock.IsMethodCallable function is refactored
2020-02-26 16:09:38 +11:00
Ogoyukin
6bf5d94027
Update comment
2020-02-26 16:09:38 +11:00
Ogoyukin
4a3d527660
Refactored 'isArgsEqual'
2020-02-26 16:09:38 +11:00
Ogoyukin
36e077c09a
Refactored 'IsMethodCallable'
2020-02-26 16:09:38 +11:00
Ogoyukin
42aafee8d7
Added function 'IsMethodCallable', which checking that the method can be called.
2020-02-26 16:09:38 +11:00
Olaf Alders
2aadfe8adc
Grammatical change in documentation for Run()
...
There was a switch between singular and plural which made this line a
little bit hard to parse.
2020-02-19 07:03:40 +11:00
Daniel Cormier
518a1491c7
IsType: A type-safe way of checking argument type
...
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`.
2020-01-31 08:08:47 +11:00
xiaolei
221dbe5ed4
fix mutex
2019-07-11 18:01:36 -06:00
xiaolei
1bb3d5a619
improve find expected call
2019-07-11 18:01:36 -06:00
Tai
f1df803a70
Preserve stack frame for mock parent method call
...
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.
2019-01-03 11:36:43 -07:00
Tony Jiang
26d4a37fb4
Fix typo ("PASS" -> "FAIL")
...
Fixes #669
2019-01-03 10:41:29 -07:00
gz-c
f35b8ab0b5
Restore type information to matched output message
2018-06-09 12:55:18 +01:00
gz-c
e4944078a3
Use %v to print matched argument values
2018-06-09 12:55:18 +01:00
Eyal Posener
33951ec724
Add T object and Test method to Mock
...
This makes is possible to fail the test instead of panicing in case
that the method was called with unexpected arguments.
Fixes #489
mock: change field 'T' to be private field 'test'
mock_test: MockTestingT not using Mock anymore
2018-03-19 07:42:13 +00:00
Eyal Posener
4c1331b42c
Anything: remove unecessary type
2018-03-18 18:59:09 +00:00
Dinesh Kumar
921da254ef
Displaying mismatch information of arguments diff while panic for closest function call. closes #556
2018-03-18 18:58:37 +00:00
Ernesto Jiménez
b89eecf5ca
Improve errors from mock assertions
...
Mark the assert helpers as helpers for Go Versions that support
`t.Helper()`
2018-03-03 14:28:11 +00:00
Jonathan ES Lin
0bfbef4e58
Modify AssertCalled and AssertNotCalled to give better error messages
...
Co-authored-by: Giuseppe Landolfi <giuseppe.landolfi@ricardo.ch>
Co-authored-by: Ernesto Jiménez <me@ernesto-jimenez.com>
2018-03-03 14:28:11 +00:00
Dinesh Kumar
be8372ae8e
Adding logging when mock assertions fails
2018-02-06 08:25:39 +00:00
Ruben de Vries
8824eb48ce
Store CallerInfo when On() is called and print for missing calls during AssertExpectations.
2018-02-02 18:36:05 +00:00
Ruben de Vries
5f831d47b7
Print missing FAIL during AssertExpectation
2018-01-31 22:19:04 +00:00