X-Git-Url: http://git.shiar.nl/barcat.git/blobdiff_plain/45371e38949c63a14570a6d69ee0302d70cd48e1..1b44cc9300bce9f117fd135102482ff50638c650:/t/examples.t diff --git a/t/examples.t b/t/examples.t index 02019b9..ae3e7c9 100755 --- a/t/examples.t +++ b/t/examples.t @@ -1,7 +1,13 @@ #!/usr/bin/env perl use 5.014; use warnings; +use re '/ms'; + use Test::More; +{ # silence fail diagnostics because of single caller + no warnings 'redefine'; + sub Test::Builder::_ok_debug {} +} my %CMDARGS = ( ping => '-c 1', @@ -20,7 +26,20 @@ while (readline $input) { /^\h/ or next; chomp; - my ($name) = /[\h(]*([^|]+)/; + # compose an identifier from significant parts + do { + s/^\h+//; # indentation + s/\\\n\s*//g; # line continuations + s/^[(\h]+//; # subshell + s/^echo\ .*?\|\s*//; # preceding input + s/\|.*//; # subsequent pipes + s/^cat\ //; # local file + s/^curl\ // and do { # remote url + s/\ -.+//g; # download options + s{//[^/\s]+/\K\S*(?=/)}{}; # subdirectories + s{^https?://}{}; # http protocol + }; + } for my $name = $_; # prepare shell command to execute my $cmd = $_; @@ -28,13 +47,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'"; + $cmd =~ s/'/'\\''/g, $cmd = " bash -c 'set -o pipefail\n$cmd'"; # run and report unexpected results ok(eval { - qx($cmd) or return; - return $? == 0; - }, $name); + my $output = qx($cmd); + $? == 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();