]> git.ipfire.org Git - thirdparty/util-linux.git/blobdiff - tests/functions.sh
tests: add --use-system-commands
[thirdparty/util-linux.git] / tests / functions.sh
index 2fb0ddb5f42459d032da70b3a59676f0dbb43d24..ab607c4ced47b213f27c2293abbf0de7c929b782 100644 (file)
@@ -75,9 +75,19 @@ function ts_report {
 }
 
 function ts_check_test_command {
-       if [ ! -x "$1" ]; then
-               ts_skip "${1##*/} not found"
-       fi
+       case "$1" in
+       */*)
+               # paths
+               if [ ! -x "$1" ]; then
+                       ts_skip "${1##*/} not found"
+               fi
+               ;;
+       *)
+               # just command names (e.g. --use-system-commands)
+               local cmd=$1
+               type "$cmd" >/dev/null 2>&1 || ts_skip "missing in PATH: $cmd"
+               ;;
+       esac
 }
 
 function ts_check_prog {
@@ -254,8 +264,20 @@ function ts_init_env {
        top_srcdir=$(ts_abspath $top_srcdir)
        top_builddir=$(ts_abspath $top_builddir)
 
-       # some ul commands search other ul commands in $PATH
-       export PATH="$top_builddir:$PATH"
+       # We use helpser always from build tree
+       ts_helpersdir="${top_builddir}/"
+
+       TS_USE_SYSTEM_COMMANDS=$(ts_has_option "use-system-commands" "$*")
+       if [ "$TS_USE_SYSTEM_COMMANDS" == "yes" ]; then
+               # Don't define anything, just follow current PATH
+               ts_commandsdir=""
+       else
+               # The default is to use commands from build tree
+               ts_commandsdir="${top_builddir}/"
+
+               # some ul commands search other ul commands in $PATH
+               export PATH="$ts_commandsdir:$PATH"
+       fi
 
        TS_SCRIPT="$mydir/$(basename $0)"
        TS_SUBDIR=$(dirname $TS_SCRIPT)
@@ -319,6 +341,8 @@ function ts_init_env {
        if [ "$TS_VERBOSE" == "yes" ]; then
                echo
                echo "     script: $TS_SCRIPT"
+               echo "   commands: $ts_commandsdir"
+               echo "    helpers: $ts_helpersdir"
                echo "    sub dir: $TS_SUBDIR"
                echo "    top dir: $TS_TOPDIR"
                echo "       self: $TS_SELF"