2 # Copyright (C) 2001-2004, Parrot Foundation.
7 t/run/exit.t - test parrot exit codes
15 Tests C<Parrot> exit codes. Tests variations of normal and abnormal exit
16 with combinations of STDERR and STDOUT open and closed. Also tests behavior
17 under error conditions, whether output files are created and whether the error
24 use lib qw( . lib ../lib ../../lib );
27 use Parrot::Test tests => 10;
30 use File::Temp qw(tempdir);
33 my $PARROT = ".$PConfig{slash}$PConfig{test_prog}";
34 my $redir = File::Spec->devnull;
36 # copy file descriptors
37 open *OLDOUT, ">&STDOUT" or die qq|Cannot dup STDOUT: $!|; ## no critic
38 open *OLDERR, ">&STDERR" or die qq|Cannot dup STDERR: $!|; ## no critic
44 is( system(qq|$PARROT --version $redir > $redir 2> $redir|) >> 8, 0, "$pre: normal exit" );
45 isnt( system(qq|$PARROT --foo $redir > $redir 2> $redir|) >> 8, 0, "$pre: abnormal exit" );
49 exits('STDERR & STDOUT open');
52 close *STDERR or die qq|Cannot close STDERR: $!|;
53 exits('STDERR closed');
56 close *STDOUT or die qq|Cannot close STDOUT: $!|;
57 exits('STDERR & STDOUT closed');
60 open *STDERR, ">&OLDERR" or die qq|Cannot restore stderr: $!|; ## no critic
61 exits('STDOUT closed');
64 open *STDOUT, ">&OLDOUT" or die qq|Cannot restore stdout: $!|; ## no critic
67 close *OLDOUT or die qq|Cannot close OLDOUT: $!|;
68 close *OLDERR or die qq|Cannot close OLDERR: $!|;
70 # exits nonzero on a parse error
71 my $tempdir = tempdir(CLEANUP => 1);
72 my $pirfn = File::Spec->catfile($tempdir, "test.pir");
73 my $pbcfn = File::Spec->catfile($tempdir, "test.pbc");
74 my $pirfile = IO::File->new(">$pirfn");
75 $pirfile->print("Parse error.\n");
77 my $rv = system(qq|$PARROT -o $pbcfn $pirfn $redir > $redir 2> $redir|) >> 8;
78 isnt($rv, 0, "parrot returns error on parse failure\n");
79 ok(! -e $pbcfn, "parrot doesn't create outfile on parse failure\n");
83 # cperl-indent-level: 4
86 # vim: expandtab shiftwidth=4: