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.
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.
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)
}
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`.
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
- NoError prints the error message on the next line, unquoted, which makes multiline error messages much clearer. Sample of an error message which includes a multiline stacktrace:
Error: Received unexpected error:
Hi!
/Volumes/Pouch/Users/russegan/dev/go/src/gitlab.protectv.local/ncryptify/client.git/client_test.go:27 (0x75c8c)
TestNew: assert.NoError(merry.New("Hi!"), "with message")
/usr/local/Cellar/go/1.7rc1/libexec/src/testing/testing.go:610 (0x70a01)
tRunner: fn(t)
/usr/local/Cellar/go/1.7rc1/libexec/src/runtime/asm_amd64.s:2086 (0x5d131)
goexit: BYTE $0x90 // NOP
Messages: with message
- Error,NoError,and EqualError now don’t inline the user’s extra messages. user’s messages are printed in the “Messages:” section, as with all other assertions.
- EqualError now avoids isNil(), mirroring the changes already made to Error and NoError.
- Equal, EqualValues, and EqualError now print the expected and actual values each on a newline, aligned vertically, which makes it easier for a human to visually detect the differences. Examples:
Error: Error message not equal:
expected: ”no failure"
recieved: “failure"
Messages: with message
Error: Not equal:
"high" (expected)
"low" (actual)
Messages: with message
- EqualValues uses the same value formatting and diff output as Equal for consistency
Go 1.7 subtests are called directly from testing.tRunner, not from the
test that contains the t.Run call. Because of this, the call stack
doesn't contain a function starting with Test, Benchmark, or Example,
causing assert.CallerInfo() to run off the end of the call stack and
return nil.
Look for testing.tRunner explicitly to solve this problem, and return
the list of callers if we do run off the call stack so that if there's a
similar problem in the future we still get an inflated stack trace
rather than no trace at all.
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)".