HSpec output option

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Baa
Reply | Threaded
Open this post in threaded view
|

HSpec output option

Baa
Hello, Dear List!

I have tests: I'm using HSpec (and QuickCheck too). And I have tests
like this:

  describe "Something" $ do
    it "something is correct" $ do
      ...blah-blah...
    it "any string is correct" $ property $
      \s -> all (=='*') (Something s) -- it's for example only!!!

so something like unit-test and property checks in one SomethingSpec.hs.

I'm running them with this Makefile:

  .PHONY: test fast-test

  fast-test:
  stack exec runhaskell -- -isrc -itest test/Spec.hs

  test:
  stack test

and in Spec.hs I have:

  {-# OPTIONS_GHC -F -pgmF hspec-discover #-}

That's all. So, when I find failed test, I get a trace like this:

  ...
  Failures:

    test/SomethingSpec.hs:172:
     1) BlahBlah.superFunc any string is correct:
        result Gave up after 48 tests
  ...etc...

So, my question is: when QuichCheck runs my property test, it passes
argument to property's lambda. And on 48th test attempt with some
concreate argument value my check fails. How can I get detailed output
from such test environment, to see what concreate arguments lead to
failure? To see something (or similar/or more detailed even):

  Failed with arguments: s = ""

Is it possible (I run them with stack and with runhaskell too) ?

===
Best regards, Paul
_______________________________________________
Beginners mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
Baa
Reply | Threaded
Open this post in threaded view
|

Re: HSpec output option

Baa
I will answer myself, because it is possible that someone will need
this answer. Reason of the problem was with one "test operator" only:
`==>` - it's something like imlication but has one difference. I
implemented own (standard) implication as:

  (-->) :: Bool -> Bool -> Bool
  True  --> True  = True
  True  --> False = False
  False --> True  = True
  False --> False = True
  infixr 0 -->

and use it instead of `==>`. And with this operator (used in QuickCheck
properties testing) I get output of case's values which leads to fail in
my tests. So, test looks like:

  ...
  describe "Some func test" $ do
    prop "negative input becomes positive" $ do
      \n -> n < 0 --> someFunc n >= 0
  ...

To see all QuickCheck generated values, I can use alternative
(verbose) `property` and `prop` funcs:

  verbproperty :: Testable prop => prop -> Expectation
  verbproperty p = verboseCheckResult p >>= (`shouldBe` True) . isSuccess

  verbprop :: (HasCallStack, Testable prop) => String -> prop -> Spec
  verbprop s = it s . vproperty

All is for HSpec tests (with QuickCheck properties)...

===
Best regards, Paul


> Hello, Dear List!
>
> I have tests: I'm using HSpec (and QuickCheck too). And I have tests
> like this:
>
>   describe "Something" $ do
>     it "something is correct" $ do
>       ...blah-blah...
>     it "any string is correct" $ property $
>       \s -> all (=='*') (Something s) -- it's for example only!!!
>
> so something like unit-test and property checks in one
> SomethingSpec.hs.
>
> I'm running them with this Makefile:
>
>   .PHONY: test fast-test
>
>   fast-test:
>   stack exec runhaskell -- -isrc -itest test/Spec.hs
>
>   test:
>   stack test
>
> and in Spec.hs I have:
>
>   {-# OPTIONS_GHC -F -pgmF hspec-discover #-}
>
> That's all. So, when I find failed test, I get a trace like this:
>
>   ...
>   Failures:
>
>     test/SomethingSpec.hs:172:
>      1) BlahBlah.superFunc any string is correct:
>         result Gave up after 48 tests
>   ...etc...
>
> So, my question is: when QuichCheck runs my property test, it passes
> argument to property's lambda. And on 48th test attempt with some
> concreate argument value my check fails. How can I get detailed output
> from such test environment, to see what concreate arguments lead to
> failure? To see something (or similar/or more detailed even):
>
>   Failed with arguments: s = ""
>
> Is it possible (I run them with stack and with runhaskell too) ?
>
> ===
> Best regards, Paul
_______________________________________________
Beginners mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners