orome
orome

Reputation: 48576

How to I suppress reporting of each test in QuickCheck, without suppressing summary output?

In QuickCheck, is there a way to suppress the

(0 tests)         (1 test)        (2 tests)         (3 tests)         (4 tests)  ...

output without suppressing the summary

+++ OK, passed 500 tests.

output?

I've tried setting chatty = False, but that suppresses both.

Upvotes: 2

Views: 190

Answers (1)

Zeta
Zeta

Reputation: 105935

Since you're only interested in the summary output, you could use quickCheckWithResult together with chatty = False:

silentQuickCheck :: Testable prop => prop -> IO () 
silentQuickCheck p = quickCheckWithResult stdArgs { chatty = False } p >>= putStr . output

Example:

main = do
   putStrLn "Even: "
   silentQuickCheck even
   putStrLn "Odd: "
   silentQuickCheck odd
   putStrLn "ID Eq: "
   silentQuickCheck $ \n -> n == n

Output:

Even:
*** Failed! Falsifiable (after 6 tests):
3
Odd: 
*** Failed! Falsifiable (after 1 test):
0
ID Eq:
+++ OK, passed 100 tests.

However, on terminals/outputs that move the cursor backwards on\b (ASCII backspace), the test count ((xx tests)) gets rewritten over and over again, so this is only necessary if your output/terminal doesn't acknowledge \b in this sense.

Upvotes: 4

Related Questions