Commit Graph

91 Commits (30f794c7de880f607b66a28131062d2a281a0234)

Author SHA1 Message Date
Gavin Cabbage 21cb1c2932 add ptr comparison func 'Same' to assert pkg 2019-02-28 14:48:09 -07:00
Viswajith Venugopal 5b93e2dc01 Run go fmt 2018-12-12 10:17:45 -08:00
Viswajith Venugopal 6697e04e8d Support arbitrary objects in msgAndArgs 2018-12-12 10:17:45 -08:00
Harald Nordgren f2347ac6c9 Allow assert.Equal on string type alias without panicking on failure 2018-10-02 17:26:21 -06:00
timfeirg 2a15e200fd support diff display for string variables 2018-06-09 11:55:26 +01:00
Cory Bennett c679ae2cc0 add function aliases for common assert and requires function signatures to make table driven tests easier 2018-03-19 22:34:59 +00:00
Ernesto Jiménez a726187e31 Fix vim-go integration and other editors
Use Go 1.9 t.Helper() to remove testify from the output of the tests and
stop using `\r` to try to overwrite the output.

This means in Go 1.7 and Go 1.8 testify will appear as failing the test.
2018-02-02 18:39:40 +00:00
Ernesto Jiménez b57b6d191c Add FileExists and DirExists assertions
Implement FileExists and DirExists assertions to check whether file/dir
exist in a given path.

Closes #428
2017-12-30 18:26:00 +01:00
Adam Medzinski 42baa3e5a4 Nil check in Implements assertion 2017-12-30 17:32:04 +01:00
Emil Stanchev 51464dae67 Consider empty/nil arrays as matching elements 2017-12-30 16:33:25 +01:00
Emil Stanchev bf57a5dedc ElementsMatch array/slice assertion ignoring order
An assertion that compares the elements of the slices/arrays disregarding the order,
i.e. it checks whether each element in the first slice/array appears the same number of times in it
as in the second slice/array.

This name seemed like it would be easy to find.

