Commit Graph

140 Commits (suite-faster-methodFilter)

Author SHA1 Message Date
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
Sean Marciniak 648a7937c5
Merge pull request #1416 from stretchr/mock-simplify-matcher-check
mock: optimize argument matching checks
2024-01-22 08:48:09 +10:30
Sean Marciniak 24e57f1a77
Merge pull request #1444 from stretchr/mock-refactor-TestIsArgsEqual
mock: refactor TestIsArgsEqual
2024-01-22 08:44:43 +10:30
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é c740480fc1 mock: refactor TestIsArgsEqual
Refactor tests to use 'append' to build copies of slices instead of
manual loops.

Thanks golangci-lint.
2023-07-30 20:51:12 +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
Oleksandr Redko 37814a1755 docs: Fix typos in tests and comments 2023-07-06 13:14:39 +03: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
Stavros Ntentos 181cea6eab
impr: `CallerInfo` should print full paths to the terminal (#1201)
* 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>
2022-06-29 20:56:06 +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 eb8c41ec07 Add more tests to mock package 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 02b2656991 Handle ineffectual assignments
Removed ineffectual assignments.
2020-03-06 16:18:13 +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 3a72ffb6d8 Refactored Test_Mock_IsMethodCallable 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 20dae58180 mock_test: remove unecessary code 2018-03-18 18:59:09 +00:00