X-Git-Url: http://git.shiar.net/barcat.git/blobdiff_plain/fd1358b672c565160eb163da00b404325864114d..a755882b1f5e89f6bd691219fe6de170cc6fcda7:/t/examples.t diff --git a/t/examples.t b/t/examples.t index 0b5e778..874b94a 100755 --- a/t/examples.t +++ b/t/examples.t @@ -2,12 +2,18 @@ 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', curl => '-sS', - 'cat \Klog/' => '/var/log/apache2/', + 'cat \Khttpd/' => '/var/log/apache2/', ); my $filename = 'barcat'; @@ -16,9 +22,10 @@ open my $input, '<', $filename local $/ = "\n\n"; while (readline $input) { - # find code snippets in the appropriate section + # find scriptlets in the appropriate section /^=head1 EXAMPLES/ ... /^=head1/ or next; - /^\h/ or next; + /^\h/ or next; # indented code snippet + /\A\h*>/ and next; # psql prompt chomp; # compose an identifier from significant parts @@ -27,6 +34,7 @@ while (readline $input) { s/\\\n\s*//g; # line continuations s/^[(\h]+//; # subshell s/^echo\ .*?\|\s*//; # preceding input + s/'(\S+)[^']*'/$1/g; # quoted arguments s/\|.*//; # subsequent pipes s/^cat\ //; # local file s/^curl\ // and do { # remote url @@ -42,13 +50,16 @@ 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, \my $error); + die("error message:\n $error\n") if $error; + $? == 0 or die "exit status ", $? >> 8, "\n"; + length $output or die "empty output\n"; + return 1; + }, $name) or diag("Failed command\n@cmd\nfrom $filename line $.: $@"); } done_testing();