Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Give information on how to re-run specific spec items on test failure #205

Closed
sol opened this issue Nov 2, 2014 · 9 comments
Closed

Give information on how to re-run specific spec items on test failure #205

sol opened this issue Nov 2, 2014 · 9 comments

Comments

@sol
Copy link
Member

sol commented Nov 2, 2014

Print information on how to rerun with -m and --rerun. This should be aware of runhaskell and GHCi, e.g. in ghci it should say :main ....

Possibly, we want to introduce some "novice"-mode and make it less verbose if it is off.

@prikhi
Copy link

prikhi commented Nov 9, 2014

I still don't know how this is done... Could you explain it so I don't have to wait for the patch :P

I'm running with cabal test. Does -m use file names? or the text in describe? or the text in it? Or the test function names? I have no idea...

@sol
Copy link
Member Author

sol commented Nov 10, 2014

@prikhi It use a combination of the arguments of describe and it. You can either match on the pretty-printed description or on all components joined by /, or any substring of any of the two.

Let's walk through an example:

-- Spec.hs
import           Test.Hspec

main :: IO ()
main = hspec $ do
  describe "Prelude" $ do
    describe "reverse" $ do
      it "reverses a list" False
    describe "show" $ do
      it "shows its argument" True
$ runhaskell Spec.hs 

Prelude
  reverse
    reverses a list FAILED [1]
  show
    shows its argument

1) Prelude.reverse reverses a list

Randomized with seed 48919573

Finished in 0.0008 seconds
2 examples, 1 failure

You now can rerun the failing spec by matching on the pretty-printed description Prelude.reverse reverses a list of the error message:

$ runhaskell Spec.hs -m "Prelude.reverse reverses a list"

Or you can join all the components with / and match on Prelude/reverse/reverses a list:

$ runhaskell Spec.hs -m "Prelude/reverse/reverses a list"

Or any substring of one of the above, e.g.:

$ runhaskell Spec.hs -m reverse

@sol
Copy link
Member Author

sol commented Nov 10, 2014

If you use ghci you can use --rerun to rerun failing specs:

$ ghci Spec.hs                          
*Main> :main
...
*Main> :main --rerun
...

@sol
Copy link
Member Author

sol commented Nov 10, 2014

If you are inclined to use cabal, try:

$ cabal configure --enable-tests --disable-optimization
$ cabal build && ./dist/build/spec/spec -m reverse

@sol
Copy link
Member Author

sol commented Nov 10, 2014

Also note that both ghci and runhaskell can be used with cabal sandboxes, but you may need to pass additional arguments. Here are examples for the common src//test/ layout:

$ cabal exec -- runhaskell -isrc -itest test/Spec.hs
$ cabal exec -- ghci -isrc -itest test/Spec.hs

@sol
Copy link
Member Author

sol commented Nov 10, 2014

Also have a look at https://github.com/sol/hspec-example#running-tests

@prikhi
Copy link

prikhi commented Nov 10, 2014

Beautiful thank you :D

Unfortunately my current use case is integration tests using hspec-webdriver and that seems to not play too nice with either the -m or --rerun flags(it only works if I target the base Spec, otherwise I get BlockedIndefinitelyOnMVar).

Ah well, good to know for the future, thanks!

@sol
Copy link
Member Author

sol commented Nov 10, 2014

That sounds scary, probably a bug in hspec-webdriver.

@sol
Copy link
Member Author

sol commented Mar 14, 2018

I added this to the docs https://hspec.github.io/match.html

@sol sol added this to the _|_ milestone Mar 14, 2018
@sol sol closed this as completed in 83dd0b6 Jul 2, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants