Haskell Stack Ghci 测试套件

Haskell Stack Ghci test-suite

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

我该怎么做?

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

我试过了
堆栈 ghci 规范
堆栈 ghci 测试套件
堆栈 ghci --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
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 堆栈将忽略测试。这就是为什么您一开始就不会收到歧义错误的原因。