IPC::Run to run example commands
[barcat.git] / t / examples.t
index 0b5e77855b86f7dd1163044957b3898003b8384b..52e7a5a7b732f06bec7a4037617d8eb36afa1e7d 100755 (executable)
@@ -2,7 +2,13 @@
 use 5.014;
 use warnings;
 use re '/ms';
+use IPC::Run 'run';
+
 use Test::More;
+{ # silence fail diagnostics because of single caller
+       no warnings 'redefine';
+       sub Test::Builder::_ok_debug {}
+}
 
 my %CMDARGS = (
        ping => '-c 1',
@@ -42,13 +48,15 @@ while (readline $input) {
                $subcmd .= " \\K", $args .= ' ' unless $subcmd =~ m/\\K/;
                $cmd =~ s/\b$subcmd/$args/;
        }
-       $cmd =~ s/'/'\\''/g, $cmd = "  bash -c 'set -o pipefail\n$cmd'";
+       my @cmd = (bash => -c => "set -o pipefail\n$cmd");
 
        # run and report unexpected results
        ok(eval {
-               qx($cmd) or return;
-               return $? == 0;
-       }, $name) or diag($cmd);
+               run(\@cmd, \undef, \my $output);
+               $? == 0 or die "error status ", $? >> 8, "\n";
+               length $output or die "empty output\n";
+               return 1;
+       }, $name) or diag("Failed command\n@cmd\nfrom $filename line $.: $@");
 }
 
 done_testing();