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?