Sta*_*iff 5 testing haskell haskell-stack
Haskell初学者在这里.
我正在努力找到一种很好的方法来运行我在我的.cabal文件中定义的测试套件.鉴于您test-suite在.cabal文件中添加了部分,我希望您可以使用单个命令来运行所有部分stack runtests.
我找到的最佳答案是: Haskell Stack Ghci测试套件,建议您必须运行
stack ghci --test module:test:libtests
然而,有两件事让我很恼火,我认为必须有一个更好的方法.
stack ghci --test module:test:libtests明确地调用是很麻烦的.如果我在项目变大时有更多的测试套件,我不想这样做.main自己打电话.这不规模.是不是有更好的方法来为堆栈项目运行测试套件?当然我可以做一些shell脚本,但是嘿堆栈应该知道如何运行我的测试,我在.cabal文件中指定了所有内容.
我试过stack runghc --test但这没有用.
项目设置:
.
??? app
? ??? Main.hs
??? LICENSE
??? README.md
??? Setup.hs
??? src
? ??? Lib.hs
? ??? WordNumber.hs
??? stack.yaml
??? test
? ??? Spec.hs
??? WordNumber.cabal
Run Code Online (Sandbox Code Playgroud)
WordNumber.cabal
name: WordNumber
version: 0.1.0.0
-- synopsis:
-- description:
homepage: https://github.com/githubuser/WordNumber#readme
license: BSD3
license-file: LICENSE
author: Author name here
maintainer: example@example.com
copyright: 2017 Author name here
category: Web
build-type: Simple
extra-source-files: README.md
cabal-version: >=1.10
library
hs-source-dirs: src
exposed-modules: Lib, WordNumber
build-depends: base >= 4.7 && < 5
default-language: Haskell2010
executable wordnumber
hs-source-dirs: app
main-is: Main.hs
ghc-options: -threaded -rtsopts -with-rtsopts=-N
build-depends: base
, WordNumber
default-language: Haskell2010
test-suite wordnumber-test
type: exitcode-stdio-1.0
hs-source-dirs: test
main-is: Spec.hs
build-depends: base
, WordNumber
, hspec
ghc-options: -threaded -rtsopts -with-rtsopts=-N
default-language: Haskell2010
Run Code Online (Sandbox Code Playgroud)
更新:其实我觉得自己找不到答案有点蠢.它要么stack test或者stack build --test,也记录在案.
然而,对于遵循HaskellBook的人来说,它可能并不那么明显.出于某种原因,测试章节中的所有测试都以繁琐的方式执行,并且stack test从未提及过运行测试.
Zpa*_*ree 10
stack test运行位于.cabal文件中的测试.它会在stack build需要时运行,因此您无需在测试之前手动构建.
进一步了解:https://docs.haskellstack.org/en/stable/GUIDE/#stack-test