From 09fd2a82ded3cf97f91f30fa1ed4937b60fc9998 Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Tue, 1 Feb 2022 13:27:46 -0500 Subject: tests: Allow tests.sh to be invoked from any directory This also resolves the path passed to --bfs early, so --bfs=./bfs now works. --- Makefile | 2 +- tests.sh | 34 +++++++++++++++++++++------------- 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/Makefile b/Makefile index 6b0ed4d..497bc70 100644 --- a/Makefile +++ b/Makefile @@ -218,7 +218,7 @@ $(FLAG_GOALS): $(FLAG_PREREQS) check: $(CHECKS) $(STRATEGY_CHECKS): check-%: bfs tests/mksock - ./tests.sh --bfs="$(CURDIR)/bfs -S $*" $(TEST_FLAGS) + ./tests.sh --bfs="./bfs -S $*" $(TEST_FLAGS) check-trie check-xtimegm: check-%: tests/% $< diff --git a/tests.sh b/tests.sh index b9e21a9..4ac9763 100755 --- a/tests.sh +++ b/tests.sh @@ -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" -- cgit v1.2.3