首页 文章

Haskell Stack Ghci测试套件

提问于
浏览
11

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

我怎样才能做到这一点?

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

我试过了
堆栈ghci规范
stack ghci测试套件
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 回答

  • 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 堆栈将忽略测试 . 那个's why you don' t首先得到歧义错误 .

相关问题