确定是否在使用Perl的测试中调用函数

Mar*_*ark 1 testing perl function

我用 Test::More

我想知道我的一个函数是否被调用.我有两种情况:一种不会调用我的函数,另一种情况不会.这个功能没有被嘲笑,我只是想知道它是否被调用.

yst*_*sth 6

就像是:

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');
Run Code Online (Sandbox Code Playgroud)