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

lud
Hello, I just extracted the boilerplate management code that I used to work with in previous years: It is yet another generic input d...
New
AstonJ
A recent chat with @leifericf inspired this thread - he’s worked in the gaming industry, and so it got me wondering what kind of industri...
New
neilberkman
Carson Katri from DockYard posted today about swift-erlang-actor-system, which enables Swift programs to join Erlang clusters as distribu...
New
bartblast
Hey there! :slight_smile: I’m working on updating the Hologram website home page and would love to get your input. Current situation: ...
New
ashkan117
I’m wondering how do people structure their JSON Api’s with Phoenix. Using the blogs example, let’s say I have a blogs view like the foll...
New
dogweather
I’ve been brainstorming about ways to solve the N-dimensional code organization problem, and am thinking about developing a Smalltalk-lik...
New
matreyes
I haven’t seen this paper being discussed by the community, but I think this makes Elixir more relevant than ever. TLDR; The paper...
New
kusokuzeshiki
I tried to generate pages with claude code and fluxon ui. I ask to claude code to generate real world page samples, the results are thes...
New
AstonJ
There seems to be a lot of buzz around DeepSeek at the moment, with some saying it’s a ChatGPT killer. The most remarkable thing (if they...
New
darkmarmot
At HCA Healthcare (500k employees and contractors), we’re currently experimenting with Elixir for both data integration (to handle parsin...
New

Other popular topics Top

vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
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 49522 488
New
KronicDeth
Elixir plugin for JetBrain’s IntelliJ Platform (including Rubymine) This is a plugin that adds support for Elixir to JetBrains IntelliJ...
289 35421 110
New
polypush135
As many of you may have realized by now (sorry for all the posts here) I’ve been working on a db problem where I’m trying to aggregate a ...
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
minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
johnnyicon
Hi all, I've just started learning Elixir and Phoenix Framework, so please pardon my n00bness at this stage. I'm trying to use Postg...
New
electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
belgoros
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New
AstonJ
by Lance Halvorsen Elixir and Phoenix are generating tremendous excitement as an unbeatable platform for building modern web application...
460 27162 124
New

We're in Beta

About us Mission Statement