我是菜鸟。
我试图从一个更大的项目中复制并粘贴单个Hspec/QuickCheck测试,以便我可以对其进行调整,看看它的行为。
我有一个类似:
的结构myproject/test/Spec.hs
myproject/test/mytest.hs
从另一个项目中复制我的Spec.hs
只有:
{-# OPTIONS_GHC -F -pgmF hspec-discover #-}
这与文档中显示的示例完全相同:http://hspec.github.io/hspec-discover.html
我的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
运行stack test
时,我会收到以下错误:
$ 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
我不明白很多。但是这里的主要难题是输出似乎表明hspec-discover-2.6.1
已成功安装。
我尚未在我的代码位中的任何地方写Test.Hspec.Discover
,因此我必须假设错误来自{-# OPTIONS_GHC -F -pgmF hspec-discover #-}
(错误消息也指向Spec.hs
作为源(。
嗯,我在做什么错?hspec-discover
找不到自己?
进行hoogle搜索该模块名称表明它在HSPEC中,而不是HSPEC中。请尝试在HSPEC上添加测试套件的依赖。