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

Fix --file-watch / hspec interaction #1928

Closed
bitemyapp opened this issue Mar 18, 2016 · 6 comments
Closed

Fix --file-watch / hspec interaction #1928

bitemyapp opened this issue Mar 18, 2016 · 6 comments

Comments

@bitemyapp
Copy link
Contributor

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?

@mgsloan
Copy link
Contributor

mgsloan commented Mar 18, 2016

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.

@mgsloan mgsloan added this to the Support milestone Mar 18, 2016
@luigy
Copy link
Contributor

luigy commented Mar 24, 2016

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 😛
here is a clip of it in action for the interaction in this issue

@mwotton
Copy link

mwotton commented May 17, 2016

for ease of copypasta:

ghcid --command='stack exec ghci --test -- -isrc -itest test/Spec.hs'  --test $':main --rerun --color'

@mwotton
Copy link

mwotton commented Jul 14, 2016

so, i ended up writing this little thing, if anyone's interested.
https://github.com/mwotton/hspec-stack-rerun

@soenkehahn
Copy link

I can confirm that the --rerun feature is only meant to work in ghci.

@bitemyapp: Can this be closed then?

@sol
Copy link
Contributor

sol commented Oct 12, 2016

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.

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

6 participants