haskell - Hspec: discovery, custom main, and passing argument to spec -


i trying use hspec-discover along custom main. custom main bracket creates file descriptor used spec's.

this spec.hs:

{-# options_ghc -f -pgmf hspec-discover -optf --module-name=spec #-} 

this main.hs:

module main (main)  import control.exception import system.posix.io import system.posix.files import test.hspec import spec (spec)  main :: io () main = bracket   (openfd verybigfile readwrite (just 384) defaultfileflags)   (\fd -> closefd fd >> removelink verybigfile)   (\fd -> hspec (spec fd))           verybigfile = "test/verybigfile" 

for spec in individual autodiscovered module accept file descriptor argument, need declare as

spec :: fd -> spec 

but hspec-discover demands spec declared as

spec :: spec 

otherwise autogenerated module not compile:

test/spec.hs:8:68:     couldn't match type `system.posix.types.fd -> spec'                   `hspec-core-2.1.7:test.hspec.core.spec.monad.specm () ()'     expected type: hspec-core-2.1.7:test.hspec.core.spec.monad.specwith                      ()       actual type: system.posix.types.fd -> spec     in second argument of `describe', namely `sendfilespec.spec'     in second argument of `postprocessspec', namely       `(describe "sendfile" sendfilespec.spec)'     in expression:       postprocessspec         "test/sendfilespec.hs" (describe "sendfile" sendfilespec.spec) 

so, how pass argument spec without disturbing autodiscovery? imagination drifts towards ioref's idea makes me shudder. right way it?

sharing values across spec files not support hspec-discover. can still share values within same spec file. following works:

foospec.hs:

module foospec (spec)  import           test.hspec import           system.io  spec :: spec spec = beforeall (openfile "foo.txt" readmode) $ afterall hclose $   describe "hgetline" $     "reads line" $ \h ->       hgetline h `shouldreturn` "foo"      "reads other line" $ \h ->       hgetline h `shouldreturn` "bar" 

spec.hs:

{-# options_ghc -f -pgmf hspec-discover #-} 

but note beforeall considered code smell. it's practice use before instead if possible.


Comments

Popular posts from this blog

javascript - Bootstrap Popover: iOS Safari strange behaviour -

Magento/PHP - Get phones on all members in a customer group -

session - Logging Out Using PHP -