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

Fix for counterexample crashing bug #327 #328

Merged
4 commits merged into from
Sep 11, 2021

Conversation

TysonMN
Copy link
Member

@TysonMN TysonMN commented Apr 14, 2021

Fixes #327

I think this PR fixes the bug where an exception isn't caught when checking a Property<_> containing counterexample. I got the idea for this fix by looking at Property.forall, which is the only other place that Property.counterexample is called. In the last commit, I removed the exception handling code from Property.forall since it is now happening in Property.bind.

How does this compare to the code in Haskell Hedgehog?

@AlexeyRaga, does the branch in this PR give the behavior that you expect?

@TysonMN
Copy link
Member Author

TysonMN commented Apr 14, 2021

The build fails because

Expecto_Expect_stringContains is not defined

when compiled by Fable. This is related to a test that I added.

@ThisFunctionalTom, do you have an opinion about how to fix this? Of course the brute force solution is to have Fable ignore this test.

@ThisFunctionalTom
Copy link
Contributor

The build fails because

Expecto_Expect_stringContains is not defined

when compiled by Fable. This is related to a test that I added.

@ThisFunctionalTom, do you have an opinion about how to fix this? Of course the brute force solution is to have Fable ignore this test.

I guess we can make a pull request in mocha to also implement Expect.stringContains or change the implementation to Expect.isTrue (report.Contains.... I think the first option is preferable.

@ThisFunctionalTom
Copy link
Contributor

I just made a pull request for it.
If you need more functions from Expect module we would probably need to copy the implementation from Expecto into Fable.Mocha but most of the time this should not be a problem I guess.

@TysonMN
Copy link
Member Author

TysonMN commented Apr 18, 2021

That PR seems like the right fix. Thanks @ThisFunctionalTom.

@ThisFunctionalTom
Copy link
Contributor

If you are in a hurry I guess we could extend the Expect module in FSharp.Hedgehog with a #if FABLE guard until the PR is merged.

@TysonMN
Copy link
Member Author

TysonMN commented Apr 18, 2021

I don't think there is any hurry. I would prefer to wait for that PR to be merged and a release to be made.

@ThisFunctionalTom
Copy link
Contributor

Sorry, have not got time for this. The pull request is already merged but we still have some troubles because we do not use the Except module from Mocha. I will look into it on the weekend.

@ThisFunctionalTom
Copy link
Contributor

ThisFunctionalTom commented May 1, 2021

Finally had some time to look into it.

The first problem is that Fable.Mocha does not have all the assertions from the Expect module as Expecto does. The stringContains is now added but there are a lot more missing.

If we are using only a few assertions we can copy the implementation from Expecto into TestDsl (not a really big fan of this solution) or we can make a pull request in Expecto repository to add the Expect.fs file into .fable directory of the Expecto nuget package (the same way we did it in fsharp-hedgehog) so all functions from Expect will work out of the box with fable compiler. I looked into it and it seams to complicated to do. There would be a lot of #if !FABLE_COMPILER guards.

The second problem is that we must open the correct namespace depending on FABLE_COMPILER. In one case it is Expecto namespace with submodule Expect and in the other case it is Fable.Mocha namespace with submodule Expect. I tried to abstract this away with TestDsl module but it does not work because each test file must open its own namespaces.
We have 3 2 options here:

  • use #if FABLE_COMPILER in each file and open different Expect modules like this
    # if FABLE_COMPILER
    open Fable.Mocha
    #else
    open Expecto
    #endif
  • alias or implement all used assertions in TestDsl module like I did for isTrue and stringContains
  • if we succeed in making Expecto more fable friendly by adding Expect.fs into .fable directory I guess it should work for most/all of the assertions from the Expect module.

The pull request with the fixed PropertyTests can be found here:
https://github.com/ThisFunctionalTom/fsharp-hedgehog/tree/bug/327_counterexample_crashes

How should we proceed? What do you think?

@TysonMN
Copy link
Member Author

TysonMN commented May 1, 2021

The first problem is that Fable.Mocha does not have all the assertions from the Expect module as Expecto does.

I would prefer if any assertions we need were added to Fable.Mocha.

The second problem is that we must open the correct namespace depending on FABLE_COMPILER. In one case it is Expecto namespace with submodule Expect and in the other case it is Fable.Mocha namespace with submodule Expect.

We don't have very many test files. I think it is fine to add the code in your comment to the top of each file.

@ThisFunctionalTom
Copy link
Contributor

ThisFunctionalTom commented May 1, 2021

The first problem is that Fable.Mocha does not have all the assertions from the Expect module as Expecto does.

I would prefer if any assertions we need were added to Fable.Mocha.

The second problem is that we must open the correct namespace depending on FABLE_COMPILER. In one case it is Expecto namespace with submodule Expect and in the other case it is Fable.Mocha namespace with submodule Expect.

We don't have very many test files. I think it is fine to add the code in your comment to the top of each file.

OK. I will change my pull request for your pull request (:trollface:) accordingly.

Yeah, about that... I am not sure how much of Expecto Expect module should I copy to Fable.Mocha. Currently we are using just 2 assertions but I guess it will be more and if we always copy just 1-2 functions Zaid will not be very happy with us 😉

Would it be OK to copy the implementation of the assertions to our TestDsl.fs file into Expect module and once we have more functions in the module we can make a merge request for Fable.Mocha?

@TysonMN
Copy link
Member Author

TysonMN commented Sep 4, 2021

Would it be OK to copy the implementation of the assertions to our TestDsl.fs file into Expect module and once we have more functions in the module we can make a merge request for Fable.Mocha?

Yes. This seems fine.

@TysonMN TysonMN force-pushed the bug/327_counterexample_crashes branch from d76d81b to 0450f76 Compare September 9, 2021 01:03
@TysonMN
Copy link
Member Author

TysonMN commented Sep 9, 2021

The most recent commit in this branch adds a workaround for the Fable compiler so that the tests pass. This is now ready to be merged.

@ghost ghost added this to the 0.11.0 milestone Sep 9, 2021
Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Found a few things, mostly around exposing new public API.

src/Hedgehog/Property.fs Outdated Show resolved Hide resolved
src/Hedgehog/Property.fs Outdated Show resolved Hide resolved
src/Hedgehog/Property.fs Outdated Show resolved Hide resolved
src/Hedgehog/Property.fs Outdated Show resolved Hide resolved
@TysonMN TysonMN force-pushed the bug/327_counterexample_crashes branch from e23f434 to 184b321 Compare September 10, 2021 00:42
@TysonMN
Copy link
Member Author

TysonMN commented Sep 10, 2021

@adam-becker, I think I addressed all the comment in your review. I left them unresolved so that is easy for you to double check them.

When you are satisfied, I would prefer to squash the commits a bit. Then we can merge.

@TysonMN TysonMN force-pushed the bug/327_counterexample_crashes branch from 004e457 to 5eadd06 Compare September 11, 2021 03:46
@TysonMN
Copy link
Member Author

TysonMN commented Sep 11, 2021

I decided to squash the commits. I think this is ready to merge.

@TysonMN TysonMN force-pushed the bug/327_counterexample_crashes branch from 5eadd06 to 2c9b721 Compare September 11, 2021 17:45
@TysonMN
Copy link
Member Author

TysonMN commented Sep 11, 2021

Rebased on master (for clarity) even though there were no conflicts

@ghost
Copy link

ghost commented Sep 11, 2021

Looks good to me! Thanks @TysonMN

@ghost ghost merged commit 2e0d21c into hedgehogqa:master Sep 11, 2021
@TysonMN TysonMN deleted the bug/327_counterexample_crashes branch September 11, 2021 18:02
This pull request was closed.
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

Successfully merging this pull request may close these issues.

Bug: counterexample breaks in presence of exceptions
2 participants