8 { # silence fail diagnostics because of single caller
9 no warnings 'redefine';
10 sub Test::Builder::_ok_debug {}
16 'cat \Khttpd/' => '/var/log/apache2/',
19 my $filename = 'barcat';
20 open my $input, '<', $filename
21 or die "Cannot read documentation from $filename script\n";
24 while (readline $input) {
25 # find scriptlets in the appropriate section
26 /^=head1 EXAMPLES/ ... /^=head1/ or next;
27 /^\h/ or next; # indented code snippet
28 /\A\h*>/ and next; # psql prompt
31 # compose an identifier from significant parts
33 s/^\h+//; # indentation
34 s/\\\n\s*//g; # line continuations
35 s/^[(\h]+//; # subshell
36 s/^echo\ .*?\|\s*//; # preceding input
37 s/'(\S+)[^']*'/$1/g; # quoted arguments
38 s/\|.*//; # subsequent pipes
39 s/^cat\ //; # local file
40 s/^curl\ // and do { # remote url
41 s/\ -.+//g; # download options
42 s{//[^/\s]+/\K\S*(?=/)}{}; # subdirectories
43 s{^https?://}{}; # http protocol
47 # prepare shell command to execute
49 while (my ($subcmd, $args) = each %CMDARGS) {
50 $subcmd .= " \\K", $args .= ' ' unless $subcmd =~ m/\\K/;
51 $cmd =~ s/\b$subcmd/$args/;
53 my @cmd = (bash => -c => "set -o pipefail\n$cmd");
55 # run and report unexpected results
57 run(\@cmd, \undef, \my $output, \my $error);
58 die("error message:\n $error\n") if $error;
59 $? == 0 or die "exit status ", $? >> 8, "\n";
60 length $output or die "empty output\n";
62 }, $name) or diag("Failed command\n@cmd\nfrom $filename line $.: $@");