测试的错误配置

时间:2016-01-16 09:30:24

标签: haskell cabal hspec

我的.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-dirs更改为src/tests 生产:

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

将所有测试移至root / tests下的顶级,并将.cabal文件更改为hs-source-dirs: tests会产生:

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

我如何错误配置?

2 个答案:

答案 0 :(得分: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

答案 1 :(得分:0)

有两件事是错的:

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

2)如此处所述:Error while creating test suites: "cannot satisfy -package-id"我的测试不依赖于可执行文件并且需要创建库