in reply to Get the number of the current test when debugging a test script

Can you somehow get to the underlying Test::Builder object? Its Curr_Test contains the current test number:
#!/usr/bin/perl use warnings; use strict; use Test::Builder; my $o = 'Test::Builder'->new; for (1 .. 3) { $o->ok(1); $o->note($o->{Curr_Test}); } $o->done_testing();
لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

Replies are listed 'Best First'.
Re^2: Get the number of the current test when debugging a test script
by Dumu (Monk) on Jul 01, 2015 at 12:42 UTC

    So the answer seems to be that you can just create a reference to the $builder object at any time, either in your test script:

    my $builder = Test::Most->builder;

    or in the debugger ('my' doesn't seem to play well on the debugger command line):

    NB for newbies: the DB<x> bit is the debugger prompt, not part of the code.
    DB<x> $builder = Test::Most->builder;

    If you do either of the above, you should find you can subsequently do either of the following in the debugger to print out the current (actually, the latest) test number:

    DB<x> x $builder->{Curr_Test} DB<x> p $builder->{Curr_Test}

    - or, as I originally sought to do, run the debugger and break after a particular test, e.g. test #20:

    DB<x> w $builder->{Curr_Test} == 20 DB<x> c

    Some Monks seem uncomfortable with the idea of running a test script through a debugger. I can sort of understand what you're saying, folks: a test script is effectively a static debugging service, so why run it through the debugger as well? I have a few answers to this but the simplest are:

    "... Perl tests are just Perl code." -- chromatic, in Organizing Perl Test Files
    "TIMTOWTDI!" -- TimToady

    Feel free to get in touch if you would like a couple more.

Re^2: Get the number of the current test when debugging a test script
by Dumu (Monk) on Jun 30, 2015 at 17:23 UTC
    Thanks choroba, this is pretty much exactly what I am trying to do.