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

I have a script which uses several input files, creates some temps and outputs others. It is tested via Test::Script and file content/creation is tracked via Test:Directory and Test::File.

After adding a new feature, making sure the unit tests are passing, the script tests are failing. I attempt to debug by running the test file as  perl -d:pdbtk t/path/to/test.t but cannot dive into the script itself.

It looks like the line executing the script from Tests::Script is the following:

(${$opt->{stdout}}, ${$opt->{stderr}}) = capture { system(@$cmd) };
but there is no way of 'stepping into' the execution.

I tried setting breakpoing inside the script, when entering the file, with  $DB::single = 1 but no success.

I tried adding debug flag to the  script_runs arguments, but it takes no effect.

edit: formatting

Replies are listed 'Best First'.
Re: Test::Script debug execution via scripts_run
by dpopchev (Novice) on Apr 22, 2021 at 04:51 UTC

    Thanks for the ideas!

    I slept on the problem and on second, closer look in the documentation https://metacpan.org/pod/Test::Script#script_runs

    interpreter_options -- Array reference of Perl options to be passed to + the interpreter. Things like -w or -x can be passed this way. This m +ay be either a single string or an array reference.
    So I just extended the script run line
    script_runs [ @{$scriptNargs} ], { exit => 0, interpreter_options +=> '-d' }, $test_run_name;
    tldr; Thanks for the ideas, fortunately the author already has covered this use case.

Re: Test::Script debug execution via scripts_run
by Perlbotics (Bishop) on Apr 21, 2021 at 17:55 UTC

    If @$cmd is causing the problem, you should identify what's going on (see below). You could then try to invoke the program with the given arguments to dive into the problem (hopefully %ENV was not modified and the files used still exist!).
    However, you could add

    • note "Now running '@$cmd'..."; and/or
    • ok(...) or diag "Getting from (@$cmd): stdout=... stderr=..."; (Diagnostics)
    to narrow down the problem. Use i.e. prove -v ... which shows all note(...)'s.
    You colud also add more logging to the modules/scripts under test (e.g Log::Log4perl).

Re: Test::Script debug execution via scripts_run
by Anonymous Monk on Apr 21, 2021 at 15:38 UTC

    You will not be able to step into a system() call, since it spawns a sub-process. What I would do in this case is figure out what command $cmd contains. If it is a perl command, you can run that under your debugger of choice. If it is not, you will have to do some more digging to figure out how Perl does get run.