取决于工作台测试
Depend on test from bench
我有一个测试项目
test-suite spec
...
benchmark bench
build-depends:
library-test-spec
...我如何依赖基准测试中的测试套件代码?以上不起作用,因为名称为 library-test-spec
的包不存在。
您不能依赖 test-suite
内部基准测试。此问题的一般解决方案是将要在 test-suite
和基准测试中使用的函数移动到 library
目标中。不幸的是,这意味着如果通用功能需要一些测试库,您的 library
目标将在依赖项中拥有这些测试框架。如果你不想要这样的行为,那么你可以将这些函数移动到单独的包中,并在你的测试和基准测试中依赖这个包。
或者只是将测试代码复制粘贴到基准测试。
从 Cabal 2.0 开始,您可以将通用代码放在命名的 "internal library" 中,测试套件和基准测试都可以依赖它。根据 documentation:
Cabal 2.0 and later support “internal libraries”, which are extra
named libraries (as opposed to the usual unnamed library section). For
example, suppose that your test suite needs access to some internal
modules in your library, which you do not otherwise want to export.
You could put these modules in an internal library, which the main
library and the test suite build-depends upon.
一个方便的内部库如下所示:
library foo-internal
exposed-modules: Foo.Internal
build-depends: base
当依赖它时,你不需要设置版本约束,因为相同的包依赖隐式引用相同的包实例。
使用内部库,您可以避免双重编译(如两次包含相同的源代码)和阻碍主库(如将公共代码放在那里)。
记得在您的 .cabal
文件中包含 cabal-version: >=2
。
我有一个测试项目
test-suite spec
...
benchmark bench
build-depends:
library-test-spec
...我如何依赖基准测试中的测试套件代码?以上不起作用,因为名称为 library-test-spec
的包不存在。
您不能依赖 test-suite
内部基准测试。此问题的一般解决方案是将要在 test-suite
和基准测试中使用的函数移动到 library
目标中。不幸的是,这意味着如果通用功能需要一些测试库,您的 library
目标将在依赖项中拥有这些测试框架。如果你不想要这样的行为,那么你可以将这些函数移动到单独的包中,并在你的测试和基准测试中依赖这个包。
或者只是将测试代码复制粘贴到基准测试。
从 Cabal 2.0 开始,您可以将通用代码放在命名的 "internal library" 中,测试套件和基准测试都可以依赖它。根据 documentation:
Cabal 2.0 and later support “internal libraries”, which are extra named libraries (as opposed to the usual unnamed library section). For example, suppose that your test suite needs access to some internal modules in your library, which you do not otherwise want to export. You could put these modules in an internal library, which the main library and the test suite build-depends upon.
一个方便的内部库如下所示:
library foo-internal
exposed-modules: Foo.Internal
build-depends: base
当依赖它时,你不需要设置版本约束,因为相同的包依赖隐式引用相同的包实例。
使用内部库,您可以避免双重编译(如两次包含相同的源代码)和阻碍主库(如将公共代码放在那里)。
记得在您的 .cabal
文件中包含 cabal-version: >=2
。