This little failing test case illustrates my question:
# Test error checking for piped system calls
# We use 'boom', a non-existent command, for testing.
use Test::More qw/no_plan/;
use strict;
ok_system_call("true");
ok_system_call("true|true");
not_ok_system_call("boom");
not_ok_system_call("boom|boom");
not_ok_system_call("true|boom");
not_ok_system_call("boom|true");
#################################3
sub ok_system_call {
my $test = shift;
my $expect_success = shift;
$expect_success = 1 if not defined $expect_success;
my $ok = (system($test) == 0);
# my $exit_code = $? >> 8;
# diag "exit code was: $exit_code";
return $expect_success ? ok($ok, $test) : ok(!$ok, $test);
}
sub not_ok_system_call {
my $test= shift;
return ok_system_call($test,0);
}
The error checking doesn't work correctly on the last one ("boom|true"),
so it fails.
I believe this happens because although boom fails, something is sent through
the pipe, and 'true' succeeds on the other end of the pipe. What's the best
practicing for error checking a piped command so this case is covered?
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.