Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/haskell/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/kotlin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Haskell 阴谋集团对测试的错误配置_Haskell_Cabal_Hspec - Fatal编程技术网

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的源