I'm struggling to figure out how to inject colored output while running tests with prove:

use Test::Utils::Dump; use Test::Dirs; # sets up temporary scratch directories use Test; use_ok('File'); my $f = File->new(); $f->path($Test::Dirs::scratch . 'test.txt'); d $f; # d sub is in Test::Utils::Dump
My Dump utility module looks like this:
package Test::Utils::Dump; use Term::ANSIColor qw(colored); use strict; use warnings; use Data::Dumper qw(Dumper); # export the dump function use Exporter qw(import); our @EXPORT_OK = qw(d); # dump the data passed in sub d { my $data = shift; print colored ['green'], "\nDumping data...\n"; # print the data and the caller my $caller_line = "Dump from: " . (caller(0))[1] . ' line: ' . (caller(0))[2] . "\n"; print colored(['green'], "\n" . $caller_line); print Dumper($data); print $caller_line; }

When I run the test with prove, however, the output from the debug code is still in black and white. Prove is outputting some color so I know that's working. For example, "All tests successful" shows up in green. Addendum: Also, I can inject color directly into the output if I do print colored right into the test file itself. But this confuses prove unless I print to STDERR.

$PM = "Perl Monk's";
$MC = "Most Clueless Friar Abbot Bishop Pontiff Deacon Curate Priest Vicar Parson";
$nysus = $PM . ' ' . $MC;
Click here if you love Perl Monks


In reply to How can I inject colored output to prove command output? by nysus

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.