diff options
Diffstat (limited to 'tools/opttest.pl')
-rwxr-xr-x | tools/opttest.pl | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/tools/opttest.pl b/tools/opttest.pl new file mode 100755 index 00000000..98213082 --- /dev/null +++ b/tools/opttest.pl | |||
@@ -0,0 +1,74 @@ | |||
1 | #!/usr/bin/perl -w | ||
2 | use strict; | ||
3 | use warnings; | ||
4 | use Test; | ||
5 | |||
6 | # This script (when executed from the monitoring plugins top level directory) | ||
7 | # executes all the plugins with -h, --help, -V and --version to verify that | ||
8 | # all of them exit properly with the state UNKNOWN (3) | ||
9 | |||
10 | use vars qw($dir $file $prog $idx $state $output %progs @dirs); | ||
11 | |||
12 | my $tests = 0; | ||
13 | |||
14 | @dirs = qw(plugins plugins-scripts); | ||
15 | |||
16 | foreach my $dir (@dirs) { | ||
17 | opendir(DIR, $dir) || die "can't opendir $dir: $!"; | ||
18 | while ($file = readdir(DIR)) { | ||
19 | if (-x "$dir/$file" && -f "$dir/$file") { | ||
20 | $tests++; | ||
21 | $progs{"$dir/$file"} = $file; | ||
22 | } | ||
23 | } | ||
24 | closedir DIR; | ||
25 | } | ||
26 | |||
27 | plan tests => $tests; | ||
28 | |||
29 | for my $prog (keys %progs) { | ||
30 | $state = 0; | ||
31 | $file = `basename $prog`; | ||
32 | |||
33 | $idx = 1; | ||
34 | $output = `$prog -h 2>&1`; | ||
35 | if(($? >> 8) != 3) { | ||
36 | $state++; | ||
37 | print "$prog failed test $idx (help exit code (short form))\n"; | ||
38 | exit(1); | ||
39 | } | ||
40 | |||
41 | unless ($output =~ m/$progs{$prog}/ms) { | ||
42 | $idx++; | ||
43 | $state++; | ||
44 | print "$output\n$prog failed test $idx\n"; | ||
45 | } | ||
46 | |||
47 | $idx++; | ||
48 | `$prog --help 2>&1 > /dev/null`; | ||
49 | if(($? >> 8) != 3) { | ||
50 | $state++; | ||
51 | print "$prog failed test $idx (help exit code (long form))\n"; | ||
52 | exit(1); | ||
53 | } | ||
54 | |||
55 | $idx++; | ||
56 | `$prog -V 2>&1 > /dev/null`; | ||
57 | if(($? >> 8) != 3) { | ||
58 | $state++; | ||
59 | print "$prog failed test $idx (version exit code (short form))\n"; | ||
60 | exit(1); | ||
61 | } | ||
62 | |||
63 | $idx++; | ||
64 | `$prog --version 2>&1 > /dev/null`; | ||
65 | if(($? >> 8) != 3) { | ||
66 | $state++; | ||
67 | print "$prog failed test $idx (version exit code (long form))\n"; | ||
68 | exit(1); | ||
69 | } | ||
70 | |||
71 | print "$prog ($idx tests) "; | ||
72 | ok $state,0; | ||
73 | } | ||
74 | |||