On 27 Feb 2008, at 13:47, Andy Armstrong wrote:
use Test::More tests => 1293
use Test::BreakAt tests => [853, 927..930];

That was a bad interface anyway...

After a bit of fiddling I now have this in my ~/.perldb:

    @DB::testbreak = ();

    # Monkeypatch cmd_b (set breakpoint)
    my $cmd_b = \&DB::cmd_b;
    *DB::cmd_b = sub {
        my ( $cmd, $line, $dbline ) = @_;
        if ( $line =~ /\s*#\s*(\d+(?:\s*,\s*\d+)*)$/ ) {
            my %seen;
            @DB::testbreak = grep { !$seen{$_}++ }
sort { $a <=> $b } ( split( /\s*,\s*/, $1 ), @DB::testbreak );
        }
        else {
            $cmd_b->( @_ );
        }
    };

    sub afterinit {
        $trace |= 4;    # Enable watchfunction
    }

    sub watchfunction {
        if ( @DB::testbreak ) {
            require Test::Builder;
            my $current = Test::Builder->new->current_test;
            if ( $current + 1 >= $DB::testbreak[0] ) {
                shift @DB::testbreak
while @DB::testbreak && $current + 1 >= $DB::testbreak[0];

                my $depth = 1;
                while ( 1 ) {
                    my ( $package, $file, $line ) = caller $depth;
                    last unless defined $package;
                    last unless $package =~ /^Test::/;
                    $depth++;
                }
                $DB::stack[ -$depth ] = 1;
            }
        }
        return 1;
    }

That extends the b (break) command so that you can do

DB<1> b #5

to set a breakpoint at the exit of test 4. You can specify multiple
tests like this:

DB<2> b #5,7,11

It manipulates the stack the debugger uses to store saved $single values
so that the debugger will stop in the first package above the current
package whose name does not begin with 'Test::'.

It's pretty crude and can almost certainly be improved upon but even in
its current form it's useful.

--
Andy Armstrong, Hexten

Reply via email to