2
0
mirror of https://github.com/munin-monitoring/contrib.git synced 2018-11-08 00:59:34 +01:00

tests: work around 'checkbashisms' complaining about "command -v"

"command -v" should be the preferred way of determining the location (or
existence) of an executable.
Sadly "checkbashisms" interprets "command -v" as a possible bashism,
since "command -v" was introduced in IEEE 1003.1 2013.
But checkbashisms checks for compliance with IEEE 1003.1 2004 - here
"command -v" is listed only as a portability extension.

See https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=733511 for the
discussion about checkbashism and "command -v".

See https://unix.stackexchange.com/a/85250 for the discussion about
"command -v" being the most portable check for a program's location.

The workaround itself is bit ugly: 'checkbashisms' is monkey-patched
and fed into the perl interpreter. This makes it harder to re-run the
check command manually (due to complicated quoting).
This commit is contained in:
Lars Kruse 2018-03-08 04:17:18 +01:00
parent 189c3953e7
commit 7ec35e1753

View File

@ -56,8 +56,22 @@ sub process_file {
description => 'sh syntax check'
}
);
my $checkbashisms_location = `command -v checkbashisms 2>/dev/null`;
chomp($checkbashisms_location);
my $command;
if ($checkbashisms_location ne "") {
# monkey-patch "checkbashisms" in order to allow "command -v"
# see https://unix.stackexchange.com/a/85250: "command -v" vs. which/hash/...
# see https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=733511
my $run_modified_checkbashisms = q/sed 's#command\\\s+-\[\^p\]#command\s+-[^pvV]#'/
. " '$checkbashisms_location' | perl - '$file'";
$command = [ 'sh', '-c', $run_modified_checkbashisms ];
} else {
# make sure that the non-confusing "checkbashisms not found" message is displayed
$command = [ 'checkbashisms', $file ];
}
run_check(
{ command => [ 'checkbashisms', $file ],
{ command => $command,
description => 'checkbashisms'
}
);