develooper Front page | perl.perl5.porters | Postings from June 2001

[PATCH t/run/exit.t] Another shot at testing exit codes.

Thread Next
From:
Michael G Schwern
Date:
June 29, 2001 16:39
Subject:
[PATCH t/run/exit.t] Another shot at testing exit codes.
Message ID:
20010629193910.D25304@blackrider
Okay, here' another shot at a test for perl's exit codes.  This one
should work fine on VMS and everything else.  Of course, its going to
fail on VMS, but that's because non-zero exit codes appear to be broken.


--- /dev/null	Sat Apr 14 22:09:58 2001
+++ t/run/exit.t	Fri Jun 29 19:31:36 2001
@@ -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' );
--- MANIFEST	2001/06/29 23:32:06	1.1
+++ MANIFEST	2001/06/29 23:32:40
@@ -2055,6 +2055,7 @@
 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


-- 

Michael G. Schwern   <schwern@pobox.com>    http://www.pobox.com/~schwern/
Perl6 Quality Assurance     <perl-qa@perl.org>	     Kwalitee Is Job One
BOFH excuse #18:

excess surge protection

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About