diff options
author | Tavian Barnes <tavianator@tavianator.com> | 2022-02-01 13:27:46 -0500 |
---|---|---|
committer | Tavian Barnes <tavianator@tavianator.com> | 2022-02-01 13:28:24 -0500 |
commit | 09fd2a82ded3cf97f91f30fa1ed4937b60fc9998 (patch) | |
tree | ece384d08ae8e11aad660fedcb946fb71c56a07d /tests.sh | |
parent | 9278a01d858d78a2e19e6da7388caa76bc1fc849 (diff) | |
download | bfs-09fd2a82ded3cf97f91f30fa1ed4937b60fc9998.tar.xz |
tests: Allow tests.sh to be invoked from any directory
This also resolves the path passed to --bfs early, so --bfs=./bfs now
works.
Diffstat (limited to 'tests.sh')
-rwxr-xr-x | tests.sh | 34 |
1 files changed, 21 insertions, 13 deletions
@@ -17,7 +17,6 @@ ############################################################################ set -e -set -o physical umask 022 export LC_ALL=C @@ -40,6 +39,8 @@ if [ -t 1 ]; then RST="$(printf '\033[0m')" fi +UNAME="$(uname)" + if command -v capsh &>/dev/null; then if capsh --has-p=cap_dac_override &>/dev/null || capsh --has-p=cap_dac_read_search &>/dev/null; then if [ -n "$BFS_TRIED_DROP" ]; then @@ -63,7 +64,7 @@ EOF fi elif [ "$EUID" -eq 0 ]; then UNLESS= - if [ "$(uname)" = "Linux" ]; then + if [ "$UNAME" = "Linux" ]; then UNLESS=" unless ${GRN}capsh${RST} is installed" fi @@ -107,17 +108,6 @@ Usage: ${GRN}$0${RST} [${BLU}--bfs${RST}=${MAG}path/to/bfs${RST}] [${BLU}--posix EOF } -function _realpath() { - ( - cd "${1%/*}" - echo "$PWD/${1##*/}" - ) -} - -BFS="$(_realpath ./bfs)" -TESTS="$(_realpath ./tests)" -UNAME="$(uname)" - DEFAULT=yes POSIX= BSD= @@ -853,6 +843,24 @@ fi eval enabled_tests=($(printf '%q\n' "${enabled_tests[@]}" | sort -u)) +function _realpath() { + ( + set -P + cd "$(dirname -- "$1")" + echo "$PWD/$(basename -- "$1")" + ) +} + +ROOT="$(dirname -- "${BASH_SOURCE[0]}")" + +# Try to resolve the path to $BFS before we cd, while also supporting +# --bfs="./bfs -S ids" +BFS=(${BFS:-$ROOT/bfs}) +BFS[0]="$(_realpath "$(command -v "${BFS[0]}")")" +BFS="${BFS[*]}" + +TESTS="$(_realpath "$ROOT/tests")" + # The temporary directory that will hold our test data TMP="$(mktemp -d "${TMPDIR:-/tmp}"/bfs.XXXXXXXXXX)" chown "$(id -u):$(id -g)" "$TMP" |