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

PragTob
Hello everyone, I know we had quite some threads (read through lots of them) about background job processing but it remains a hotly deba...
New
blackode
Elixir Upgrading is so Simple in Ubuntu and It worked for me Ubuntu 16.04 git clone https://github.com/elixir-lang/elixir.git cd elixir...
New
arpan
Hello everyone :wave: Today I am very excited to announce a project that I have been working on for almost 3 months now. The project is...
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
New
nburkley
AWS re:Invent is on at the moment with some interesting announcements. One new feature in particular is the Lambda Runtime API for AWS La...
New
Qqwy
Looking at the stacks that existing large companies have used, WhatsApp internally uses Mnesia to store the messages, while Discord uses ...
New
rms.mrcs
A couple of days ago I was discussing with a friend about different approaches to write microservices. He said that if he was going to w...
New
klo
Got a question about when to concat vs. prepending items to list then reversing to achieve appending. So i know lists boil down to [1 | ...
New
dogweather
I wrote this comment on r/haskell, and it’s not popular there. :wink: But I think I’m on to something… Haskell reminds me of Java, and e...
New

Other popular topics Top

sorentwo
Hello! tl;dr Announcing Oban, an Ecto based job processing library with a focus on reliability and historical observability. After spen...
985 42842 311
New
aesmail
Hello guys, I have finally made it. I created an admin interface for a framework. It’s been on my todo list for years and with the curre...
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
chrismccord
This release brings a number of exciting features, including integration with the new Phoenix LiveDashboard and Phoenix LiveView. There h...
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
jason.o
In the code below, if the create action is not set to accept “extra_key” as an input, it errors out with a message shown above. Is there ...
New
KronicDeth
Elixir plugin for JetBrain’s IntelliJ Platform (including Rubymine) This is a plugin that adds support for Elixir to JetBrains IntelliJ...
289 35953 110
New
dblack
I’ve got an issue with an app and I’ve no idea of how to troubleshoot it. I’m hoping someone here might have seen something similar. I p...
New
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
New
sergio
Kind of like when jquery came out, it was super necessary. Existing drag and drop libraries have a bunch of baggage to support old browse...
New

We're in Beta

About us Mission Statement