Peter Hsu
8ccf48a064
Allow a method call to be optional
2017-12-30 15:23:32 +01:00
Dan Heller
2aa2c176b9
Fix unprotected call fields access in MethodCalled()
...
This change fixes a race condition I discovered when a multithreaded
test in a service I work on failed under -race. The included test case
simulates that failure (concurrent mutation of a Call with invocations
on the mock). The test will fail with a data race if run under the
race detector; the new locking ensures that call fields are not
accessed without the protection of the parent mutex.
2017-10-17 22:22:57 -07:00
Yimin Chen
e964b172ca
add MethodCalled to the mock
...
remove IsCallExpected method
add comment
2017-05-30 21:11:52 +01:00
Ernesto Jiménez
345898142b
Run go vet in travis
2017-05-29 13:40:41 +01:00
Ernesto Jiménez
bd79c01e74
Fix race condition on mock package's Called
...
Closes #442
2017-05-28 14:43:48 +01:00
Ernesto Jiménez
f712be9266
Revert "add mock.MethodCalled(methodName, args...)"
...
This reverts commit 17a0bd50e9
.
Should avoid simply exporting an internal method.
2017-05-26 07:47:23 +01:00
Ernesto Jiménez
34687ebd28
Revert "diffArguments: remove unnecessary range-for ( #417 )"
...
This reverts commit 5c861cc4a4
.
Bug was already fixed in another merge.
2017-05-26 07:46:34 +01:00
Ernesto Jiménez
2b76a9702e
Revert "Added goconvey style assertions to the mock package"
...
This reverts commit faf0710ff2
.
2017-05-26 07:46:02 +01:00
Richard Knop
18cfa6871f
Added extra unit test for function with mixed variadic arguments.
2017-05-25 17:38:37 -07:00
Simon Mulser
b1f1bcb83a
fix typo
2017-05-25 17:32:03 -07:00
Joseph Anthony Pasquale Holsten
5c861cc4a4
diffArguments: remove unnecessary range-for ( #417 )
...
When `len(actual) > len(expected)`, this for loop would cause a panic.
Alternative to this implementation, there could be a check for
`if len(actual) != len(expected)`, but generating a meaningful message
describing that is already provided by `diff()`. So we defer to diff in
every case.
Fixes #393
2017-05-25 17:27:00 -07:00
Jonas Finnemann Jensen
115ab90138
Provide argument name `args` in function signature
...
This mainly serves to make code-completion better in IDEs that automatically create the function signature.
2017-05-25 17:13:31 -07:00
Andy McCall
faf0710ff2
Added goconvey style assertions to the mock package
2017-05-25 17:05:23 -07:00
Yimin Chen
17a0bd50e9
add mock.MethodCalled(methodName, args...)
2017-05-25 17:03:17 -07:00
Tagir Magomedov
9afdd65e6a
Check number of provided arguments vs mocked
...
Pre-diff:
```
panic: runtime error: index out of range
```
Post-diff:
```
panic:
mock: Unexpected Method Call
-----------------------------
MyFunction(string,string,string)
0: string,
1: string,
2: string
The closest call I have is:
MyFunction(string,string)
0: "mock.Anything"
1: "mock.Anything"
Provided 3 arguments, mocked for 2 arguments
```
2017-05-25 17:02:05 -07:00
Ernesto Jiménez
598ab58e60
Merge pull request #171 from ANPez/master
...
Release lock before .WaitUntil
2016-12-17 13:32:40 -06:00
Seppe Stas
434d5c1f51
Fixed minor typo
...
"interface", was missing the 'r'
2016-12-02 13:02:34 +01:00
Alexander Staubo
cbd71e7dd4
When diffing with spew, use a format that doesn't include pointer addresses (which
...
generate false negatives). This updates go-spew to 04cdfd42973bb9c8589fd6a731800cf222fde1a9.
2016-10-29 16:24:47 -04:00
Ernesto Jiménez
0858597361
mock spew config in init
2016-09-24 21:05:08 +01:00
Ernesto Jiménez
dfaf6b82bc
Merge pull request #335 from dominicbarnes/mock-arg-diff
...
Mock: Add diff to output when no exact match found
2016-09-24 19:44:49 +01:00
Ernesto Jiménez
92787b8c71
Fixes #342 - AssertExpectationsForObjects takes *Mock
2016-09-24 18:04:24 +01:00
Dominic Barnes
6a1a0a4608
add arguments diffing
2016-08-11 17:12:24 -07:00
Martin Hamrle
e704e18cb5
fix typos
2016-06-30 19:23:22 +02:00
Konstantin Cherkasov
e9777bfbf1
Fix typo: preceeded -> preceded
2016-05-04 10:20:41 +03:00
Konstantin Cherkasov
48c93141f0
Fix typo: underyling -> underlying
2016-05-04 10:17:29 +03:00
Konstantin Cherkasov
b72b9c302b
Fix typo: arugment -> argument
2016-05-04 09:50:41 +03:00
Ernesto Jiménez
c5d7a69bf8
Fixes #300 - Fix backwards-incompatible change
2016-04-18 23:58:27 +01:00
Ernesto Jiménez
3058ec34fb
Document chances of false reults on mock asserts
2016-04-12 21:41:11 +01:00
Ernesto Jiménez
096a13e3a4
Fix #293 - Fix mock.AssertExpectations w/ pointers
...
AssertExpectations did fail using an argument pointer whose underlying
value changed before the assertion.
2016-04-12 21:25:54 +01:00
Will Ogden
17400e7672
Update MatchedBy example to include actual use of MatchedBy!
2016-04-07 11:11:40 +01:00
Thomas LE ROUX
dcb39ac4d8
docs: Fix a typo
2016-01-29 17:29:26 +01:00
Ernesto Jiménez
1661650f98
Fix most golint warnings
2016-01-09 19:30:22 +01:00
Ernesto Jiménez
7e30b2ce7a
Fixes #261 - Add FailNow back
2016-01-08 12:25:24 +01:00
Ernesto Jiménez
347825ef79
Use Godeps with GO15VENDOREXPERIMENT
2016-01-07 18:08:03 +01:00
Ernesto Jiménez
15b3d4d0fc
Merge pull request #249 from stretchr/godep
...
Vendor dependencies and rewrite import paths
2016-01-07 16:54:51 +01:00
Ernesto Jiménez
5b9da39b66
MatchedBy documentation
2016-01-02 12:02:58 +01:00
Ernesto Jiménez
6905a3e663
Merge pull request #227 from pippio/master
...
Add custom mock argument matching
2016-01-02 11:55:03 +01:00
Ernesto Jiménez
d04dca765f
Vendor dependencies and rewrite import paths
2015-12-02 20:32:31 +01:00
Antonio Nicolás Pina
8879a0154e
Unlock and relock not needed anymore. Addresses #167 .
2015-11-20 13:39:52 +02:00
Antonio Nicolás Pina
384cc6617a
Merge branch 'master' of https://github.com/stretchr/testify
2015-11-20 13:19:13 +02:00
Johnny Graettinger
ed275850b6
Add custom mock argument matching
...
Add an argumentMatcher type and MatchedBy() helper to the mock
package, enabling custom fine-grained argument matching behaviors.
This is particularly helpful when building mocks over complex argument
types where deep equality is cumbersome or can't be used. Ex, a matcher
might match over just the the URL of an argument *http.Request.
2015-11-09 18:11:46 -05:00
Ernesto Jiménez
ef3ce2dd13
Show struct fields in mock unexpected method error
2015-11-02 00:46:20 +00:00
Levi Corcoran
3c35d25e9b
fix race conditions related to mutation of expectedCall.Repeatability
2015-10-07 16:34:11 -05:00
Srini Brahmaroutu
0df687d7a9
Due to function name format differences, code fails with GCCGO
...
Signed-off-by: Srini Brahmaroutu <srbrahma@us.ibm.com>
2015-09-29 17:07:45 +00:00
Ernesto Jiménez
b8dc1cecf1
Merge pull request #208 from tcsc/master
...
Allows mock call expectations to be defined in arbitrary order
2015-09-14 10:32:55 +01:00
Trent Clarke
49804a382a
Allows mock call expectations to be defined in arbitrary order
...
Originally the expctations required that the return values be specified
immediately after the method name and arguments, otherwise the call
setup will either panic (best case) or silently modify the *previous*
call specification (worst case).
This change moves the Return(), Run(), Once(), etc methods onto the Call
struct, and changes the chaining behaviour so that they modify the Call
data directly rather than referencing the last item in the ExpectedCalls
array.
2015-08-27 22:19:12 +10:00
Boris Pruessmann
84e2423404
AssertNumberOfCalls: wrong order of arguments
...
The assert.Equal called had the actual and expected values mixed up.
2015-07-03 13:30:03 +02:00
Sergiusz Urbaniak
b11fb16915
mock: fix races to m.Calls/m.ExpectedCalls
...
Fixes races inside the mock package caused by
unsychronized reads/writes of m.Calls/m.ExpectedCalls.
2015-06-05 16:24:27 +02:00
Ernesto Jiménez
4464dda05e
Add extra tests mocking variadic functions
2015-06-02 20:23:13 +01:00
Ernesto Jiménez
d6265bda1a
Add test mocking variadic function
2015-06-02 19:59:43 +01:00