1

我是菜鸟。

我试图将一个更大的项目中的单个 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找不到自己?

4

1 回答 1

4

对该模块名称进行Hoogle 搜索表明它在 hspec 中,而不是 hspec-discover。请尝试添加对 hspec 的测试套件依赖项。

于 2019-07-05T02:51:36.197 回答