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

QuickCheck Imp integration #3886

Merged
merged 2 commits into from
Nov 22, 2023
Merged

QuickCheck Imp integration #3886

merged 2 commits into from
Nov 22, 2023

Conversation

lehins
Copy link
Contributor

@lehins lehins commented Nov 21, 2023

Description

Changes in this PR allows us to write QuickCheck properties with ImpSpec:

We can either use Arbitrary (however only for a single argument, which can be a nested tuple):

  it "test1" $ \(foo, blah) -> do
    kh <- freshKeyHash
    show kh `shouldBe` foo
    blah `shouldBe` foo

or manually running an ImpTestM somewhere inside a regular hspec/quickcheck property

  it "test2" $ \impState ->
    forAll arbitrary $ \foo ->
      forAll arbitrary $ \blah ->
        evalImpTestM impState $ do
          kh <- freshKeyHash
          show kh `shouldBe` foo
          blah `shouldBe` foo

Checklist

  • Commit sequence broadly makes sense and commits have useful messages
  • New tests are added if needed and existing tests are updated
  • When applicable, versions are updated in .cabal and CHANGELOG.md files according to the
    versioning process.
  • The version bounds in .cabal files for all affected packages are updated. If you change the bounds in a cabal file, that package itself must have a version increase. (See RELEASING.md)
  • All visible changes are prepended to the latest section of a CHANGELOG.md for the affected packages. New section is never added with the code changes. (See RELEASING.md)
  • Code is formatted with fourmolu (use scripts/fourmolize.sh)
  • Cabal files are formatted (use scripts/cabal-format.sh)
  • hie.yaml has been updated (use scripts/gen-hie.sh)
  • Self-reviewed the diff

Copy link
Contributor

@Soupstraw Soupstraw left a comment

Choose a reason for hiding this comment

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

Nice!

This allows us to write property tests using ImpTest:

```haskell
  it "test" $ \impState -> do
    forAll arbitrary $ \foo -> evalImpTestM impState $ do
      kh <- freshKeyHash
      show kh `shouldBe` foo
```
This allows us writing imp tests like this:

```haskell
  it "test1" $ \(foo, blah) -> do
    kh <- freshKeyHash
    show kh `shouldBe` foo
    blah `shouldBe` foo
```
@lehins lehins merged commit afedb7d into master Nov 22, 2023
11 of 22 checks passed
@iohk-bors iohk-bors bot deleted the lehins/qc-imp-integration branch November 22, 2023 12:52
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.

None yet

2 participants