如何调试单个 Perl 单元测试子程序?

How can I debug a single Perl unit test sub?

我有一个带有 t/ 测试目录的常用 MakeMaker 模块,我可以 运行 单个测试文件,例如 prove -I lib t/my-test.t.

我的测试使用 Test::ClassTest::More 和 subs(使用 Effective Perl 的模数技术),像这样:

use strict;
use warnings;
use base 'Test::Class';  
use Test::More;

__PACKAGE__->runtests() unless caller;

sub set_up : Test(setup) {
    # ...
} 

sub test_something : Test {
    is(MyModule::some_sub(1), 1);
}

# ...more test subs...

现在我想使用 Perl 调试器来调查显示我的模块中存在问题的测试子。我只想在调试器中使用 运行 test_something,而不 运行 宁 .t 文件中的所有其他测试子。

prove好像没有这个选项

perl -d -I lib t/my-test.t 运行s 所有测试,除非我更改我的模数以调用设置方法然后调用实际测试方法而不是 __PACKAGE__->runtests():

unless (caller) { 
    set_up(); 
    test_something();  
    done_testing();  
}

如何在不修改代码的情况下运行只测试一个子?

为避免 运行 所有测试,必须在加载测试脚本时定义 caller。尝试这样的事情:

$ perl -Ilib -de 1
DB<1>   do 't/my-test.t'
DB<2>   set_up()
DB<3>   b test_something_else
DB<4>   test_something_else()
    ... step through test_something_else() function ...
DB<16>   done_testing()