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.
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
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
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.