Using Hspec's very handy --rerun functionality doesn't work with --file-watch, I get this after a failed test and a file save:
Progress: 1/2WARNING: Could not read environment variable HSPEC_FAILURES; `--rerun' is ignored!
The command I'm using is:
STACK_YAML="../stack.yaml" stack build --test --test-arguments '--rerun' --file-watch --fast $(PROJECT) 2>&1
Did I get something wrong?
It seems like hspec is expecting environment variables to be preserved between invocations?
It uses setEnv here, but it seems to me like that would only work if you ran hspec in ghci and didn't reload. In other words, setEnv only affects the current process, not the parent process.
Prelude System.Posix.Env> setEnv "TEST" "hullo" True
Prelude System.Posix.Env> :q
Leaving GHCi.
mgsloan@computer:~$ echo $TEST
mgsloan@computer:~$
So, seems like this is an issue with hspec's implementation of --rerun, but perhaps I misunderstand its usage, I haven't used --rerun before.
Unless the help output is outdated, it looks like that is the expected behavior outside of ghci
$ spec --help
...
-r --rerun rerun all examples that failed in the
previously test run (only works in GHCi)
...
I'm gonna plug ghcid once more because it is so awesome :stuck_out_tongue:
here is a clip of it in action for the interaction in this issue
for ease of copypasta:
ghcid --command='stack exec ghci --test -- -isrc -itest test/Spec.hs' --test $':main --rerun --color'
so, i ended up writing this little thing, if anyone's interested.
https://github.com/mwotton/hspec-stack-rerun
I can confirm that the --rerun feature is only meant to work in ghci.
@bitemyapp: Can this be closed then?
Yes, this is only meant to work in ghci.
Running tests outside of ghci is slow. If you care about productivity, then you really want to fix that first (either use :reload/:main directly in ghci or even better use something like hspec/sensei)!
@mgsloan it works in ghci, even if you use :reload.
Most helpful comment
for ease of copypasta: