3

I am running tests with Hspec and Quickcheck http://hspec.github.io/

The provided example to execute a random test case is

it "returns the first element of an *arbitrary* list" $
      property $ \x xs -> head (x:xs) == (x :: Int)

With associated output:

returns the first element of an *arbitrary* list 

How can I see the actual run-time values generated for the test? So given above example, sample desired output would include values passed for x and xs with something like:

returns the first element of an *arbitrary* list 
    \x xy head (x:xs) == (x :: Int) with x = 'a' and xs = "bc" holds 
brander
  • 121
  • 4

2 Answers2

1

No. Hspec's runner disables any QuickCheck output. Also, the random tests will provide a lot of noise. However, there's a workaround:

import Test.Hspec
import Test.QuickCheck
import Test.QuickCheck.Test (isSuccess)

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

main = hspec $ describe "head" $
  it "returns the first element of an *arbitrary* list" $
    verboseProperty $ \x xs -> head (x:xs) == (x :: Int)

However, the formatting will differ:

returns the first element of an *arbitrary* list
Passed:  
0
[]
Passed: 
1
[-1]
Passed:  
2
[-2]
Passed:  
3
[]
Passed:  
0
[]
Passed:  
1
[2,-5,5,5]
Passed:  
0
[-3,-1,-5,3]
…

There are of course more drawbacks, but that might be an easy way out. But passing tests aren't that interesting, it's the counter-examples that are more important—which are shown by default.

Zeta
  • 103,620
  • 13
  • 194
  • 236
1

With the new version of HSpec (>= 2.5.0) you just have to write it this way:

it "returns the first element of an *arbitrary* list" $
  verbose $ \x xs -> head (x:xs) == (x :: Int)

Look at the discussion here: https://github.com/hspec/hspec/issues/257

hnefatl
  • 5,860
  • 2
  • 27
  • 49
Nicolas Henin
  • 3,244
  • 2
  • 21
  • 42