在 HSpec 中设置测试套件

Setting up a test suite in HSpec

如何在 HSpec 中指定测试套件?我将为我的每个模块创建多个 *.hs 测试文件,我只想 运行 stack test,所有测试都为 运行。我该如何设置?

我试图在我的 cabal 文件中列出这样的测试模块,但它不起作用:

test-suite foo-test
  type:                exitcode-stdio-1.0
  hs-source-dirs:      test
  main-is:             Spec.hs
                     , Mod1Spec.hs
  build-depends:       base
                     , containers >= 0.5.6.2
                     , hqfl
                     , hspec >= 2.2.3
                     , hspec >= 2.2.3
                     , mtl >= 2.2.1
                     , pipes >= 4.1.8
                     , random >= 1.1
  ghc-options:         -threaded -rtsopts -with-rtsopts=-N
  default-language:    Haskell2010

这里有一些关于 hspec 测试的文档:

http://hspec.github.io/hspec-discover.html

如果您的主要规范模块仅包含以下行:

{-# OPTIONS_GHC -F -pgmF hspec-discover #-}

hspec-discover 将扫描目录树以进行规范测试。

此外 - 这是一个小的 hspec 示例:

https://github.com/hspec/hspec-example