8 { # silence fail diagnostics because of single caller
9 no warnings 'redefine';
10 sub Test::Builder::_ok_debug {}
16 'cat \Klog/' => '/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 code snippets in the appropriate section
26 /^=head1 EXAMPLES/ ... /^=head1/ or next;
30 # compose an identifier from significant parts
32 s/^\h+//; # indentation
33 s/\\\n\s*//g; # line continuations
34 s/^[(\h]+//; # subshell
35 s/^echo\ .*?\|\s*//; # preceding input
36 s/\|.*//; # subsequent pipes
37 s/^cat\ //; # local file
38 s/^curl\ // and do { # remote url
39 s/\ -.+//g; # download options
40 s{//[^/\s]+/\K\S*(?=/)}{}; # subdirectories
41 s{^https?://}{}; # http protocol
45 # prepare shell command to execute
47 while (my ($subcmd, $args) = each %CMDARGS) {
48 $subcmd .= " \\K", $args .= ' ' unless $subcmd =~ m/\\K/;
49 $cmd =~ s/\b$subcmd/$args/;
51 my @cmd = (bash => -c => "set -o pipefail\n$cmd");
53 # run and report unexpected results
55 run(\@cmd, \undef, \my $output, \my $error);
56 die("error message:\n $error\n") if $error;
57 $? == 0 or die "exit status ", $? >> 8, "\n";
58 length $output or die "empty output\n";
60 }, $name) or diag("Failed command\n@cmd\nfrom $filename line $.: $@");