cabal 测试配置错误
cabal misconfiguration for tests
我的 .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)
我怎么配置错误了?
你的hs-source-dirs
是错误的:
hs-source-dirs: tests
鉴于HSpecTests
的路径是src/tests/HSpecTests.hs
,应该是
hs-source-dirs: src/tests
但是,请记住 tests
通常位于 top-level 文件夹中:
MyProject
| - src
| - Main.hs
| - Other.hs
| - tests
| -HSpecTests.hs
| - dist
| - MyProj.cabal
有两处错误:
1)(感谢@Zeta 让我的文件结构步入正轨),测试需要在根级别的测试目录中
2) 如此处所述:Error while creating test suites: "cannot satisfy -package-id" 我的测试不能依赖可执行文件,需要创建一个库
我的 .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)
我怎么配置错误了?
你的hs-source-dirs
是错误的:
hs-source-dirs: tests
鉴于HSpecTests
的路径是src/tests/HSpecTests.hs
,应该是
hs-source-dirs: src/tests
但是,请记住 tests
通常位于 top-level 文件夹中:
MyProject
| - src
| - Main.hs
| - Other.hs
| - tests
| -HSpecTests.hs
| - dist
| - MyProj.cabal
有两处错误:
1)(感谢@Zeta 让我的文件结构步入正轨),测试需要在根级别的测试目录中
2) 如此处所述:Error while creating test suites: "cannot satisfy -package-id" 我的测试不能依赖可执行文件,需要创建一个库