haskell - How to tap into hpc information during execution -
consider following use case: have quickcheck test suite consisting of 2 test cases prop_testcase1
, prop_testcase2
. using hpc can observe code coverage of test suite.
however, i'd separate results coverage of prop_testcase1
, prop_testcase2
(to further process results). 1 way out run executable several times explicitly specifying test case command line argument , process generated tix file after each run.
yet, prefer hide away logic in library. in reality run more 2 test cases. explicitly re-executing binary each test case seems rather inconvenient. @ same time i'd imagine hpc keeps coverage data in kind of intermediate data structure during program execution.
question: there way recognize program has been compiled hpc symbols , somehow access data hpc generates @ runtime?
i think found way achieve desired effect. required functions provided trace.hpc.reflect module. unfortunately documentation lacking.
nevertheless, here minimal example seems work:
import trace.hpc.reflect main :: io () main = print (show $ f 5) tix <- examinetix print (show tix) print (show $ f 6) print (show $ f 7) tix <- examinetix print (show tix) return () f x = x*2
compile , run follows:
$ ghc -fhpc main [1 of 1] compiling main ( main.hs, main.o ) linking main ... $ ./main "10" "tix [tixmodule \"main\" 3889152622 31 [1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1]]" "12" "14" "tix [tixmodule \"main\" 3889152622 31 [3,3,3,3,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, in1,1,1,1,0,0,0,0,0,1,1]]"
so using can tap coverage data provided hpc while program executing.
if executable compiled without hpc support program still works tix object returned examinetix contains empty list.
Comments
Post a Comment