Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

Test::More Too Verbose

by bichonfrise74 (Vicar)
on Mar 25, 2010 at 23:18 UTC ( #830995=perlquestion: print w/replies, xml ) Need Help??

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


When I run this test which will intentionally fail,
#!/usr/bin/perl use warnings; use strict; use Test::More tests => 1; my $test_ls = `lxs`; like( $test_ls, qr/incorrect/, 'lxs command is missing.' );
It gives me this output.
1..1 Can't exec "lxs": No such file or directory at ./1.t line 7. Use of uninitialized value in pattern match (m//) at ./1.t line 9. not ok 1 - lxs command is missing. # Failed test 'lxs command is missing.' # at ./1.t line 9. # undef # doesn't match '(?-xism:incorrect)' # Looks like you failed 1 test of 1.
Is there a way to make it less verbose? I wanted something like 'Failed test 'lxs command is missing.'.

And is there a way to remove this 'Use of uninitialized value in pattern match'?

Replies are listed 'Best First'.
Re: Test::More Too Verbose
by toolic (Bishop) on Mar 25, 2010 at 23:43 UTC
    By default, backticks only capture STDOUT, not STDERR. The 'uninitialized' message appears on STDERR. To capture both STDOUT and STDERR, use:
    my $test_ls = `lxs 2>&1`;
    That will remove the warning message.

    I was browsing around CPAN, and I stumbled uopn Test::Cmd. I have never tried it, but it does seem relevant.

Re: Test::More Too Verbose
by educated_foo (Vicar) on Mar 25, 2010 at 23:37 UTC
    This is a self-inflicted wound caused by use warnings and use Test::More. These two modules are supposed to create verbosity, so if you don't want it, don't use warnings, and use e.g. Test::Simple instead of Test::More.
Re: Test::More Too Verbose
by ikegami (Patriarch) on Mar 26, 2010 at 01:42 UTC

    hum, it shouldn't give that uninitialized warning. I'd call that a bug. But you asked for the rest.

    I wanted something like 'Failed test 'lxs command is missing.'.

    That's not valid TAP, which is what Test::More and similar output. TAP is basically

    1..5 ... ok 3 ...
    1..5 ... not ok 3 ...

    Most of the rest is optional, but it does allow to determine what the problem is, since you, the maintainer, is typically not the one that's going to be running the tests.

    By the way, if you execute your test as follows, it'll hide pretty much all of the non-errors:

    perl -MTest::Harness -e'runtests @ARGV' test.t
Re: Test::More Too Verbose
by jethro (Monsignor) on Mar 25, 2010 at 23:37 UTC
    Executing a command to test if it exists is a bit overkill. `which lxs` will tell you whether lxs exists without executing it and without printing something unwanted on STDERR.

      Sometimes you have to execute a binary to see if it exists. eg, if you're checking to see if you have GNU cp, you can't just see if there's a file called cp, you need to examine the binary. The easiest way of examining the binary is to execute it.

      See, eg, App::Rsnapshot::CheckGNUcp

      (please don't use App::Rsnapshot, it's an experimental and as-yet-incomplete rewrite of rsnapshot)

        maybe safer to try binary --help
Re: Test::More Too Verbose
by Your Mother (Archbishop) on Mar 25, 2010 at 23:47 UTC

    A snippet for testing perl scripts which may or may not be on point-

    use Test::More; use FindBin qw( $RealBin ); my $out = qx{ /bin/env perl -cw $RealBin/../bin/ }; like( $out, qr{ syntax OK}, "Syntax OK" );

    Compiling it, even without "execution," can have side-effects because of BEGIN but it's safer than straight execution.

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://830995]
Approved by toolic
Front-paged by toolic
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (4)
As of 2022-10-07 06:40 GMT
Find Nodes?
    Voting Booth?
    My preferred way to holiday/vacation is:

    Results (29 votes). Check out past polls.