]> git.draconx.ca Git - dxcommon.git/commitdiff
Avoid nonportable ${x##y} substitutions in program tests.
authorNick Bowler <nbowler@draconx.ca>
Tue, 9 Mar 2021 06:13:48 +0000 (01:13 -0500)
committerNick Bowler <nbowler@draconx.ca>
Tue, 9 Mar 2021 06:13:48 +0000 (01:13 -0500)
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 [new file with mode: 0644]
m4/bison.m4
m4/flex.m4
m4/gob2.m4
tests/macros.at
tests/programs.at

diff --git a/m4/basename.m4 b/m4/basename.m4
new file mode 100644 (file)
index 0000000..aeb1337
--- /dev/null
@@ -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()])
index 18274aaac096a1156ed36f97a94060454238ffd9..b3569f3fa5f2b7d241a2343db18187aca3eba110 100644 (file)
@@ -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=:
index 4e9b56fbb7a17cd61c0b61fd6685045bae8a51c0..1aa3dab3c10f726d89088f6b86a0eca79f22ae24 100644 (file)
@@ -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=:
index 5292c5c2774e2aae75bd700b97e9ed6e9f66a2ee..3e95ab46d5ca9cbf52e954da3da2f1d8b53aa31f 100644 (file)
@@ -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=:
index 07d23ca4b76d312b9a7e87461e6c403f97aae5c6..f746e54522ae8e849d0fab932ff6b044dc1eddf5 100644 (file)
@@ -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
index 1346edee73ec816e48590d6146f46c2a920e818f..5460b5ccd5dc7cf9b676edcc6995db0af3196aa3 100644 (file)
@@ -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