I have a bunch of utility scripts I'd like to test in part by scraping their log output. The scripts use Log::Dispatch with the default screen output and a file output for logging. Presently, the tests use Test::Trap to check log output on STDOUT.

This approach works well when proving tests directly from the command line. However, we run automated tests nightly via cron and under these conditions either Dispatch::Log doesn't write log entries (likely because STDOUT goes nowhere) or Test::Trap doesn't get them. I see the same results when running the tests with nohup prove ... --html

I'd rather not completely change the test approach (to reading the file, for example, instead of using Test::Trap) just because the logging tests fail under cron. On the other hand, we rely on the nightly test output to alert us to trouble and don't want a bunch of "known" failing results.

Supposing I can detect when running under cron (probably with ENV injection in the cron script that launches the tests--I've found checking PS1 is not sufficient to know) is there some UNIX or Perl hack I can use to persuade Log::Dispatch to log such that Test::Trap gets the lines?


In reply to Test::Trap + Log::Dispatch under Cron by Solo

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.