Commit Graph

100 Commits (allow-error-string-from-custom-matcher)

Author SHA1 Message Date
Brandon Bodnar 30f794c7de Merge remote-tracking branch 'origin/master' into allow-error-string-from-custom-matcher 2019-05-28 07:08:05 -05: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
Brandon Bodnar 3cd4cbe71a Fix example codeblock spacing 2018-09-17 07:54:50 -05:00
Brandon Bodnar 42afde47af Introduce unexported match method to report errors matching
Changes to the method signature for argumentMatcher.Matches may lead to breaking existing
external uses of that function. Introducing a  new method used internally allows presenting
the error information out for internal testify functionality while not breaking other
existing uses of Matches.
2018-09-17 07:37:43 -05:00
Brandon Bodnar b59ea01145 Allow custom matcher functions to return error strings displayed on a failed match 2018-07-19 13:32:01 -05: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 20dae58180 mock_test: remove unecessary code 2018-03-18 18:59:09 +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
Adam Medzinski 2c9035a78f Changed mock assertions text output to be non-unicode friendly 2017-12-31 12:25:00 +01:00
Dinesh Kumar b3596e9279 Fxinng After(time.Duration) to wait properly
commit 5b0291d47dc3a70cc6c6be3bba3c2f934a8e933e
Merge: 1f324ec 8ccf48a
Author: Dinesh Kumar <dineshkumar-cse@users.noreply.github.com>
Date:   Sat Dec 30 19:55:13 2017 +0530

    Merge branch 'master' into master

commit 1f324ec8cbe892a2c5364904643aa1b710121824
Author: Dinesh Kumar <dinesh.kumar@go-jek.com>
Date:   Sat Dec 30 19:07:16 2017 +0530

    Fixing comments: reduced test time, locking in after, unexported waitTime

    - WaitUntil/After overrides each other value
    - currently if channel is set that takes the priority, if not the
      waitTime is used to Sleep

commit a7101ec14224918fc06532acae76418d1b4f04c5
Author: Dinesh Kumar <dinesh.kumar@go-jek.com>
Date:   Fri Dec 29 13:02:14 2017 +0530

    Using if else instead of switch and pulling out the commone one

commit 936f63dd689acacfd051867c5c700489caa1dbc2
Author: Dinesh Kumar <dinesh.kumar@go-jek.com>
Date:   Fri Dec 29 12:41:40 2017 +0530

    After - making it wait during method call

    After was using call.WaitUntil(time.After(duration)),
    <-time.After(duration) returns a channel with the timer immediately
    started
2017-12-30 17:53:34 +01:00
Joel Low cbf22d8d28 Support nil arguments to Argument Matchers 2017-12-30 17:48:55 +01:00
Maxim Kolganov 6e494f9834 put closestCall.Arguments to the expected side of the diff 2017-12-30 16:53:32 +01:00
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