From cb5abf1981629234f4ee0e1b2ecda2b32ef1cb00 Mon Sep 17 00:00:00 2001 From: Lorenz Kästle <12514511+RincewindsHat@users.noreply.github.com> Date: Wed, 19 Feb 2025 14:36:37 +0100 Subject: opttest.pl: Move to tools --- tools/opttest.pl | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100755 tools/opttest.pl (limited to 'tools/opttest.pl') diff --git a/tools/opttest.pl b/tools/opttest.pl new file mode 100755 index 00000000..96c4fb0a --- /dev/null +++ b/tools/opttest.pl @@ -0,0 +1,51 @@ +#!/usr/bin/perl -w +use strict; +use warnings; +use Test; + +use vars qw($dir $file $prog $idx $state $output %progs @dirs); + +my $tests = 0; + +@dirs = qw(plugins plugins-scripts); + +foreach my $dir (@dirs) { + opendir(DIR, $dir) || die "can't opendir $dir: $!"; + while ($file = readdir(DIR)) { + if (-x "$dir/$file" && -f "$dir/$file") { + $tests++; + $progs{"$dir/$file"} = $file; + } + } + closedir DIR; +} + +plan tests => $tests; + +for my $prog (keys %progs) { + $state = 0; + $file = `basename $prog`; + + $idx = 1; + $output = `$prog -h 2>&1`; + if($?) {$state++;print "$prog failed test $idx\n";} + unless ($output =~ m/$progs{$prog}/ms) { + $idx++; $state++;print "$output\n$prog failed test $idx\n"; + } + + $idx++; + `$prog --help 2>&1 > /dev/null`; + if($?) {$state++;print "$prog failed test $idx\n";} + + $idx++; + `$prog -V 2>&1 > /dev/null`; + if($?) {$state++;print "$prog failed test $idx\n";} + + $idx++; + `$prog --version 2>&1 > /dev/null`; + if($?) {$state++;print "$prog failed test $idx\n";} + + print "$prog ($idx tests) "; + ok $state,0; +} + -- cgit v1.2.3-74-g34f1 From b982e12ecfee9db869d443d2a8524182b7d09b13 Mon Sep 17 00:00:00 2001 From: Lorenz Kästle <12514511+RincewindsHat@users.noreply.github.com> Date: Wed, 19 Feb 2025 19:43:40 +0100 Subject: Fix opttest script --- tools/opttest.pl | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) (limited to 'tools/opttest.pl') diff --git a/tools/opttest.pl b/tools/opttest.pl index 96c4fb0a..56a5c88f 100755 --- a/tools/opttest.pl +++ b/tools/opttest.pl @@ -28,22 +28,41 @@ for my $prog (keys %progs) { $idx = 1; $output = `$prog -h 2>&1`; - if($?) {$state++;print "$prog failed test $idx\n";} + if(($? >> 8) != 3) { + $state++; + print "$prog failed test $idx (help exit code (short form))\n"; + exit(1); + } + unless ($output =~ m/$progs{$prog}/ms) { - $idx++; $state++;print "$output\n$prog failed test $idx\n"; + $idx++; + $state++; + print "$output\n$prog failed test $idx\n"; } $idx++; `$prog --help 2>&1 > /dev/null`; - if($?) {$state++;print "$prog failed test $idx\n";} + if(($? >> 8) != 3) { + $state++; + print "$prog failed test $idx (help exit code (long form))\n"; + exit(1); + } $idx++; - `$prog -V 2>&1 > /dev/null`; - if($?) {$state++;print "$prog failed test $idx\n";} + `$prog -V 2>&1 > /dev/null`; + if(($? >> 8) != 3) { + $state++; + print "$prog failed test $idx (version exit code (short form))\n"; + exit(1); + } $idx++; `$prog --version 2>&1 > /dev/null`; - if($?) {$state++;print "$prog failed test $idx\n";} + if(($? >> 8) != 3) { + $state++; + print "$prog failed test $idx (version exit code (long form))\n"; + exit(1); + } print "$prog ($idx tests) "; ok $state,0; -- cgit v1.2.3-74-g34f1 From 0d0f4ee7e30dcd2c5f9f0c53400ed6b2a9bc14a2 Mon Sep 17 00:00:00 2001 From: Lorenz Kästle <12514511+RincewindsHat@users.noreply.github.com> Date: Wed, 19 Feb 2025 19:46:37 +0100 Subject: Add a comment to opttest to explain the purpose --- tools/opttest.pl | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'tools/opttest.pl') diff --git a/tools/opttest.pl b/tools/opttest.pl index 56a5c88f..98213082 100755 --- a/tools/opttest.pl +++ b/tools/opttest.pl @@ -3,6 +3,10 @@ use strict; use warnings; use Test; +# This script (when executed from the monitoring plugins top level directory) +# executes all the plugins with -h, --help, -V and --version to verify that +# all of them exit properly with the state UNKNOWN (3) + use vars qw($dir $file $prog $idx $state $output %progs @dirs); my $tests = 0; -- cgit v1.2.3-74-g34f1