Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why do properties have to return boolean results? #187

Open
TylerPachal opened this issue Dec 7, 2020 · 1 comment
Open

Why do properties have to return boolean results? #187

TylerPachal opened this issue Dec 7, 2020 · 1 comment

Comments

@TylerPachal
Copy link

TylerPachal commented Dec 7, 2020

Hello,

I am wondering why properties have to return a boolean result instead of a truthy result like regular ExUnit assertions. As far as I know, it means that I cannot write properties which assert using a pattern match like the following, because the assert statement with a single = does not return a boolean value:

property "returns a map" do
  forall i <- pos_integer() do
    assert %{val: ^i} = make_map(i)      # This doesn't work and raises an error {:error, :non_boolean_result}
  end
end

This is just a toy example, often I have more complicated pattern matches where it would not be as easy to swap the single = for a double ==.

Is it possible to change the assertion to check for a truthy value instead of a boolean? Or is that a constraint of PropEr?

@alfert
Copy link
Owner

alfert commented Apr 25, 2021

Sorry for the late delay, but if you want to assert a match, I would suppose to use match?:

property "returns a map" do
  forall i <- pos_integer() do
    match?(%{val: ^i}, make_map(i))
  end
end

But I assume that your problem is that assert requires a boolean expression according to the Elixir docs. In PropCheck you can use assertions which is helpful alone for the better error reporting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants