From 7ec35e1753e54d53e3ac85ad37b35c62e3495440 Mon Sep 17 00:00:00 2001 From: Lars Kruse Date: Thu, 8 Mar 2018 04:17:18 +0100 Subject: [PATCH] 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). --- t/test.t | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/t/test.t b/t/test.t index 08debf70..ed255731 100644 --- a/t/test.t +++ b/t/test.t @@ -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' } );