neilwatson has asked for the wisdom of the Perl Monks concerning the following question:
I've read that WIFEXITED from POSIX is supposed to reverse the logic of the system command so that commands that return above zero will be evaled as false. But, my test shows nothing happening. What have I missed?
What does test one pass?#!/usr/bin/perl use strict; use warnings; use feature 'say'; use Data::Dumper; use POSIX qw/ WIFEXITED /; use Test::More tests => 2; WIFEXITED( system '/bin/false' ) or die $!; ok( WIFEXITED( system '/bin/false' ), "Should fail because exits 1" ); ok( WIFEXITED( system '/bin/true' ), "Should pass because exits 0" ); done_testing(); Run it: 1..2 ok 1 - Should fail because exits 1 ok 2 - Should pass because exits 0
UPDATE: This works:
#!/usr/bin/perl use strict; use warnings; use feature 'say'; use Data::Dumper; use POSIX qw/ WIFEXITED /; use Test::More tests => 2; ok( WIFEXITED( ( system '/bin/false' ) >> 8 ) , "This should fail because exits 1" ); ok( WIFEXITED( ( system '/bin/true' ) >> 8 ) , "This should pass because exits 0" ); done_testing(); Run it: 1..2 not ok 1 - This should fail because exits 1 # Failed test 'This should fail because exits 1' # at ./perl line 10. ok 2 - This should pass because exits 0 # Looks like you failed 1 test of 2.
Neil Watson
watson-wilson.ca
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: WIFEXITED when system returns none zero
by pme (Monsignor) on Aug 11, 2015 at 17:26 UTC | |
by neilwatson (Priest) on Aug 11, 2015 at 17:34 UTC |