Testing was Re: main modules in GHC, deriving differences between
GHC and Hugs
Matthew Donadio
m.p.donadio@ieee.org
Fri, 13 Jun 2003 20:06:37 -0400
(redirected to haskell-cafe)
Hal Daume III wrote:
> Yes, but there's a problem with this solution. Namely, if Foo.hs takes a
> long time to compile, then you can't leverage having already created Foo.o
> and Foo.hi when making the Main.
Yeah, it's not perfect, but I think we just have different methodologies
for testing.
Typically, I do most of my development with ghci or hugs. Each module
will have a single variable that represents the tests
tests :: [Bool]
tests = [ test1, test2, test3 ... ]
and then I define a variable called
test :: Bool
test = and tests
so I can just load a module and either evaluate tests or test to check
things out. This generalizes to importing and testing several modules
at once (as long as I take care of name conflists).
This only works for simple modules, though. For more complicated ones,
I have a "pretty" tester. For example, my Haskell FFT library is
collection of mutually recursive modules. I have a specialzed test
function for this that tests a range of lengths. It looks someone like
main = testfft n1 n2
testfft n1 n2 = sequence $ map test1fft [n1..n2]
test1fft n = do putStr $ show n ++ ":\t"
putStr $ if ok then "OK\n" else "ERROR\n"
where ok = and [ test1 n, test2 n, test3 n ]
This way I can compile the code, and run the executable as
ffttest 2 2048 | grep ERROR
and I am confident that I get full coverage of the algorithm.
I am always to hear about other methods of automated testing.
--
Matthew Donadio (m.p.donadio@ieee.org)