Author: particle
Date: Thu Jul 28 13:05:32 2005
New Revision: 8720
Added:
trunk/t/run/
trunk/t/run/exit.t
Log:
[perl #36677] checked in to wrong branch.
added t/run/exit.t to trunk
Added: trunk/t/run/exit.t
==============================================================================
--- (empty file)
+++ trunk/t/run/exit.t Thu Jul 28 13:05:32 2005
@@ -0,0 +1,66 @@
+#! perl -w
+
+# Copyright: 2001-2004 The Perl Foundation. All Rights Reserved.
+# $Id$
+
+=head1 NAME
+
+t/run/exit.t - test parrot exit codes
+
+=head1 SYNOPSIS
+
+ % perl -Ilib t/run/exit.t
+
+=head1 DESCRIPTION
+
+Tests C<Parrot> exit codes. Tests variations of normal and abnormal exit
+with combinations of STDERR and STDOUT open and closed.
+
+=cut
+
+use Parrot::Test tests => 8;
+use Test::More;
+use Parrot::Config;
+
+$PARROT = ".$PConfig{slash}$PConfig{test_prog}";
+
+# windows wants '>nul', most everything else wants '>/dev/null'
+my $redir = $^O =~ /^(MSWin\d+)$/
+ ? q{>nul 2>&1}
+ : q{>/dev/null 2>&1};
+
+# copy file descriptors
+open OLDOUT, ">&STDOUT";
+open OLDERR, ">&STDERR";
+
+sub exits
+{
+ my $pre = shift;
+ $pre ||= '';
+
+ is( system(qq|$PARROT --version $redir|) >> 8, 0, "$pre: normal exit" );
+ isnt( system(qq|$PARROT --foo $redir|) >> 8, 0, "$pre: abnormal exit" );
+}
+
+# all open
+exits( 'STDERR & STDOUT open' );
+
+# close stderr
+close STDERR or die qq|Cannot close STDERR: $!|;
+exits( 'STDERR closed' );
+
+# close stdout too
+close STDOUT or die qq|Cannot close STDOUT: $!|;
+exits( 'STDERR & STDOUT closed' );
+
+# restore stderr
+open STDERR, ">&OLDERR" or die qq|Cannot restore stderr: $!|;
+exits( 'STDOUT closed' );
+
+# restore stdout
+open STDOUT, ">&OLDOUT" or die qq|Cannot restore stdout: $!|;
+
+# close copies
+close OLDOUT or die qq|Cannot close OLDOUT: $!|;
+close OLDERR or die qq|Cannot close OLDERR: $!|;
+