From 485ec08e224f3ffed90259f445839572096187a0 Mon Sep 17 00:00:00 2001 From: Nick Bowler Date: Tue, 9 Mar 2021 01:13:48 -0500 Subject: [PATCH] Avoid nonportable ${x##y} substitutions in program tests. Using ${x##y} is not portable: in particular it is not supported by Solaris /bin/sh (or heirloom-sh). Define a new macro DX_BASENAME which implements the particular substitution in a compatible way, then use it in the flex, bison and gob2 tests. Moreover, apparently heirloom-sh does not support "command" either, so let's suppress the error message it generates (the tests will still produce a usable result), and adjust the test cases to the correct expected output in this scenario. --- m4/basename.m4 | 24 ++++++++++++++++++++++++ m4/bison.m4 | 4 ++-- m4/flex.m4 | 4 ++-- m4/gob2.m4 | 4 ++-- tests/macros.at | 31 +++++++++++++++++++++++++++++++ tests/programs.at | 11 +++++++---- 6 files changed, 68 insertions(+), 10 deletions(-) create mode 100644 m4/basename.m4 diff --git a/m4/basename.m4 b/m4/basename.m4 new file mode 100644 index 0000000..aeb1337 --- /dev/null +++ b/m4/basename.m4 @@ -0,0 +1,24 @@ +dnl Copyright © 2021 Nick Bowler +dnl +dnl License WTFPL2: Do What The Fuck You Want To Public License, version 2. +dnl This is free software: you are free to do what the fuck you want to. +dnl There is NO WARRANTY, to the extent permitted by law. + +dnl DX_BASENAME(variable, string) +dnl +dnl If string, which must be a single shell word, contains a / character, +dnl variable is assigned to the portion of string that follows the last +dnl such character. Otherwise, variable is set to string. +AC_DEFUN([DX_BASENAME], +[AC_REQUIRE([_DX_BASENAME_SETUP])dnl +dx_fn_basename $1 $2]) + +AC_DEFUN_ONCE([_DX_BASENAME_SETUP], [m4_divert_push([INIT_PREPARE])dnl +dx_fn_basename () { + _dx_tmp=; { _dx_tmp=${2##*/}; } 2>/dev/null + AS_CASE([$_dx_tmp], [""], [_dx_save_IFS=$IFS; IFS=/ + for _dx_tmp in $][2; do :; done + IFS=$_dx_save_IFS]) + AS_VAR_SET([$][1], [$_dx_tmp]) +} +m4_divert_pop()]) diff --git a/m4/bison.m4 b/m4/bison.m4 index 18274aa..b3569f3 100644 --- a/m4/bison.m4 +++ b/m4/bison.m4 @@ -38,8 +38,8 @@ AC_CACHE_CHECK([for bison], [ac_cv_path_BISON], [dx_cv_bison_found=: AC_PATH_PROGS_FEATURE_CHECK([BISON], [bison], [_DX_BISON_DO_TEST([$ac_path_BISON], -[bison_relcmd=${ac_path_BISON##*/} -bison_bypath=`command -v "$bison_relcmd"` #'' +[DX_BASENAME([bison_relcmd], ["$ac_path_BISON"]) +bison_bypath=`{ command -v "$bison_relcmd"; } 2>/dev/null` #'' ac_cv_path_BISON=$ac_path_BISON test x"$bison_bypath" = x"$ac_path_BISON" && ac_cv_path_BISON=$bison_relcmd ac_path_BISON_found=: diff --git a/m4/flex.m4 b/m4/flex.m4 index 4e9b56f..1aa3dab 100644 --- a/m4/flex.m4 +++ b/m4/flex.m4 @@ -20,8 +20,8 @@ AC_CACHE_CHECK([for flex], [ac_cv_path_FLEX], [dx_cv_flex_found=: AC_PATH_PROGS_FEATURE_CHECK([FLEX], [flex lex], [_DX_FLEX_DO_TEST([$ac_path_FLEX], -[flex_relcmd=${ac_path_FLEX##*/} -flex_bypath=`command -v "$flex_relcmd"` #'' +[DX_BASENAME([flex_relcmd], ["$ac_path_FLEX"]) +flex_bypath=`{ command -v "$flex_relcmd"; } 2>/dev/null` #'' ac_cv_path_FLEX=$ac_path_FLEX test x"$flex_bypath" = x"$ac_path_FLEX" && ac_cv_path_FLEX=$flex_relcmd ac_path_FLEX_found=: diff --git a/m4/gob2.m4 b/m4/gob2.m4 index 5292c5c..3e95ab4 100644 --- a/m4/gob2.m4 +++ b/m4/gob2.m4 @@ -25,8 +25,8 @@ AC_CACHE_CHECK([for GObject Builder], [ac_cv_path_GOB2], AC_PATH_PROGS_FEATURE_CHECK([GOB2], [gob2], [rm -f conftest.c $ac_path_GOB2 conftest.gob >&AS_MESSAGE_LOG_FD 2>&1 && test -f conftest.c && { - gob_relcmd=${ac_path_GOB2##*/} - gob_bypath=`command -v "$gob_relcmd"` # '' + DX_BASENAME([gob_relcmd], ["$ac_path_GOB2"]) + gob_bypath=`{ command -v "$gob_relcmd"; } 2>/dev/null` # '' ac_cv_path_GOB2=$ac_path_GOB2 test x"$gob_bypath" = x"$ac_path_GOB2" && ac_cv_path_GOB2=$gob_relcmd ac_path_GOB2_found=: diff --git a/tests/macros.at b/tests/macros.at index 07d23ca..f746e54 100644 --- a/tests/macros.at +++ b/tests/macros.at @@ -235,3 +235,34 @@ MOFILES = @&t@ ]]) AT_CLEANUP + +AT_SETUP([DX_BASENAME]) +AT_KEYWORDS([DX_BASENAME macro]) + +AT_DATA([test.in], [[@base0@ +@base1@ +@base2@ +@base3@ +]]) + +TEST_CONFIGURE_AC( +[[DX_BASENAME([base0], ["hello"]) +DX_BASENAME([base1], ["foo/bar"]) +DX_BASENAME([base2], ["/foo/bar/baz"]) +DX_BASENAME([base3], ["hello world"]) +AC_SUBST([base0]) +AC_SUBST([base1]) +AC_SUBST([base2]) +AC_SUBST([base3]) +AC_CONFIG_FILES([test]) +]]) +TEST_AUTORECONF + +TEST_CONFIGURE +AT_CHECK([cat test], [0], [hello +bar +baz +hello world +]) + +AT_CLEANUP diff --git a/tests/programs.at b/tests/programs.at index 1346ede..5460b5c 100644 --- a/tests/programs.at +++ b/tests/programs.at @@ -37,14 +37,17 @@ TEST_AUTORECONF # Check the search via path lookup save_PATH=$PATH -PATH=$PWD/bin${PATH:+":$PATH"} +PATH=`pwd`/bin${PATH:+":$PATH"} -# Sanity test on PATH lookup -AT_CHECK([test x"`command -v $1`" = x"$PWD/bin/$1" || exit 99 #'']) +# Sanity test on PATH lookup; configure will substitute absolute path if +# "command" does not work (e.g., heirloom-sh). +expected=$1 +val=`$TEST_SHELL -c 'command -v $1'` +test x"$val" = x"`pwd`/bin/$1" || expected=`pwd`/bin/$1 TEST_CONFIGURE AT_CHECK_UNQUOTED([cat test], [0], [yes -$1 +$expected ]) PATH=$save_PATH -- 2.43.0