Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I set up a simple test with Cabal?

I have a Haskell project and Cabal package-description that allows me to build and install my package with

$ cabal configure
$ cabal build
$ cabal install

But what about cabal test? Cabal's help says to configure a test suite with UserHooks, but how can I do that?

like image 500
Greg Bacon Avatar asked Jun 25 '09 15:06

Greg Bacon


2 Answers

As Duncan mentioned in Greg's answer, Cabal-1.10 has support for test suites out of the box.

The manual seems to have the best information that's I've found regarding how to make use of this.

Here's a snippet from the manual which shows how to use the exitcode-stdio test type:

foo.cabal

Name:           foo
Version:        1.0
License:        BSD3
Cabal-Version:  >= 1.9.2
Build-Type:     Simple

Test-Suite test-foo
    type:       exitcode-stdio-1.0
    main-is:    test-foo.hs
    build-depends: base

test-foo.hs:

module Main where

import System.Exit (exitFailure)

main = do
    putStrLn "This test always fails!"
    exitFailure
like image 173
Jacob Stanley Avatar answered Nov 11 '22 20:11

Jacob Stanley


For one approach, see Setting up a simple test with Cabal.

This approach has drawbacks, and there's an open Cabal ticket that suggests being able to specify tests more directly, e.g.,

test
  test-is: Test
  build-depends: QuickCheck
  hs-source-dirs: tests src
like image 42
Greg Bacon Avatar answered Nov 11 '22 19:11

Greg Bacon