James_E

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 = right
  • refute match?(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 < 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

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

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

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

Where Next?

Popular in Discussions Top

mbenatti
Following https://github.com/tbrand/which_is_the_fastest |&gt; https://raw.githubusercontent.com/tbrand/which_is_the_fastest/master/imgs...
New
restack_oslo
Hello, Please pardon me for any faux paux. I am 46 and this is my first time on a forum of any kind. I wanted to to get answers from tho...
New
und0ck3d
Hello everyone! A few days ago I’ve created a topic here about how people were creating CMSs with Elixir and Phoenix. I’ve been studying...
New
Fl4m3Ph03n1x
Background A few days ago I was listening to The future of Elixir from Elixir Talks, with Dave Thomas (@pragdave ) and Brian Mitchell. I...
New
eteeselink
Hi all, In the last days, two things happened: A blog post titled “They might never tell you it’s broken” made the rounds. It’s about ...
New
thojanssens1
It would be nice to be able to define a redirect from one route to another from the router.ex file. E.g.: redirect "/", UserController, ...
New
Rustixir
Hi everyone, im working on find best language/framework/system for high concurrency, high performance and stable performance after wor...
New

Other popular topics Top

Qqwy
Update: How to use the Blogs &amp; Podcasts section You can post links to your blog posts or podcasts either in one of the Official Blog...
3271 130286 1222
New
vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
grych
Hi folks, Few months ago I have announced the proof-of-concept of the library to manipulate the browsers DOM objects directly from Elixi...
639 54006 488
New
jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod – where is this set? Thanks.
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New

We're in Beta

About us Mission Statement