[Haskell-cafe] Hunit Testing
byorgey at seas.upenn.edu
Wed Oct 12 04:28:16 CEST 2011
On Wed, Oct 12, 2011 at 03:55:43AM +0530, mukesh tiwari wrote:
> Hello everyone
> I was going through this tutorial
> http://hunit.sourceforge.net/HUnit-1.0/Guide.html and just wrote some simple
> code but i am getting error
> ghci>let test1 = TestCase (assertEqual " equal " 3 ( id 3 )) ghci>let
> tests = [ TestLabel "test 1" test1 ]ghci>runTestTT tests
> Couldn't match expected type `Test' with actual type `[Test]'
> In the first argument of `runTestTT', namely `tests'
> In the expression: runTestTT tests
> In an equation for `it': it = runTestTT tests
> Could some one please tell me what is wrong with this code.
This is something you should be able to figure out yourself. The
error message is actually quite good. It says that it expects 'tests'
to have type 'Test', but it actually has type '[Test]'. We can see
why it has type [Test]: it is defined as
tests = [ TestLabel ... ]
that is, a list with a single element. So why is its type *expected*
to be 'Test'? Well, look at the type of runTestTT:
runTestTT :: Test -> IO Counts
It expects a Test as its argument.
So, that is what is wrong. The right way to fix it is not as obvious,
but Ivan already covered that.
More information about the Haskell-Cafe