Re: [HUnit-users] automatic suite statements?
Status: Beta
Brought to you by:
dherington
|
From: Shae M. E. <sh...@Sc...> - 2002-08-05 18:51:34
|
Dean Herington <her...@cs...> writes:
> If you mean that you'd like simply to add the top-level definition for a new test
> case and have it included automatically in the set of tests to be run by HUnit, the
> answer is "no". Haskell doesn't provide the reflection capabilities needed to do
> this. With HUnit, you must construct the set of tests as a data structure. (On
> the plus side, it's so much easier to construct test suites as data structures in
> Haskell.)
Rumor on the #haskell irc channel is that Template Haskell will allow for
compile time reflection, I'm looking forward to that.
> But if you find it inconvenient to define a test case and separately add it to a
> test suite, there's no reason you couldn't simply define your new test case
> directly in the data structure representing the suite. Something like:
>
> suite = test [
> ... test 1 ... ,
> ... test 2 ... ,
> ... test 3 ...
> ]
That's an excellent idea, thanks. This covers what I want.
By the way, if you wish to use Hat 2.00 with HUnit, you need to apply the patch
below because Hat isn't flawless yet.
<paste>
> /home/shae/src/haskell/libraries/THUnitText.hs:64:
> Variable not in scope: `TPrelude.fnegate'
The problem here is with hat-trans - in the following definition,
put line pers (-1) = do ...; return (-1)
it has mistakenly interpreted the negative number literal on the left
hand side as a variable binding for negate. Hence, in the transformed
version of the code, it has used the lambda-bound form `fnegate'
on the right, instead of the real let-bound variable `gnegate'.
Until we can find a fix for hat-trans, here is a workaround for your
application. Replace the negative numeric literal pattern with another
form, such as a guard. For instance:
--- HUnitText.lhs Thu Feb 21 20:21:13 2002
+++ HUnitText.lhs.new Fri Jul 26 10:43:40 2002
@@ -55,7 +55,8 @@
> putTextToHandle handle showProgress = PutText put initCnt
> where
> initCnt = if showProgress then 0 else -1
-> put line pers (-1) = do when pers (hPutStrLn handle line); return (-1)
+> put line pers cnt | cnt == (-1)
+> = do when pers (hPutStrLn handle line); return (-1)
> put line True cnt = do hPutStrLn handle (erase cnt ++ line); return 0
> put line False cnt = do hPutStr handle ('\r' : line); return (length line)
> -- The "erasing" strategy with a single '\r' relies on the fact that the
</paste>
--
Shae Matijs Erisson - http://www.webwitches.com/~shae/
<radix> shapr: I think you *are* a purist :)
<radix> shapr: it's just that you're morally against unstable software, instead
of morally against MS, or non-free software, or whatnot.
|