Haskell Stack Ghci测试套件

时间:2016-01-01 16:48:38

标签: haskell cabal haskell-stack

我试图使用堆栈在ghci中加载我的测试套件并让它加载QuickCheck和hspec依赖。

我该怎么做?

我使用franklinchen模板。
https://github.com/commercialhaskell/stack-templates/blob/master/franklinchen.hsfiles

我试过了 stack ghci spec
stack ghci test-suite
stack ghci --main-is spec

我修改了测试套件规范以定位main-is:LibSpec.hs文件

test-suite spec
  default-language:    Haskell2010
  ghc-options:         -Wall
  type:                exitcode-stdio-1.0
  hs-source-dirs:      test
  main-is:             LibSpec.hs
  build-depends:       base
                     , chapterexercises
                     , hspec
                     , QuickCheck

1 个答案:

答案 0 :(得分:13)

stack ghci --test

请注意,只有在有一个测试套件而没有其他可执行文件的情况下,这才有效。否则它会给你一个警告:

* * * * * * * *
The main module to load is ambiguous. Candidates are:
Package `project' component exe:project-exe with main-is file: T:\project\app\Main.hs
Package `project' component test:project-test with main-is file: T:\project\test\Spec.hs
None will be loaded. You can specify which one to pick by:
 1) Specifying targets to stack ghci e.g. stack ghci project:exe:project-exe
 2) Specifying what the main is e.g. stack ghci --main-is project:exe:project-exe
* * * * * * * *

在这种情况下,您必须使用

stack ghci --test chapterexercises:test:spec

没有--test堆栈会忽略测试。这就是为什么你不首先得到模棱两可的错误。