95 lines
2.0 KiB
Bash
95 lines
2.0 KiB
Bash
|
#! /usr/bin/bash
|
||
|
|
||
|
#echo "-- " "$0" "$@" "(utils)"
|
||
|
|
||
|
function help() {
|
||
|
echo "$(basename "$0") SUBCOMMAND"
|
||
|
echo " test: run the test suite using this runner"
|
||
|
echo " deps-check: check for this runner's dependencies"
|
||
|
}
|
||
|
|
||
|
function depsCheck() {
|
||
|
# Explicit arguments, or $DEPENDENCIES
|
||
|
echo "-- Dependency checks for "$(basename "$0")""
|
||
|
if [ ! $# -eq 0 ]; then
|
||
|
DEPS=("$@")
|
||
|
else
|
||
|
DEPS=("${DEPENDENCIES[@]}")
|
||
|
fi
|
||
|
MISSING=()
|
||
|
for i in "${DEPS[@]}"; do
|
||
|
if ! command -v "$i" >/dev/null 2>&1; then
|
||
|
MISSING+=("$i")
|
||
|
fi
|
||
|
done
|
||
|
if [ ${#MISSING[@]} -gt 0 ]; then
|
||
|
echo "ERROR: missing dependencies: "${MISSING[@]}""
|
||
|
return 1
|
||
|
fi
|
||
|
}
|
||
|
|
||
|
function subcommand() {
|
||
|
SUBCOMMAND="${1:-test}"
|
||
|
#echo " Subcommand "$1" evaluated to "$SUBCOMMAND""
|
||
|
case "$SUBCOMMAND" in
|
||
|
"help"|"--help"|"-h")
|
||
|
help
|
||
|
return 1
|
||
|
;;
|
||
|
"deps-check")
|
||
|
depsCheck
|
||
|
return $?
|
||
|
;;
|
||
|
"test")
|
||
|
echo "Running tests from "$QBTNOX_DIR""
|
||
|
return $?
|
||
|
;;
|
||
|
*)
|
||
|
echo "$(basename "$0") ERROR: wrong subcommand "$SUBCOMMAND""
|
||
|
return 2
|
||
|
;;
|
||
|
esac
|
||
|
}
|
||
|
|
||
|
# $1 exit code
|
||
|
# $2 reason
|
||
|
# $3 orig dir to return to
|
||
|
function abortIfError() {
|
||
|
if [ ! $1 -eq 0 ]; then
|
||
|
cd "$ORIGDIR"
|
||
|
echo "$2"
|
||
|
#set +x
|
||
|
if [ $# -eq 3 ]; then
|
||
|
cd "$3"
|
||
|
fi
|
||
|
exit $1
|
||
|
fi
|
||
|
}
|
||
|
|
||
|
# finds a free TCP port
|
||
|
# https://stackoverflow.com/questions/28989069/how-to-find-a-free-tcp-port/45539101#45539101
|
||
|
function findFreePort() {
|
||
|
BASE_PORT=16998
|
||
|
INCREMENT=1
|
||
|
|
||
|
port=$BASE_PORT
|
||
|
isfree=$(netstat -taln | grep $port)
|
||
|
|
||
|
while [[ -n "$isfree" ]]; do
|
||
|
port=$[port+INCREMENT]
|
||
|
isfree=$(netstat -taln | grep $port)
|
||
|
done
|
||
|
|
||
|
echo "$port"
|
||
|
}
|
||
|
|
||
|
# runTests APIADDR
|
||
|
function runTests {
|
||
|
echo "Running tests at "$1""
|
||
|
if bats ../units/; then
|
||
|
echo "OK"
|
||
|
else
|
||
|
echo "FAIL"
|
||
|
fi
|
||
|
}
|