我有一个阴谋集团项目。它有库和测试目标。
测试目标依赖于库,因为它测试库的功能。
问题是,每当我向库添加包依赖项时(比如,cryptohash-sha1(
library Lib
exposed-modules: Lib
other-extensions: DeriveGeneric
build-depends: base >=4.13 && <4.14,
cryptohash-sha1,
并运行测试,我得到错误
无法加载模块的Crypto。搞砸SHA1'
它是隐藏包"cryptohash-sha1-0.11.100.1"的成员。
也许您需要将"cryptochash-sha1"添加到构建中,这取决于您的.cab文件
在这种情况下,我所做的是将相同的包添加到测试目标
test-suite json-generator-test
hs-source-dirs: test, src
main-is: Test.hs
other-modules: Lib
build-depends: base >=4.13 && <4.14
cryptohash-sha1,
只有到那时,测试才会运行。
我希望测试目标自动依赖于库目标中的所有包。我该怎么做?
您可以使用名为公共节的cabal功能。你可以在下面的博客文章中阅读更多关于它的信息:
- https://vrom911.github.io/blog/common-stanzas
使用这种方法,您可以将所有常见的依赖项放在一个单独的节中,并将其导入库和测试套件中:
common common-dependencies
build-depends: base >=4.13 && <4.14
, cryptohash-sha1
library Lib
import: common-dependencies
exposed-modules: Lib
other-extensions: DeriveGeneric
test-suite json-generator-test
import: common-dependencies
hs-source-dirs: test, src
main-is: Test.hs
other-modules: Lib