【发布时间】:2010-11-05 21:13:58
【问题描述】:
我有一个 Haskell 项目和 Cabal 包描述,它允许我构建和安装我的包
$ cabal 配置 $ 阴谋集团 $ cabal 安装
但是cabal test 呢? Cabal 的帮助说要使用 UserHooks 配置测试套件,但我该怎么做呢?
【问题讨论】:
我有一个 Haskell 项目和 Cabal 包描述,它允许我构建和安装我的包
$ cabal 配置 $ 阴谋集团 $ cabal 安装
但是cabal test 呢? Cabal 的帮助说要使用 UserHooks 配置测试套件,但我该怎么做呢?
【问题讨论】:
正如 Duncan 在 Greg 的回答中提到的,Cabal-1.10 支持开箱即用的测试套件。
manual 似乎拥有我找到的关于如何使用它的最佳信息。
这是手册中的一个 sn-p,它展示了如何使用 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
test-foo.hs:
module Main where
import System.Exit (exitFailure)
main = do
putStrLn "This test always fails!"
exitFailure
【讨论】:
Cabal-Version: >= 1.10吗?还是早期的阴谋集团会无害地忽略它?
cabal install --enable-tests。然后你可以运行cabal test 来运行你的测试。
对于一种方法,请参阅Setting up a simple test with Cabal。
这种方法有缺点,有一个 open Cabal ticket 建议能够更直接地指定测试,例如,
test
test-is: Test
build-depends: QuickCheck
hs-source-dirs: tests src
【讨论】: