Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/perl/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
确定是否在使用Perl的测试中调用函数_Perl_Function_Testing - Fatal编程技术网

确定是否在使用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函数之后使用作用域…
将关闭警告的代码量限制在一行