Permalink
Browse files

add checking the exit code of the commands

  • Loading branch information...
1 parent 9030f5b commit 0b04fc240b591bafb7c4f91ec3e62c37673c3019 @szabgab committed Apr 9, 2009
Showing with 31 additions and 0 deletions.
  1. +12 −0 eg/samedir/other.pl
  2. +1 −0 eg/samedir/other.pl.err
  3. +1 −0 eg/samedir/other.pl.exit
  4. +1 −0 eg/samedir/other.pl.in
  5. +2 −0 eg/samedir/other.pl.out
  6. +14 −0 lib/Test/Snapshots.pm
View
@@ -0,0 +1,12 @@
+#!/usr/bin/perl
+use strict;
+use warnings;
+
+print "Please type in your name\n";
+my $name = <STDIN>;
+chomp $name;
+print "Hello $name\n";
+
+warn "Some warning\n";
+exit(10);
+
@@ -0,0 +1 @@
+Some warning
@@ -0,0 +1 @@
+10
@@ -0,0 +1 @@
+Foo
@@ -0,0 +1,2 @@
+Please type in your name
+Hello Foo
View
@@ -136,6 +136,7 @@ my $glob = '*.pl';
my $command = $^X;
my $skip = {};
my $accessories_dir;
+my $default_expected_exit = 0;
sub debug {
$debug = shift;
@@ -245,6 +246,7 @@ sub test_all_snapshots {
my $T = Test::Builder->new;
my $cnt = $combine ? 1 : 2;
+ $cnt++; # for exit codes
$T->plan(tests => @files * $cnt );
my $tempdir = tempdir( CLEANUP => 1 );
@@ -275,6 +277,8 @@ sub test_all_snapshots {
}
#$T->diag($file);
system $cmd;
+ my $exit = $?;
+ #$T->diag("Exit '$exit'");
my @stds = $combine ? qw(out) : qw(err out);
foreach my $ext (@stds) {
@@ -288,6 +292,16 @@ sub test_all_snapshots {
or $T->diag("Expected nothing.\nReceived\n\n$data");
}
}
+ # exit code
+ {
+ my $expected_exit = $default_expected_exit;
+ my $expected_file = "$accessories_path.exit";
+ if (-e $expected_file) {
+ $expected_exit = _slurp($expected_file);
+ chomp $expected_exit;
+ }
+ $T->is_eq($exit >> 8, $expected_exit, "Exit code of $file");
+ }
}
}

0 comments on commit 0b04fc2

Please sign in to comment.