Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use detailed-0.9 in cabal testing

I'm having a surprising amount of difficulty getting the unit tests to run under cabal. I've copied the test code verbatim from the cabal documentation, with the exception of changing the module name

{-# LANGUAGE FlexibleInstances #-}
module Test.Integral ( tests ) where

import Distribution.TestSuite

instance TestOptions (String, Bool) where
    name = fst
    options = const []
    defaultOptions _ = return (Options [])
    check _ _ = []

instance PureTestable (String, Bool) where
    run (name, result) _ | result == True = Pass
                         | result == False = Fail (name ++ " failed!")

test :: (String, Bool) -> Test
test = pure

-- In actual usage, the instances 'TestOptions (String, Bool)' and
-- 'PureTestable (String, Bool)', as well as the function 'test', would be
-- provided by the test framework.

tests :: [Test]
tests =
    [ test ("bar-1", True)
    , test ("bar-2", False)
    ]

However, when I try to build the tests, I get the following messages:

Test/Integral.hs:6:10:
    Not in scope: type constructor or class `TestOptions'

Test/Integral.hs:12:10:
    Not in scope: type constructor or class `PureTestable'

I tried importing them directly from Distribution.TestSuite, but it said that they weren't exported. This is simple enough that I have to be doing something stupid, but I can't see what it is.

like image 626
rprospero Avatar asked Aug 20 '13 19:08

rprospero


1 Answers

There is not much support for detailed-0.9 out there. It's possible to hook up existing testing libraries to use it, but even then you will not get progress information as tests pass.

I recommend to use the exitcode-stdio-1.0 interface together with an existing testing framework + use GHCi during development.

A full example for Hspec is here https://github.com/sol/hspec-example.

like image 123
Simon Hengel Avatar answered Nov 03 '22 10:11

Simon Hengel