0

我的.cabal文件包含以下 hspec 配置:

-- The name of the package.
name:                MyModule

version:             0.1.0.0

cabal-version:       >=1.10
...
test-suite my-tests
  ghc-options:         -Wall -Werror
  cpp-options:         -DTEST
  default-extensions:  OverloadedStrings
  type:                exitcode-stdio-1.0
  main-is:             HSpecTests.hs
  hs-source-dirs:      tests
  build-depends:       MyModule, base >= 4.8 && < 4.9, containers >= 0.5 && <0.6, split >= 0.2 && < 0.3, hspec
  default-language:    Haskell2010

我的目录结构如下:

MyProject
     | - src
          | - Main.hs
          | - Other.hs
          | - tests
             | -HSpecTests.hs
     | - dist
     | - MyProj.cabal

当我运行时cabal build,我的源代码成功构建为可执行文件./dist/build/myproj/myproj

cabal build然后失败:

cabal: can't find source for HSpecTests in
dist/build/my-tests/my-tests-tmp, tests

检查build目录显示my-tests目录丢失。

改变hs-source-dirstosrc/tests 产生:

cabal: can't find source for HSpecTests in 
dist/build/my-tests/my-tests-tmp, src/tests

将所有测试移动到根/测试下的顶层,并将.cabal文件更改为hs-source-dirs: tests生成:

<command line>: cannot satisfy -package-id MyModule-0.1.0.0-inplace
    (use -v for more information)

我怎么配置错了?

4

2 回答 2

2

hs-source-dirs错了:

 hs-source-dirs:      tests

鉴于它HSpecTests的路径是src/tests/HSpecTests.hs,它应该是

 hs-source-dirs:      src/tests

但是,请记住,tests它们通常位于顶级文件夹中:

MyProject
     | - src
          | - Main.hs
          | - Other.hs
     | - tests
          | -HSpecTests.hs
     | - dist
     | - MyProj.cabal
于 2016-01-16T09:35:50.303 回答
0

有两件事不对:

1)(感谢@Zeta让我的文件结构走上正轨),测试需要在根级别的测试目录中

2)如此处所述:创建测试套件时出错:“无法满足-package-id”我的测试不能依赖于可执行文件并且需要创建库

于 2016-01-16T10:16:22.660 回答