Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Redirecting the output of Test::More

by thor (Priest)
on Feb 18, 2005 at 12:54 UTC ( #432307=perlquestion: print w/ replies, xml ) Need Help??
thor has asked for the wisdom of the Perl Monks concerning the following question:

Greetings fellow monks,

Perhaps I'm missing something, but for some reason, I can't seem to figure out how to have Test::More output its test results to anywhere but STDERR. In Test::Builder, I see an output method that seems to do what I want, but I can't seem to access Test::More's Test::Builder object. Does anyone have any ideas?

thor

Feel the white light, the light within
Be your own disciple, fan the sparks of will
For all of us waiting, your kingdom will come

Comment on Redirecting the output of Test::More
Re: Redirecting the output of Test::More
by mlh2003 (Scribe) on Feb 18, 2005 at 13:19 UTC
    Could you use the return codes (true or false) of the Test::More methods to generate your own message for each test? I know that it is more cumbersome, but if there are no other alternatives...

    For example:

    ok($this eq $that, $test_name) || print "$this does not equal $that in + test: $test_name\n";

      Test::Harness will try to interpret anything printed to STDOUT. diag() works better. (However, in this case, is() is the best option of all.)

Re: Redirecting the output of Test::More
by fglock (Vicar) on Feb 18, 2005 at 13:24 UTC
Re: Redirecting the output of Test::More
by dragonchild (Archbishop) on Feb 18, 2005 at 13:30 UTC
    Look at prove, which comes with Test::More. That should give you an idea of how to do what you want.

    Being right, does not endow the right to be rude; politeness costs nothing.
    Being unknowing, is not the same as being stupid.
    Expressing a contrary opinion, whether to the individual or the group, is more often a sign of deeper thought than of cantankerous belligerence.
    Do not mistake your goals as the only goals; your opinion as the only opinion; your confidence as correctness. Saying you know better is not the same as explaining you know better.

Re: Redirecting the output of Test::More
by thedoe (Monk) on Feb 18, 2005 at 13:38 UTC

    You could try redirecting the STDERR output by reassigning it using open.

    For example, the following code will redirect STDERR to STDOUT:

    open (STDERR, ">&STDOUT") or die 'Can not redirect STDERR';

    For more information, try consulting the documentation in

    perldoc -f open
Re: Redirecting the output of Test::More
by Tanktalus (Canon) on Feb 18, 2005 at 15:10 UTC

    Maybe I'm missing something here ... but why would you want to redirect the test output anywhere? If you're running your test under "make test" (or "Build test"), then it's all going exactly where you want. Are you trying to run the test standalone without the MakeMaker/Build framework? Where do you want to send the results? To a file, or to the screen? In the latter case, I'm not sure why STDERR is not sufficient. In the former case, I would recommend using your shell to do this - so that when you later run your tests under the standard frameworks, it will just work (because they will redirect to themselves).

    Just my thoughts...

      There are other uses for the Test::* modules than just build tests for modules. I am using this for testing a large system and want the results to go to a file. Redirecting STDERR is somewhat of a chore as I'm on a windows box (perhaps this is the opportunity that I need to learn how to do that on windows). It just would've been nice to be able to do this in some simple way...seems that there will have to be some hackery involved. *sigh*...why can't easy things be easy? ;)

      thor

      Feel the white light, the light within
      Be your own disciple, fan the sparks of will
      For all of us waiting, your kingdom will come

        I've been thinking about doing the same thing at work ... however, I was thinking of doing it still under the Module::Build framework so I could just Build test. And then I could "Build test > logfile.out 2>&1" to get the full output (assuming I was on unix - I can't recall how to redirect stderr and stdout to the same place on DOS/OS2/Windows).

Re: Redirecting the output of Test::More
by mpeters (Chaplain) on Feb 18, 2005 at 15:56 UTC
    I've tried to do this before as well (trying to email test results to developers) but there are greater problems than just redirecting STDERR. Test::Harness uses formats for displaying the results, and there is no way to completely redirect the output of a format. See redirecting output from a format.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://432307]
Approved by davis
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (4)
As of 2014-08-23 21:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (178 votes), past polls