Perl Test::更多和设置测试要求
对于Test::More
,我经常希望有一个模块可以运行测试并能够中止调用者test_plan
。我进行了一系列测试,为 Catalyst::Test
设置了插件列表。我不想进行测试来检查它们是否存在;相反,如果这些插件不存在,我希望我的脚本中止。
我试图找出 Catalyst 中的错误::Authentication::Store::DBI::ButMaintained
,我注意到这个错误也存在于 Catalyst::Authentication::Store::DBI
。如下:
eval {
require Catalyst::Model::DBI;
require Catalyst::Plugin::Session;
require Catalyst::Plugin::Session::State::Cookie;
require Catalyst::Plugin::Session::Store::File;
require DBD::SQLite;
require Test::WWW::Mechanize::Catalyst;
} or plan skip_all => $@;
...
$ENV{'TESTAPP_PLUGINS'} = [ qw(
Authentication
Session
Session::Store::File
Session::State::Cookie
Authorization::Roles
) ];
如您所见,eval/skip_all
不会检查 Authorization::Roles
包含,但测试依赖于它,因为它是一个插件。
不过,我还有另一个问题——是否有比这更优雅的方式来指定测试依赖项?请记住,我的目标与原作者相同。如果测试要求不存在,我只想跳过测试。理想情况下,在这种情况下,我想破解 Catalyst::Test
来包装 Catalyst::Plugin::*
内容的插件机制,然后找到更好的无需 eval/skip_all
即可完成其余操作的方法。
With Test::More
I often want to have a module that runs tests and has the ability to abort the callers test_plan
. I have a series of tests that set up a plugin list for Catalyst::Test
. I don't want to have to make my test check to see if they exist; instead, I want my script to abort if those plugins aren't present.
I was trying to track down a bug in my Catalyst::Authentication::Store::DBI::ButMaintained
, and I noticed this bug is also present in Catalyst::Authentication::Store::DBI
. Here it is:
eval {
require Catalyst::Model::DBI;
require Catalyst::Plugin::Session;
require Catalyst::Plugin::Session::State::Cookie;
require Catalyst::Plugin::Session::Store::File;
require DBD::SQLite;
require Test::WWW::Mechanize::Catalyst;
} or plan skip_all => $@;
...
$ENV{'TESTAPP_PLUGINS'} = [ qw(
Authentication
Session
Session::Store::File
Session::State::Cookie
Authorization::Roles
) ];
As you can see, the eval/skip_all
doesn't check Authorization::Roles
inclusion, but the test depends on it by virtue of it being a plugin.
I have another question though -- is there a more elegant way to specify Test-dependencies than this? Keep in mind my goal is the same as the original authors. I simply want to skip the test, if the test requirements don't exist. Ideally, in this case, I'd like to hack Catalyst::Test
to wrap the plugin mechanism for Catalyst::Plugin::*
stuff, and then find a better way to do the rest of this stuff without eval/skip_all
.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以通过调用动态影响计划中的测试数量:
您可以使用 do 根据需要有条件地计算测试数量。
You can dynamically affect the # of tests in the plan by calling:
You can use that do conditionally calculate the # of tests based on the needs.
根据需要更新您的插件列表:
如果您在单独的包中测试一堆要求,如果不满足依赖项,您可以简单地让该包返回 false(而不是传统的 true 值):
当我使用名为
Foo
的 dep 检查器,此操作失败并显示适当的输出:Update with your list of plugins as needed:
If you are testing a bunch of requirements in a separate package, you could simply have that package return false (rather than the traditional true value) if a dependency is not met:
When I run this using a dep checker called
Foo
, this fails with appropriate output: