Haskell 阴谋集团对测试的错误配置
我的Haskell 阴谋集团对测试的错误配置,haskell,cabal,hspec,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-extens
.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
当我运行cabalbuild
时,我的源代码构建成功地成为一个可执行文件/dist/build/myproj/myproj
阴谋集团构建
然后失败:
cabal: can't find source for HSpecTests in
dist/build/my-tests/my-tests-tmp, tests
检查build
目录显示mytests
目录缺失
将hs源代码更改为src/tests
产生:
cabal: can't find source for HSpecTests in
dist/build/my-tests/my-tests-tmp, src/tests
<command line>: cannot satisfy -package-id MyModule-0.1.0.0-inplace
(use -v for more information)
将所有测试移到root/tests下的顶层,并将.cabal
文件更改为hs source dirs:tests
时,会产生:
cabal: can't find source for HSpecTests in
dist/build/my-tests/my-tests-tmp, src/tests
<command line>: cannot satisfy -package-id MyModule-0.1.0.0-inplace
(use -v for more information)
:无法满足-package id MyModule-0.1.0.0-inplace
(有关详细信息,请使用-v)
我是如何配置错误的?您的hs源代码是错误的:
hs-source-dirs: tests
考虑到HSpecTests
的路径是src/tests/HSpecTests.hs
,它应该是
hs-source-dirs: src/tests
但是,请记住,测试通常位于顶级文件夹中:
MyProject
| - src
| - Main.hs
| - Other.hs
| - tests
| -HSpecTests.hs
| - dist
| - MyProj.cabal
您的hs源目录
错误:
hs-source-dirs: tests
考虑到HSpecTests
的路径是src/tests/HSpecTests.hs
,它应该是
hs-source-dirs: src/tests
但是,请记住,测试通常位于顶级文件夹中:
MyProject
| - src
| - Main.hs
| - Other.hs
| - tests
| -HSpecTests.hs
| - dist
| - MyProj.cabal
有两件事不对:
1) (感谢@Zeta让我的文件结构走上正轨),测试需要放在根级别的测试目录中
2) 如本文所述:我的测试不能依赖于可执行文件,需要创建库有两个错误:
1) (感谢@Zeta让我的文件结构走上正轨),测试需要放在根级别的测试目录中
2) 如本文所述:我的测试不能依赖于可执行文件,需要创建一个库将hs source dirs更改为src/tests会产生以下消息:cabal:在dist/build/my tests/my tests tmp中找不到hspects的源,src/testschanging hs source dirs to src/tests生成消息:cabal:在dist/build/my tests/my tests tmp、src/tests中找不到hspects的源