Supplying options to HSpec from Cabal

347 views Asked by At

I'm trying to get started with hspec. I've got a working case working with QuickCheck, but I would just like some more detail when running cabal test. I found this article from hspec, giving instructions on supplying some more detailed control when running the executable. I'm currently using hi to initialize my haskell packages, so my cabal test suite looks like this:

Test-Suite spec
  Type:                 exitcode-stdio-1.0
  Default-Language:     Haskell2010
  Hs-Source-Dirs:       src
                      , test
  Ghc-Options:          -Wall
  Main-Is:              Spec.hs
  Build-Depends:        base
                      , hspec
                      , QuickCheck
                      , quickcheck-instances
                      , mtl
                      , text
                      , transformers

My guess is something like "default command line arguments", but that just doesn't feel right. How could I supply arguments to a hspec suite?

Also, this might be important. hi splits the test suite so that the only content in Spec.hs is:

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

but all tests and code reside in test/MainSpec.hs, which exports main and spec.

1

There are 1 answers

0
Rodrigo B. de Oliveira On

Check out the Using a custom main function section on http://hspec.github.io/hspec-discover.html

Relevant bits copied here for your convenience:

Here is an example that shows how this can be utilized to specify a different default formatter:

-- file test/Spec.hs
{-# OPTIONS_GHC -F -pgmF hspec-discover -optF --module-name=Spec #-}

-- file test/Main.hs
module Main where

import Test.Hspec.Runner
import Test.Hspec.Formatters
import qualified Spec

main :: IO ()
main = hspecWith defaultConfig {configFormatter = Just progress} Spec.spec