James_E
Broader "assert" and "refute" support?
I see that the current ExUnit source code has support for rich failure messages on a small whitelist of “recognized” assertion patterns, namely:
assert match?(left, right),assert left = rightrefute match?(left, right),refute left = rightassert left === right,refute left !== right,assert left !== right,refute left === right,assert left == right,refute left != right,assert left != right,refute left == right,assert left >= right,refute left < right,assert left > right,refute left <= rightassert left <= right,refute left > rightassert left < right,refute left >= rightassert left ~= rightrefute left ~= right
Would there be any interest in a pull request adding support for an additional pattern:
refute left and not right(implication, right must be true whenever left is)
This pattern is coming up repeatedly as the most robust, developer-intent-communicating form for some unittests I’m writing:
property "delete returns a well-formed multiset whenever input is well-formed" do
check all ms <- t(term(), strict: false),
value <- term(),
count <- one_of([non_negative_integer(), constant(:all)]) do
result = One9.Ms.delete(ms, value, count)
refute One9.Ms.well_formed?(ms) and not One9.Ms.well_formed?(result)
end
end
property "put 0 copies doesn't corrupt struct" do
check all multiset <- t(term()), value <- term() do
result = One9.Multiset.put(multiset, value, 0)
assert One9.Ms.well_formed?(result.counts)
assert One9.Multiset.equals?(result, multiset)
refute One9.Multiset.member?(result, value) and not One9.Multiset.member?(multiset, value)
end
end
And having these tests augmented with a little bit of extra verbiage and awesome debug formatting, like the comparison checks currently have, would be a minor boon.
Most Liked
fuelen
When guards are failing, boolean logic is highlighted with colours. I don’t see any reason why it shouldn’t be supported in ExUnit as well.
As @christhekeele has already suggested, please start a discussion on the core mailing list.
christhekeele
This seems like a reasonable conversation to start on the core mailing list, if you can’t find a prior discussion.
I think property-based testing and other test design philosophy is orthogonal to this discussion:
- Elixir has special forms and operators
- ExUnit tries to provide pretty formatting when recognizing some assertions on the language’s forms
- Whether or not it can do better by recognizing some boolean operator combinations and formatting them specially is a conversation worth having
- Regardless of testing practices









