adjust example commands for testing
[barcat.git] / t / examples.t
1 #!/usr/bin/env perl
2 use 5.014;
3 use warnings;
4 use Test::More;
5
6 my %CMDARGS = (
7         ping => '-c 1',
8         curl => '-sS',
9         'cat \Klog/' => '/var/log/apache2/',
10 );
11
12 my $filename = 'barcat';
13 open my $input, '<', $filename
14         or die "Cannot read documentation from $filename script\n";
15
16 local $/ = "\n\n";
17 while (readline $input) {
18         /^=head1 EXAMPLES/ ... /^=head1/ or next;
19         /^\h/ or next;
20         chomp;
21
22         my ($name) = /[\h(]*([^|]+)/;
23
24         my $cmd = $_;
25         while (my ($subcmd, $args) = each %CMDARGS) {
26                 $subcmd .= " \\K", $args .= ' ' unless $subcmd =~ m/\\K/;
27                 $cmd =~ s/\b$subcmd/$args/;
28         }
29         ok(qx($cmd), $name);
30 }
31
32 done_testing();