Skip to content
Snippets Groups Projects
Commit b87ec973 authored by Simon McVittie's avatar Simon McVittie
Browse files

CapsuleTest: If a command fails, explain how

parent e5c03a80
Branches
Tags
1 merge request!311Build capsule-capture-libs from a bundled copy of libcapsule
...@@ -30,6 +30,7 @@ use Test::More; ...@@ -30,6 +30,7 @@ use Test::More;
our @EXPORT = qw( our @EXPORT = qw(
diag_multiline diag_multiline
explain_wait_status
get_symbols_with_nm get_symbols_with_nm
run_ok run_ok
run_verbose run_verbose
...@@ -176,6 +177,38 @@ sub diag_multiline { ...@@ -176,6 +177,38 @@ sub diag_multiline {
} }
} }
=item explain_wait_status(I<CODE>)
Convert Unix-style wait status I<CODE> into something human-readable.
=cut
sub explain_wait_status {
my $status = shift;
my @ret;
my $signal = $status & 127;
my $code = ($status >> 8);
if ($signal) {
push @ret, "killed by signal $signal";
}
if ($status & 128) {
push @ret, 'core dumped';
}
if ($code & 128) {
my $maybe = $code & 127;
unshift @ret,
"exited with code $code (child process killed by signal $maybe?)";
}
elsif ($code || ! @ret) {
unshift @ret, "exited with code $code";
}
return join(', ', @ret);
}
=item run_ok(I<ARGV>, ...) =item run_ok(I<ARGV>, ...)
A TAP assertion that the given command exits 0. I<ARGV> is an A TAP assertion that the given command exits 0. I<ARGV> is an
...@@ -188,7 +221,13 @@ sub run_ok { ...@@ -188,7 +221,13 @@ sub run_ok {
my $argv = shift; my $argv = shift;
my $debug = join(' ', @$argv); my $debug = join(' ', @$argv);
diag($debug); diag($debug);
ok(run($argv, @_), qq{"$debug" should succeed}); if (run($argv, @_)) {
ok(1, qq{Command successful as expected: '$debug'});
}
else {
my $explained = explain_wait_status($?);
ok(0, "Command exited with status $? ($explained): '$debug'");
}
} }
=item run_verbose(I<ARGV>, ...) =item run_verbose(I<ARGV>, ...)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment