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

Hi

I want to use Test::More's is_deeply() and probably other tests inside a web application, and am concerned about output and other side effects of the testing framework.

Is it possible to control the testing framework without destabilizing the app?

I'm aware about Data::Compare and Test::Deep::NoTest but would rather prefer not adding more dependencies.

TIA! :)

Cheers Rolf
(addicted to the 𐍀𐌴𐍂𐌻 Programming Language :)
Wikisyntax for the Monastery

  • Comment on Controlling output and side effects from Test::More

Replies are listed 'Best First'.
Re: Controlling output and side effects from Test::More
by tobyink (Canon) on Jul 19, 2023 at 09:49 UTC

    In theory you could write a TAP::Formatter::Base subclass, but it seems easier to copy and paste the code from Test::More::_deep_check() and modify it to suit your needs — changing how differences are reported.

Re: Controlling output and side effects from Test::More (solved)
by LanX (Saint) on Jul 19, 2023 at 15:10 UTC
    This seems to do the trick :)
    use v5.12.0; use warnings; use Data::Dump qw/pp dd/; use Test::More import => ['is_deeply', 'done_testing']; my $test_builder = Test::More->builder; my %out; $test_builder->output(\ $out{std}); $test_builder->failure_output(\ $out{failure}); $test_builder->todo_output(\ $out{todo}); warn "Test pass: " . is_deeply( {a=>1}, {a=>1},"pass?"); warn "Test fail: " . is_deeply( {a=>1}, {b=>1},"fail?"); done_testing; my $div = "-"x10; for my $type (qw/std failure todo/){ my $out = $out{$type} // ""; say <<"__OUT__"; $div $type $div $out $div __OUT__ } pp \%out;

    Test pass: 1 at d:/temp/redirect_test_more.pl line 16. Test fail: 0 at d:/temp/redirect_test_more.pl line 17. ---------- std ---------- ok 1 - pass? not ok 2 - fail? 1..2 ---------- ---------- failure ---------- # Failed test 'fail?' # at d:/temp/redirect_test_more.pl line 17. # Structures begin differing at: # $got->{b} = Does not exist # $expected->{b} = '1' ---------- ---------- todo ---------- ---------- { failure => "# Failed test 'fail?'\n# at d:/temp/redirect_test_mo +re.pl line 17.\n# Structures begin differing at:\n# \$go +t->{b} = Does not exist\n# \$expected->{b} = '1'\n", std => "ok 1 - pass?\nnot ok 2 - fail?\n1..2\n", todo => undef, }

    Cheers Rolf
    (addicted to the 𐍀𐌴𐍂𐌻 Programming Language :)
    Wikisyntax for the Monastery