Haskell Stack Ghci test-suite

别来无恙 提交于 2019-12-03 12:03:15

问题


I'm trying to use stack to load my test-suite in ghci and have it load the QuickCheck and hspec dependency.

How can I do this?

I'm using the franklinchen template.
https://github.com/commercialhaskell/stack-templates/blob/master/franklinchen.hsfiles

I have tried
stack ghci spec
stack ghci test-suite
stack ghci --main-is spec

I modified the test-suite spec to target the main-is: LibSpec.hs file

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:


stack ghci --test

Note that this will only work if there's a single test suite and no other executable. Otherwise it will give you a warning:

* * * * * * * *
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
* * * * * * * *

In this case you have to use

stack ghci --test chapterexercises:test:spec

Without --test stack is going to ignore the tests. That's why you don't get the ambiguity error in the first place.



来源:https://stackoverflow.com/questions/34558002/haskell-stack-ghci-test-suite

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!