NorfairKing / sydtest

A modern testing framework for Haskell with good defaults and advanced testing features.
113 stars 25 forks source link

Support for Hedgehog properties with resources #49

Closed L7R7 closed 2 years ago

L7R7 commented 2 years ago

I'd like to test a WAI app using Hedgehog. However, I don't get it to compile. The QuickCheck version does compile. The following is a minimal example of what I'd like to do (it doesn't make a lot of sense but it's enough to demonstrate the problem:

application :: Application 
application = undefined

spec :: Spec
spec = waiClientSpecWith application $ do
  it "reversing twice is the same as not reversing" $ \_ ->
      QC.property $ \(ls :: [Int]) ->
        reverse (reverse ls) `shouldBe` ls

  it "reversing twice is the same as not reversing" $  \_ ->
      property $ do
        xs <- forAll $ Gen.list (Range.linear 0 100) Gen.alpha
        reverse (reverse xs) === xs

The error is:

    • Couldn't match type ‘Arg1 (p0 -> Property)’ with ‘()’
        arising from a use of ‘it’
      The type variable ‘p0’ is ambiguous
    • In the first argument of ‘($)’, namely
        ‘it "reversing twice is the same as not reversing"’
      In a stmt of a 'do' block:
        it "reversing twice is the same as not reversing"
          $ \ _
              -> property
                   $ do xs <- forAll $ Gen.list (Range.linear 0 100) Gen.alpha
                        reverse (reverse xs) === xs
      In the second argument of ‘($)’, namely
        ‘do it "reversing twice is the same as not reversing"
              $ \ _ -> QC.property $ \ (ls :: [Int]) -> ...
            it "reversing twice is the same as not reversing"
              $ \ _ -> property $ do ...’
   |        
18 |   it "reversing twice is the same as not reversing" $  \_ ->
   | 

Am I missing something? Is there a way to support hedgehog properties or do I need to use QuickCheck for such tests?

NorfairKing commented 2 years ago

Jup, there's an instance missing here: https://github.com/NorfairKing/sydtest/blob/e55fad0f6b8058a9b44c6c0d66bdd3c3be556d71/sydtest-hedgehog/src/Test/Syd/Hedgehog.hs#L32-L35 You can take inspiration from here: https://github.com/NorfairKing/sydtest/blob/e55fad0f6b8058a9b44c6c0d66bdd3c3be556d71/sydtest/src/Test/Syd/Run.hs#L167-L180