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

Re-running counterexamples ignores changes to generators #30

Closed
evnu opened this issue Nov 29, 2017 · 9 comments
Closed

Re-running counterexamples ignores changes to generators #30

evnu opened this issue Nov 29, 2017 · 9 comments

Comments

@evnu
Copy link
Collaborator

evnu commented Nov 29, 2017

#10 added re-running failing counterexamples. If the fix to a failing property is to change the generators, the counterexample will keep on failing until the persisted file is deleted.

Consider this obviously failing example:

property "failing" do
  forall x <- nat() do
    is_float(x)
  end
end

Now, we fix this example by changing the generator:

property "failing" do
  forall x <- float() do
    is_float(x)
  end
end

But due to how counterexamples currently work, we still receive an error:

  1) property failing (PropTest)
     test/prop_test.exs:5
     Property Elixir.PropTest.property failing() failed. Counter-Example is:
     [0]
     
     code: nil
     stacktrace:
       (propcheck) lib/properties.ex:107: PropCheck.Properties.handle_check_results/3
       test/prop_test.exs:5: (test)
@evnu
Copy link
Collaborator Author

evnu commented Jan 29, 2018

Would it be possible to peek into the block passed into PropCheck and determine if the generators changed since the counter example was stored? I don't know how stable the internal property definitions within PropEr are. Maybe :erlang.phash2(p) is enough?

@evnu
Copy link
Collaborator Author

evnu commented Feb 20, 2018

@alfert Do you have an idea how this could be fixed?

@alfert
Copy link
Owner

alfert commented Feb 22, 2018

Hmm, do you mean that we store a hash of the generator definition (= of the AST) together with the counter example? So, we could check whether this has changed and in that case rerun the property from scratch (i.e. without using the counter example)? I assume that this should work.

@evnu
Copy link
Collaborator Author

evnu commented Feb 22, 2018

Yes, that's what I meant. I was not yet able to come up with a way to retrieve such a hash yet, though.

@alfert
Copy link
Owner

alfert commented Feb 23, 2018

It depends on what the hash is about. If the generator is "only" the part of forall up to do, this should do-able, since the macro gets the AST for the generator and the do-part as argument. Putting this into an hash-function is easy. After that we only have to use it properly. i.e. inject it into a function that checks whether the hash differs etc. What will not work is to detect whether the definition of nat() has changed (according to your example above).

@evnu
Copy link
Collaborator Author

evnu commented Mar 19, 2018

What will not work is to detect whether the definition of nat() has changed (according to your example above).

For "simple" generators, it might be possible to remember the seed value (if there is such a thing) when a test failed, use that to produce an extra value and store that and the seed along with the counter example. Now, before running the counter example, we could try to regenerate this stored value. If that succeeds, we know that the generator did not change. If we fail to do that, either the generator changed, or it was not deterministic enough. In either case, we should try to run the property without the counter example. @alfert Do you know if PropEr uses a seed when evaluating generators? If so, is it possible to influence this?

@evnu
Copy link
Collaborator Author

evnu commented May 29, 2018

@alfert I think this can be closed. I can't think of a usable solution to solve this beside the additional informational output from #52.

@evnu
Copy link
Collaborator Author

evnu commented May 31, 2018

For future reference, this pull request in PropEr seems related (setting a seed for reproducibility).

@alfert
Copy link
Owner

alfert commented Oct 28, 2019

As proposed in May, i.e. 6 month ago, I close this item.

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

2 participants