我有一个阴谋计划。它具有库和测试目标。
测试目标取决于库,因为它测试库的功能。
问题是,每当我向库中添加程序包依赖项(例如 cryptohash-sha1 )
library Lib
exposed-modules: Lib
other-extensions: DeriveGeneric
build-depends: base >=4.13 && <4.14,
cryptohash-sha1,
运行测试,我得到了错误
无法加载模块“ Crypto.Hash.SHA1”。
它是隐藏程序包“ cryptohash-sha1-0.11.100.1”的成员。
也许您需要在.cabal文件的构建依赖项中添加“ cryptohash-sha1”
在这种情况下,我要做的是将相同的程序包添加到测试目标中
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,
只有这样,测试才能运行。
我希望测试目标自动依赖库目标中的所有软件包。我该怎么办?
答案 0 :(得分:2)
您可以使用称为 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