tj_thompson has asked for the wisdom of the Perl Monks concerning the following question:

Hello monks,

I have a module using Module::Build. There is one test file that is failing under 'Build test' but does not fail under 'perl -Mblib <test_file>'. My print debugging was showing identical things happening during test in both cases, so I decided to run under the debugger and have a look.

I found that while I could insert breakpoints when running via 'perl -d -Mblib <test_file>', the same breakpoints would not stop execution while running under 'perl -d Build test'.

Here's some simple code showing the issue I'm seeing:

#pm file package BPTest; use strict; use warnings; sub do_stuff { $DB::single = 1; my $x = 10; return $x; } 1; #test file use Test::More tests => 2; BEGIN { use_ok( 'BPTest' ); } is( BPTest->do_stuff, 10, 'do_stuff returns 10' )

Here is what happens under 'perl -Mblib <test_file>':

plxc16479> perl -d -Mblib t/001_load.t Loading DB routines from perl5db.pl version 1.33 Editor support available. Enter h or `h h' for help, or `man perldebug' for more help. 1..2 ok 1 - use BPTest; main::(t/001_load.t:9): is( main::(t/001_load.t:10): BPTest->do_stuff, main::(t/001_load.t:11): 10, main::(t/001_load.t:12): 'do_stuff returns 10' main::(t/001_load.t:13): ) DB<1> c + BPTest::do_stuff(/nfs/pdx/disks/nehalem.pde.077/tmp/BPTest/blib/lib/BP +Test.pm:7): 7: my $x = 10; DB<1>

I'm stopped at my breakpoint like I expect. Here's what happens under 'perl -d Build test':

plxc16479> perl -d Build test Loading DB routines from perl5db.pl version 1.33 Editor support available. Enter h or `h h' for help, or `man perldebug' for more help. main::(Build:17): my $progname; DB<1> c + t/001_load.t .. ok All tests successful. Files=1, Tests=2, 0 wallclock secs ( 0.03 usr 0.00 sys + 0.02 cusr + 0.00 csys = 0.05 CPU) Result: PASS Debugged program terminated. Use q to quit or R to restart, use o inhibit_exit to avoid stopping after program termination, h q, h R or h o to get additional info. DB<1>

Here I did not stop at the breakpoint. This is making debug difficult since the test failure only occurs under 'Build test'. I have tried to set the breakpoint from the debugger via 'b <sub_name>' and 'b <line>', but both are ignored the same as $DB::single.

So the questions: What is happening under 'Build test' that prevents breakpoints from being honored? At a higher level, what does 'Build test' do differently regarding test files as compared to 'perl -Mblib <file>'?

I appreciate the help and any time spent looking over my question :)

UPDATE: I have resolved the underlying problem causing the test failure. Turns out the @INC array was in a different order when executing 'Build test' vs 'perl -Mblib <test_file>' and was picking up a non test version of one of my modules. However, I'm still interested in why the breakpoints do not seem to work from Build test :)

Replies are listed 'Best First'.
Re: Module::Build's Build test does not stop at breakpoints (exec)
by tye (Sage) on Jan 28, 2014 at 01:58 UTC

    I would expect the Build command to run perl in a subprocess to run each test. So the Build process having the debugger active would have no bearing on whether or not the debugger was active in the other process.

    Either use the debugger to find the point in Build where it starts the other Perl and have that invocation add "-d" or, more simply, add "-d" to the "#!" line of your test script and just run Build normally.

    - tye        

Re: Module::Build's Build test does not stop at breakpoints
by LanX (Saint) on Jan 27, 2014 at 20:23 UTC
    tl;dr ...but...

    BEGIN blocks are executed at compile time, i.e. already done before you can set your breakpoint with b .

    AFAIR an explicit $DB::single=1 can help.

    Should have been mentioned in the docs, see perldebug and perldebtut

    edit

    yep, see Debugging Compile Time Statements

    HTH! =)

    Cheers Rolf

    ( addicted to the Perl Programming Language)

      This should not be compile time though, correct? The only BEGIN block is around the use_ok test for the package. The test I'm trying to debug here is the second test, which is not part of a BEGIN block. I already include an explicit $DB::single here also, which seems to have no impact.

        ok sorry forget what I said, no real idea what blib is good for, looks like dark magic.

        Cheers Rolf

        ( addicted to the Perl Programming Language)