确定是否在使用Perl的测试中调用函数
我用 我想看看我的函数是否被调用。我有两种情况:一种不会调用我的函数,另一种会。这个函数不是模拟出来的,我只是想看看它是否被调用 类似于:确定是否在使用Perl的测试中调用函数,perl,function,testing,Perl,Function,Testing,我用 我想看看我的函数是否被调用。我有两种情况:一种不会调用我的函数,另一种会。这个函数不是模拟出来的,我只是想看看它是否被调用 类似于: my $called; my $orig_function = \&YourPackage::YourFunction; { no warnings 'redefine'; *YourPackage::YourFunction = sub { ++$called; goto &$orig_function }; } # cod
my $called;
my $orig_function = \&YourPackage::YourFunction;
{
no warnings 'redefine';
*YourPackage::YourFunction = sub { ++$called; goto &$orig_function };
}
# code that may or may not call YourFunction here
ok($called, 'function called');
看起来您即将发明代码覆盖率报告。你看到了吗?这会让你的生活更轻松。我不知道还有其他人,但我想看看你调用的代码示例。你能描述一下这段代码的功能吗?我想我能理解,但我有点困惑,为什么要在
我的$orig\u函数之后使用作用域…
将关闭警告的代码量限制在一行