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

Gre*_*con 41 testing haskell cabal

我有一个Haskell项目和Cabal包描述,允许我构建和安装我的包

$ cabal configure
$ cabal build
$ cabal install

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

Jac*_*ley 28

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

手册似乎有这就是我发现关于如何利用这个最好的信息.

以下是手册中的一个片段,其中显示了如何使用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
Run Code Online (Sandbox Code Playgroud)

测试foo.hs:

module Main where

import System.Exit (exitFailure)

main = do
    putStrLn "This test always fails!"
    exitFailure
Run Code Online (Sandbox Code Playgroud)

  • 请注意,为了使测试套件依赖于*install*,您必须运行`cabal install --enable-tests`.然后你可以运行`cabal test`来运行你的测试. (3认同)

Gre*_*con 10

有关一种方法,请参阅使用Cabal设置简单测试.

这种方法有缺点,并且有一个开放的Cabal票证,建议能够更直接地指定测试,例如,

test
  test-is: Test
  build-depends: QuickCheck
  hs-source-dirs: tests src
Run Code Online (Sandbox Code Playgroud)

  • 此功能将在Cabal-1.10中 (7认同)