mudasobwa

mudasobwa

Creator of Cure

Print out current binding from `assert/1`/`refute/1` macros in `ex_unit`

I am not sure it deserves to be discussed in the mailing list, so I’d start here.

assert/1 and/or refute/1 macros print the following error message when they fail during a direct comparison

Error:      test/file:line
     Expected truthy, got false
     code: assert value >= min_value and value <= max_value
     stacktrace:
       test/file:line: anonymous fn/3 in Test

It would be extremely helpful to print the binding reduced to the variables used in the expression, like

...
     code: assert value >= min_value and value <= max_value
     binding: value: 1.0, min_value: 2.0, max_value: 3.0

It’s an easy change and if there is an interest, I am open to either start a discussion in the mailing list or straight provide a PR doing this.

Most Liked

brettbeatty

brettbeatty

Would this just be for more complex expressions? For very basic comparisons, we already get the left/right printouts:

     Assertion with >= failed
     code:  assert value >= min_value
     left:  1.0
     right: 2.0

And that works with function calls as well

     Assertion with >= failed
     code:  assert calculate(input) >= min_value
     left:  1.0
     right: 2.0

If only the bindings were shown for something like this, you would see the value of input but not the more important value of calculate(input).
One could argue you would want to store the result in a variable for more complex comparisons, but maybe instead of just bindings it could be preferable to have a step-through of evaluation? Something like

     Expected truthy, got false
     code: assert value >= min_value and value <= max_value
     eval: assert 1.0 >= 2.0 and value <= max_value
           assert false and value <= max_value
           assert false

I don’t love that, though. But I’m not sure how best to show calculated values.

mudasobwa

mudasobwa

Creator of Cure

Well, I thought it would be a good addition to all of them. Yes, basic expressions do already print left and right, but even in your example it might be helpful to see input as well via bindings to quickly figure out why calculate(input) resulted in 1. Like

     Assertion with >= failed
     code:  assert calculate(input) >= min_value
     left:  1.0
     right: 2.0
     binding: input: nil, min_value: 2.0

It costs nothing but would play the role of binding inspector.

Where Next?

Popular in Proposals: Ideas Top

maxpohlmann
In our application, we have many structs that contain lists of floats and, especially in test, we often use pattern matching on these obj...
New
dimitarvp
To @jonatanklosko and @the-mikedavis: I see that there is a Rust crate at crates.io: Rust Package Registry but it is pointing at https:/...
New
mudasobwa
I am not sure it deserves to be discussed in the mailing list, so I’d start here. assert/1 and/or refute/1 macros print the following er...
New
sodapopcan
So after complaining about this for the third or fourth time on this forum, I figured I should make a proposal. TL;DR with can be hard t...
New
ffloyd
The Problem Currently, if I define a struct in the following way: defmodule MyStruct do # Both x and y will have the FIXED values unti...
New
7rans
I implemented Access behavior for a struct today. Pseudo-code… defmodule MyStruct do defstruct data: %{} @behaviour Access # ... ...
New
winsalva
Hello all. First of all i’m running this using termux on an android phone. Running mix assets.setup shows this message 06:54:08.450 [de...
New
Oliver
One common problem we face in constructing lists is that there is (AFAIK) no support for conditionally inserting members into list declar...
New
pejrich
I propose adding compact_map/2 to the Enum module. What is it? Sometimes you want to map over a collection, but sometimes you want to ma...
New
cevado
IEx is a very powerfull shell and it would be awesome to have all this power integrated inside a code editor. Clojure enables something l...
New

Other popular topics Top

Brian
What is the proper way to load a module from a file in to IEX? In the python world, doing something like this pretty standard: from ....
New
aalberti333
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this: ...
New
Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New
quazar
How to set Jason to encode all fields in ecto schema, I don’t care about security and implementing only is taking long list of attributes...
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
lk-geimfari
What is most correct way to open, read and parse JSON file with poison? For example if we have example.json file in root of some projec...
New
danschultzer
None of the current solutions worked well for me, so I went ahead and built a user management system from scratch. This project took far...
548 27727 240
New
aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New
josevalim
Hi everyone, One of the features added to Elixir early on to help integration with Erlang code was the idea of overridable function defi...
New
Nvim
Elixir appears to be a superior language to Python. I don’t see any advantage of Python over Elixir. Are there any?
New

We're in Beta

About us Mission Statement