I am a noob.
I have tried to copy and paste a single Hspec/QuickCheck test out of a bigger project into my own so I can tweak it and see how it behaves.
I have a structure like:
myproject/test/Spec.hs
myproject/test/mytest.hs
Copying from the other project my Spec.hs
just has:
{-# OPTIONS_GHC -F -pgmF hspec-discover #-}
This is exactly the same as the example shown in the docs: http://hspec.github.io/hspec-discover.html
Additionally I have in my package.yml
:
tests:
myproject-test:
main: Spec.hs
source-dirs: test
ghc-options:
- -threaded
- -rtsopts
- -with-rtsopts=-N
dependencies:
- myproject
- QuickCheck
- hspec-megaparsec
- hspec-discover
When I run stack test
I get the following error:
$ stack test
hspec-discover > configure
hspec-discover > Configuring hspec-discover-2.6.1...
hspec-discover > build
hspec-discover > Preprocessing library for hspec-discover-2.6.1..
hspec-discover > Building library for hspec-discover-2.6.1..
hspec-discover > [1 of 4] Compiling Paths_hspec_discover
hspec-discover > [2 of 4] Compiling Test.Hspec.Discover.Config
hspec-discover > [3 of 4] Compiling Test.Hspec.Discover.Sort
hspec-discover > [4 of 4] Compiling Test.Hspec.Discover.Run
hspec-discover > Preprocessing executable 'hspec-discover' for hspec-discover-2.6.1..
hspec-discover > Building executable 'hspec-discover' for hspec-discover-2.6.1..
hspec-discover > [1 of 2] Compiling Main
hspec-discover > [2 of 2] Compiling Paths_hspec_discover
hspec-discover > Linking .stack-work/dist/x86_64-osx/Cabal-2.4.0.1/build/hspec-discover/hspec-discover ...
hspec-discover > copy/register
hspec-discover > Installing library in /Users/anentropic/.stack/snapshots/x86_64-osx/9ea21a5325b81a2dfa4286ce80451092e847f54dde50f04e1f7e952425f2d334/8.6.5/lib/x86_64-osx-ghc-8.6.5/hspec-discover-2.6.1-GcEMs7l4z3NWJQPD5eMXU
hspec-discover > Installing executable hspec-discover in /Users/anentropic/.stack/snapshots/x86_64-osx/9ea21a5325b81a2dfa4286ce80451092e847f54dde50f04e1f7e952425f2d334/8.6.5/bin
hspec-discover > Registering library for hspec-discover-2.6.1..
Building all executables for `myproject' once. After a successful build of all of them, only specified executables will be rebuilt.
myproject> configure (lib + exe + test)
Configuring myproject-0.1.0.0...
myproject> build (lib + exe + test)
Preprocessing library for myproject-0.1.0.0..
Building library for myproject-0.1.0.0..
[1 of 2] Compiling Lib
[2 of 2] Compiling Paths_waterloo_haskell
Preprocessing executable 'myproject-exe' for myproject-0.1.0.0..
Building executable 'myproject-exe' for myproject-0.1.0.0..
[1 of 2] Compiling Main
[2 of 2] Compiling Paths_waterloo_haskell
Linking .stack-work/dist/x86_64-osx/Cabal-2.4.0.1/build/myproject-exe/myproject-exe ...
Preprocessing test suite 'myproject-test' for myproject-0.1.0.0..
Building test suite 'myproject-test' for myproject-0.1.0.0..
[1 of 2] Compiling Main
/Users/anentropic/Documents/Dev/Personal/waterloo/myproject/test/Spec.hs:3:1: error:
Could not find module ‘Test.Hspec.Discover’
Perhaps you meant
Test.Hspec.Discover.Run (from hspec-discover-2.6.1)
Test.Hspec.Discover.Sort (from hspec-discover-2.6.1)
Use -v to see a list of the files searched for.
-- While building package myproject-0.1.0.0 using:
/Users/anentropic/.stack/setup-exe-cache/x86_64-osx/Cabal-simple_mPHDZzAJ_2.4.0.1_ghc-8.6.5 --builddir=.stack-work/dist/x86_64-osx/Cabal-2.4.0.1 build lib:myproject exe:myproject-exe test:myproject-test --ghc-options " -fdiagnostics-color=always"
Process exited with code: ExitFailure 1
Progress 2/3
There's a lot I don't understand. But the main puzzle here is the output appears to show that hspec-discover-2.6.1
was successfully installed.
I have not written Test.Hspec.Discover
anywhere in my bits of code so I have to assume the error comes from {-# OPTIONS_GHC -F -pgmF hspec-discover #-}
(also the error message points to Spec.hs
as the source).
Um, what am I doing wrong? hspec-discover
can't find itself?
Doing a Hoogle search for that module name shows that it is in hspec, not hspec-discover. Please try adding a test suite dependency on hspec.