Commit Graph

359 Commits (f36bfe3c337aa95c86f04c721acdbafb5ffb1611)

Author SHA1 Message Date
Daniel White f36bfe3c33
Fix Subset/NotSubset when map is missing keys from the subset (#1261)
`MapIndex` returns a zero `reflect.Value` if the map value does not
exist. This now aligns more closely with `InDeltaMapValues` by
checking `reflect/Value.IsValid`.

The use of `recover()` was hiding this error by setting the result of
the test to be "false" despite the test suite passing. This led to
flapping tests where they would succeed if the panic occurred on a
missing key before comparing key values that didn't match!

I've ensured the test suite now asserts on the expected error message
and added another example where the subset has keys not found on the
map under test.
2023-02-25 22:46:30 +10:00
Artem V. Navrotskiy 0ab3ce1249
Fix `CallerInfo()` source file paths (#1288) 2023-01-03 20:57:11 +10:00
sunpeng 9acc22213e
fix: fix bug for check unsafe.Pointer isNil (#1319) 2022-12-20 19:39:16 +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
Oladapo Ajala 66eef0ef3a
fix: assert.MapSubset (or just support maps in assert.Subset) (#1178)
* WIP: added map key value check in subset

* upgraded subset & notsubset to check handle maps
2022-06-28 21:24:53 +10:00
Ruan Moolman 2fab6dffcf
Add WithinTimeRange method (#1188)
* Add WithinTimeRange method

* Run ./.ci.generate.sh

* Rename WithinTimeRange to WithinRange

* Rename WithinRange expected parameter to actual

* Capitalise start parameter at start of error message

* Improve WithinRange example
2022-06-28 21:14:39 +10:00
Ryan Leung c31ea0312f
Support comparing byte slice (#1202)
* support comparing byte slice

Signed-off-by: Ryan Leung <rleungx@gmail.com>

* address the comment

Signed-off-by: Ryan Leung <rleungx@gmail.com>
2022-06-21 14:54:58 +10:00
Adam Luzsi 840cb80149
arrays value types in a zero-initialized state are considered empty (#1126)
* fix .Empty assertion with Array types

* refactor .Empty assertion for array types
2022-06-20 20:44:27 +10:00
cuishuang 35864782d2 assert: fix typo
Signed-off-by: cuishuang <imcusg@gmail.com>
2022-05-04 20:29:57 +10:00
RmbRT 083ff1c044 Fixed didPanic to now detect panic(nil).
Previously, the function would not detect panic(nil) calls.
In didPanic, removed the anonymous function call, instead,
added named return values. Added extra test cases for the
panic(nil) call.
2022-03-16 07:08:43 +10:00
Torkel Rogstad 1e36bfe104 Use cross Go version compatible build tag syntax 2022-02-15 20:26:04 +10:00
Torkel Rogstad e798dc2763 Add docs on 1.17 build tags 2022-02-15 20:26:04 +10:00
Torkel Rogstad 83198c2c50 assert: guard CanConvert call in backward compatible wrapper 2022-02-15 20:26:04 +10:00
Torkel Rogstad 087b655c75 assert: allow comparing time.Time 2022-02-15 20:26:04 +10:00
Ilia Kravets 7bcf74e94f fix msgAndArgs forwarding 2022-02-10 20:09:05 +10:00
Ilia Kravets c29de71342 add tests for correct msgAndArgs forwarding
len(msgAndArgs)>1 should lead to fmt.Sprintf()
2022-02-10 20:09:05 +10:00
Menno ab6dc32628 fix linting errors in /assert package 2021-08-24 21:55:23 +10:00
Menno edff5a049b fix funtion name 2021-08-24 21:55:23 +10:00
Menno 5c61ef97ae fix potential nil-pointer dereference
the fix gracefully fails the assertion instead of panicking unresolved.
2021-08-24 21:55:23 +10:00
Menno fd9e1fb0e1 Fix NaN similarity checks
Plus minor alignments in code.
2021-07-09 20:35:46 +10:00
Harald Nordgren dc5c261377 Make sure time.Time comparison produces a helpful diff. closes #989 2021-04-27 21:16:43 +10:00
Alun Evans 6990a05d54 Add ErrorContains 2021-01-16 12:32:05 +11:00
Yongxin Wang bf646ea5b3 add test to check that Helper is called 2021-01-15 21:06:28 +11:00
Yongxin Wang 6f81fdf1db fix the output source file in test output 2021-01-15 21:06:28 +11:00
Graham Jenson c26b7f39f8 Update assertions.go
lower to 10
2020-11-03 21:38:56 +11:00
Graham Jenson 8fb4b2442e [Fix] The most recent changes to golang/protobuf breaks the spew Circular data structure detection
The latest update to golang/protobuf (I am on v1.4.2) break the spew circular data structure detection. This means that when calling `assert.Equal(t, proto1, proto2)` will not only fail, but also enter an infinite recursion.

Given spew is not being actively maintained, and tesitfy should set some upper bound, we need to set a `MaxDepth` to some very high number, so at least the test will not run for a very long time and finish and fail quickly.
2020-11-03 21:38:56 +11:00
Masaya Hayashi dc8af7208c add generated code for positive/negative assertion 2020-11-03 21:37:46 +11:00
Masaya Hayashi 1544508911 add assert positive/negative 2020-11-03 21:37:46 +11:00
alexpantyukhin cf221cc875 add tests and fix message 2020-08-14 20:45:51 +10:00
alexpantyukhin c74c0d3a7f add fnctions into requres 2020-08-14 20:45:51 +10:00
alexpantyukhin a9284e66a9 add assertion order 2020-08-14 20:45:51 +10:00
Martijn a3bed97cf3 assert: s/rune/r/ to avoid "rune" predeclared ident shadowing #642
Thanks @quasllyte
2020-08-03 19:54:30 +10:00
Boyan ed4976c764 Revert "Fix PR comments"
This reverts commit 1ebd9c5791.
2020-07-27 22:28:46 +10:00
arseny 415d89281b Fix time.Time not equals bug
Adding test
2020-07-27 21:16:21 +10:00
arseny 1ebd9c5791 Fix PR comments 2020-07-27 21:16:21 +10:00
Pal Sivertsen 95a9d909e9 Add wrapper functions for errors Is and As funcs
This commit adds wrapper functions for Is and As functions from the
errors package.
2020-07-20 20:40:44 +10:00
Torkel Rogstad 51595dcf94 Allow comparing custom comparable types
Prior to this commit, this would not work:

```go
type myInt int
assert.Less(t, myInt(1), myInt(2)) // panic!
```

We add some type conversions, similarly to how `ObjectsAreEqualValues`
work. This allows us to compare `myInt` to `myInt`, as well as `myInt`
to `int`.
2020-06-22 19:40:53 +10:00
Ivo van der Wijk b8f7d52a4a Rewrite test loops into individual test cases 2020-06-13 21:33:52 +10:00
Ivo van der Wijk 8a501b0fac make testcase definition local 2020-06-13 21:33:52 +10:00
Ivo van der Wijk 4bbffeac6c table-ify TestElementsMatch 2020-06-13 21:33:52 +10:00
Ivo van der Wijk 52b38ca424 table-ify, refactor (Not)Subset() 2020-06-13 21:33:52 +10:00
Ivo van der Wijk 0929293466 refactor, table-ify TestContains / TestNotContains 2020-06-13 21:33:52 +10:00
Ivo van der Wijk 67a4d91853 table-ify ObjectsAreEqual() 2020-06-13 21:33:52 +10:00
Ivo van der Wijk 5717c498e9 table-ify Equal() 2020-06-13 21:33:52 +10:00
Ivo van der Wijk 408bc6703a keep type definition local to function where used 2020-06-13 21:33:52 +10:00
Ivo van der Wijk 590942c47f table-ify Exactly 2020-06-13 21:33:52 +10:00
Ivo van der Wijk 9ffb85bbec clarify sets of tests 2020-06-13 21:33:52 +10:00
Ivo van der Wijk 51b7cfe385 rewrite NotEqual() tests to table tests 2020-06-13 21:33:52 +10:00
Ivo van der Wijk 07d1e00890 first attempt at table-ifying NotEqualValues tests 2020-06-13 21:33:52 +10:00
Ivo van der Wijk f50e178a9f first attempt at table-ifying NotEqualValues tests 2020-06-13 21:33:52 +10:00