nick8325 / quickcheck

Automatic testing of Haskell programs.
Other
714 stars 119 forks source link

Weird behavior of Show instance for TFGen #171

Closed sol closed 7 years ago

sol commented 7 years ago

Steps to reproduce:

ghci> import Test.QuickCheck.Random 
ghci> gen <- newTheGen
ghci> (gen, "foo")

Expected output:

(TFGenR 00000B11BF8B90F7000000003B9ACA00000000000000E236000001827FB5D800 0 16384 15 0,"foo")

Actual output:

(TFGenR 00000B11BF8B90F7000000003B9ACA00000000000000E236000001827FB5D800 0 16384 15 0,"FOO")

Note the all-uppercase FOO here.

This also happens with the Show instance of Result, when it is Failure everything after usedSeed will be all-uppercase, e.g.:

ghci> quickCheckResult (== 0)
*** Failed! Falsifiable (after 2 tests and 1 shrink):     
1
Failure {numTests = 2, numShrinks = 1, numShrinkTries = 0, numShrinkFinal = 1, usedSeed = TFGenR 00000678041F2D79000000001DCD6500000000000000E23600000196FCEB4800 0 6 3 0, USEDSIZE = 1, REASON = "FALSIFIABLE", THEEXCEPTION = NOTHING, LABELS = [], OUTPUT = "*** FAILED! FALSIFIABLE (AFTER 2 TESTS AND 1 SHRINK): \N1\N"}
sol commented 7 years ago

I tried a couple of things but couldn't quite narrow it down.

sol commented 7 years ago

Found it:

instance Show Hex where
  showsPrec _ (Hex ba) =
    map toUpper .
    showHex' x1 .
    showHex' x2 .
    showHex' x3 .
    showHex' x4
    where
    (x1, x2, x3, x4) = readBlock256 ba
    showHex' x c = (pad $ showHex x "") ++ c
    pad s = take (16 - l) (repeat '0') ++ s
      where l = length s

map toUpper on the difference list, WTF!

sol commented 7 years ago

https://hub.darcs.net/michal.palka/tf-random/browse/src/System/Random/TF/Gen.hs#69

Apparently fixed upstream but not on Hackage?

sol commented 7 years ago

https://hub.darcs.net/michal.palka/tf-random/issue/8#comment-20150502T195204

Apparently tf-random is unmaintained.

sol commented 7 years ago

Thx!