如何使用Cabal设置简单测试?

时间:2009-06-25 15:22:59

标签: testing haskell cabal

我有一个Haskell项目和Cabal包描述,允许我使用

构建和安装我的包
$ cabal configure
$ cabal build
$ cabal install

但是cabal test呢? Cabal的帮助说用UserHooks配置测试套件,但我该怎么做呢?

2 个答案:

答案 0 :(得分:28)

正如Duncan在Greg的回答中提到的,Cabal-1.10支持开箱即用的测试套件。

manual似乎拥有关于如何使用此信息的最佳信息。

以下是手册中的一个片段,其中显示了如何使用exitcode-stdio测试类型:

<强> 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

<强>测试foo.hs:

module Main where

import System.Exit (exitFailure)

main = do
    putStrLn "This test always fails!"
    exitFailure

答案 1 :(得分:10)

有关一种方法,请参阅Setting up a simple test with Cabal

这种方法有缺点,并且有一个open Cabal ticket表明能够更直接地指定测试,例如

test
  test-is: Test
  build-depends: QuickCheck
  hs-source-dirs: tests src
相关问题