This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Another shot at testing exit codes.
authorMichael G. Schwern <schwern@pobox.com>
Fri, 29 Jun 2001 19:39:11 +0000 (15:39 -0400)
committerJarkko Hietaniemi <jhi@iki.fi>
Sat, 30 Jun 2001 12:59:25 +0000 (12:59 +0000)
Message-ID: <20010629193910.D25304@blackrider>

p4raw-id: //depot/perl@11039

MANIFEST
t/run/exit.t [new file with mode: 0644]

index fe882a2..7695b79 100644 (file)
--- a/MANIFEST
+++ b/MANIFEST
@@ -2060,6 +2060,7 @@ t/pod/testp2pt.pl         Module to test Pod::PlainText for a given file
 t/pod/testpchk.pl              Module to test Pod::Checker for a given file
 t/pod/testpods/lib/Pod/Stuff.pm                        Sample data for find.t
 t/README                       Instructions for regression tests
+t/run/exit.t                    Test perl's exit status.
 t/run/runenv.t                 Test if perl honors its environment variables.
 t/TEST                         The regression tester
 t/TestInit.pm                  Preamble library for core tests
diff --git a/t/run/exit.t b/t/run/exit.t
new file mode 100644 (file)
index 0000000..828b832
--- /dev/null
@@ -0,0 +1,32 @@
+#!./perl
+#
+# Tests for perl exit codes, playing with $?, etc...
+
+
+BEGIN {
+    chdir 't' if -d 't';
+    @INC = '../lib';
+}
+
+# VMS needs -e "...", most everything else works better with '
+my $quote = $^O eq 'VMS' ? q{"} : q{'};
+
+# Run some code, return its wait status.
+sub run {
+    my($code) = shift;
+    my $cmd = "$^X -e ";
+    return system($cmd.$quote.$code.$quote);
+}
+
+use Test::More tests => 3;
+
+my $exit;
+
+$exit = run('exit');
+is( $exit >> 8, 0,              'Normal exit' );
+
+$exit = run('exit 42');
+is( $exit >> 8, 42,             'Non-zero exit' );
+
+$exit = run('END { $? = 42 }');
+is( $exit >> 8, 42,             'Changing $? in END block' );