Possible alternatives for the name:
- ContainsSameElements
- IsPermutation (C++: http://en.cppreference.com/w/cpp/algorithm/is_permutation)
- MatchArray (rspec: http://www.rubydoc.info/github/rspec/rspec-expectations/RSpec/Matchers:match_array)
- EqualSorted
- Other ideas?

This implementaiton is O(N^2), while sorting both lists first would be O(nlogn).
However, this one doesn't need to copy the lists, so it is simpler and doesn't require additional
memory and time for the copies.

I realize this was deemed as out of scope
https://github.com/stretchr/testify/issues/275
but I decided to give it a shot as I needed it also.
2017-12-30 16:33:25 +01:00
Emil Stanchev 9fb9de17de Make NotSubset actually fail the test on nil subset
The assertion function was simply returning false, which doesn't actually fail a test.
An example test that should have failed but doesn't:

  func TestNotSubset(t *testing.T) {
      assert.NotSubset(t, []string{"x"}, nil)
  }
2017-12-30 16:07:04 +01:00
odog c0f1d443b4 indent actual value for better comparison with expected value 2017-12-30 14:43:45 +01:00
Jonathan Jin 249123e03a Implement delta comparison for map values 2017-12-30 14:26:37 +01:00
Vincent Cote-Roy 88a414d072 generalize Empty assertion
Make `Empty` work against any struct and custom types, by replacing
explicit zero value comparisons with a `DeepEqual` comparison with
the type's `reflect.ZeroValue`.
2017-12-30 13:03:09 +01:00
Joshua T Corbin 2f1cd6b778 time.Duraions are numbers too 2017-07-14 14:27:08 -07:00
Tom Artale f6abca5936 Added assert.PanicsWithValue + tests 2017-06-01 22:03:22 +01:00
Adam Medzinski 46b3c8225b Simple validation of Equal/NotEqual assertion arguments 2017-05-29 17:57:31 +01:00
Ernesto Jiménez c7668ea997 Fixes #339 - Add `assertion`f assertions like Errorf and Equalf 2017-05-29 12:56:43 +01:00
Ernesto Jiménez c33f336b92 Fix vet warnings and go generate to update docs 2017-05-29 12:56:43 +01:00
decauwsemaecker.glen@gmail.com 3a59a58abc
add Subset and NotSubset assertions 2017-05-27 17:24:18 -05:00
Cameron Moore 09f61d78b8 assert: fix error reporting when error contains escape sequences
Fixes #325
2017-05-25 17:28:59 -07:00
havnesvo bc11a6e4dd Tighten language by increasing overall consistency in wording in texts and argument names: use 'actual' instead of 'received' 2017-05-25 17:16:55 -07:00
Denys Smirnov 97c0e43cd5 compare bytes with bytes.Equal instead of reflect.DeepEqual 2017-05-25 17:04:05 -07:00
Ernesto Jiménez 332ae0e18f Add Equal test comparing nil with non-nil 2017-01-30 11:25:29 +00:00
Ernesto Jiménez 2402e8e7a0 Merge pull request #364 from nmiyake/fixFailOutput
Ensure that assert.Fail properly align its output
2016-12-17 14:04:45 -06:00
Ernesto Jiménez ae4c58e530 Merge pull request #367 from packrat386/rm_numeric_check
Remove isNumericType check
2016-12-17 13:26:48 -06:00
Nick Miyake 3928f579ee Add comments for Equal and NotEqual to clarify pointer comparison
Clarify that pointer equality is determined by equality of values
rather than memory address.

Fixes #358
2016-11-19 23:31:18 -08:00
Aidan Coyle 6835870125 Remove isNumericType check
I'm not sure why this check is needed. It seems worthwhile to print the
type any time the types aren't equal. Closes #366.
2016-11-17 10:29:04 -06:00
Nick Miyake ddb91ee140 Ensure that assert.Fail properly align its output
Previous implementation depended on tab alignment. This worked
when the output was not prepended with anything, but would break
if the output was prepended with further spaces (which can occur
in environments like IntelliJ test runners). This commit fixes it
so that the output is always aligned logically.

Fixes #83
2016-10-28 19:36:52 -07:00
Ernesto Jiménez 69483b4bd1 Merge pull request #327 from jveski/issue-155
Clarify assert.Equal failure message given mismatched numeric types
2016-09-25 02:54:16 +01:00
Jordan Olshevski d2b5f58808 Add formatUnequalValues struct test coverage
This expands the TestFormatUnequalValues test case to cover the behavior
of the function when provided two struct type'd values.
2016-09-24 17:22:54 -07:00
Michael Broll 3656ffd69b write test to simulate parallel execution of diff() 2016-09-06 17:15:19 -07:00
Jordan Olshevski 3bfb674961 Print types in failed numeric equality assertions
This addresses vague and misleading output when asserting on the
equality of two values of differing numeric types.

Example: assert.Equal(t, int64(123), int32(123))

Previously, the user would have received a vague message claiming that
123 != 123. Now the message will read "int64(123) != int32(123)".
2016-07-06 18:38:55 -07:00
Ernesto Jiménez d77da356e5 Fixes #311 - Detect empty interface error gotcha 2016-06-15 11:28:44 +02:00
Ernesto Jiménez 0f6478d3a8 Fixes #257 - InEpsilon works when actual == 0
Implemented new InEpsilon by calculating the relative error and
comparing it to the expected epsilon rather than calculating the
acceptable margin and using InDelta.

While doing so we got rid of the false failure when the actual value
was zero.
2016-01-09 17:37:37 +01:00
Ernesto Jiménez 3dad6b7b59 Add tests for workaround solution to #263 2016-01-09 02:56:16 +01:00
Cyrill Schumacher cd2b6c1151 Add check for empty time.Time struct (non pointer)
The standard library returns always a non-pointer Time type.
2016-01-07 07:55:48 +01:00
Ernesto Jiménez 67106a5111 Sort map keys before diffing maps 2015-11-11 20:37:34 +01:00
Matt Joiner 7d6ace9113 Handle case where one object is nil and the other is not 2015-11-07 19:02:25 +11:00
Ernesto Jiménez a76410419d Merge pull request #232 from stretchr/issue-136
Fix #136 - Empty returns true for nil pointers
2015-11-07 04:46:19 +00:00
Ernesto Jiménez 33c4c93911 Fixes #229 - show diffs for structs/maps/arrays/slices when Equal fails 2015-11-03 01:32:38 +00:00
Ernesto Jiménez c478a808a1 Fix #136 2015-11-02 01:41:59 +00:00
Ernesto Jiménez 40b02b9eef Merge pull request #165 from tuvistavie/master
Support map keys for Contains/NotContains assertion.
2015-11-01 21:02:28 +00:00
Ernesto Jiménez a0534acc7b Merge pull request #217 from juliancooper/assert-equivalent-json
Added assertion/requirement that checks if two JSON strings represent equivalent objects
2015-11-01 20:45:50 +00:00
Julian Cooper 7f6cb13c5c split JSONEq tests into individual assertions from one monolithic test 2015-10-13 13:36:47 -07:00
Bryan Matsuo ee60e76e54 Test Nil assertion behavior for typed nil values 2015-09-24 10:02:27 -07:00
Bryan Matsuo fb64a0ab08 Fix NotNil assertion for typed nil values
The NotNil assertion had an error in its handling of typed nil values.
This change makes use of the helper function isNil (used by the Nil
assertion).  The helper function has correct handling of typed nil
values and when negated provides the expected semantics for
`assert.NotNil(t, x)`.

    if x == nil {
        assert.Fail(t, "is nil", x)
    }
2015-09-23 23:48:02 -07:00
Julian Cooper 930ea90dbd Added assertion/requirement that checks if two JSON strings represent equivalent objects 2015-09-23 10:34:52 -07:00
Will Faught 8512261d41 Add Zero and NotZero assertions and requirements
Zero returns true if the value equals the value's type's zero value.

NotZero returns the opposite of Zero.
2015-08-24 15:53:36 -07:00