Search code examples
haskellcharacter-encodingcabalquickcheck

unreadable quickcheck log file after a test routine


I made a test routine for a Haskell program with quickcheck. I declared it in my cabal file with :

Test-Suite routine_de_test
  Type:               exitcode-stdio-1.0
  Hs-Source-Dirs:     test
  Main-is:            Tests.hs

and launched it with :

cabal configure --enable-tests
cabal buil
cabal test

The tests are processed correctly and I was expecting to see details about the random value used for each test in the log file dist/test/ but when I open it, the file looks like this :

enter image description here

I tried to open the file with several encoding (UTF8, ISO-8859-15, ...) but nothing is changed.

Is it normal? Or is there something wrong?

Is it possible when performing quickcheck test from cabal to get the complete list of random values used for each tests?


Solution

  • It looks like the funny characters are simply backspaces, and quickcheck is simply reporting the number of tests it has performed so far by overwriting (0 tests) with (1 test) and then (2 tests) and then with (3 tests), etc.

    Visually it will look fine when displayed to a terminal.

    Update:

    To report the random values used for a test the only way I know of is to write your test to explicitly display (or save to a file) the values used.

    If your test is a pure function you can use the trace function from Debug.Trace. For instance, if you have this property:

    prop_commutes :: Int -> Int -> Bool
    prop_commutes a b = a + b == b + a
    

    You can trace each invocation of prop_commutes by modifying like this:

    import Debug.Trace
    
    prop_commutes :: Int -> Int -> Bool
    prop_commutes x y = a + b == b + a
      where (a,b) = trace ("(a,b) = " ++ show (x,y)) (x,y)
    

    and then quickCheck prop_commutes will emit lines like:

    (x,y) = (20,-73)
    (x,y) = (71,-36)
    (x,y) = (2,-11)
    ...
    

    in addition to its normal output.