qbt-rs/tests/test.sh

95 lines
2.7 KiB
Bash
Executable File

#! /usr/bin/env bash
# LET TEST RUNNERS KNOW WE ALREADY PERFORM CHECKS
export TESTRUNNER="YEAH"
export QBTNOX_DIR="$(mktemp -d)"
ORIGDIR="$(pwd)"
cd "$(dirname "$0")"
help() {
echo "test.sh RUNNER"
echo " Run the test suite. Requires bats and qBittorrent as dependencies. Dependencies are found by one of the following runners:"
echo " - local: the local system's \$PATH"
echo " - nix: nixos.org package repositories (requires working nix setup)"
echo " - docker: Debian stable base image + APT packages (requires working docker setup/daemon)"
echo " (default) if no explicit runner is requested, they are tried in order."
}
# FIND THE QBT BINARY
cd ..
BIN_NAME="$(grep -Po '^name = (.*)' Cargo.toml | sed 's/[" ]//g' | sed 's/name=//')"
if [ -f target/release/$BIN_NAME ]; then
cargo build --release
export BIN_PATH="$(realpath target/release/"$BIN_NAME")"
else
cargo build
export BIN_PATH="$(realpath target/debug/"$BIN_NAME")"
fi
echo "Using build $BIN_PATH"
cd tests
SUCCESS=0
RUNNER="${1:-default}"
shift
case "$RUNNER" in
"--help"|"-h"|"help")
help
;;
# "docker")
# echo "Running tests under: docker ("$QBTNOX_DIR")"
# if ./runners/docker.sh deps-check; then
# ./runners/docker.sh test
# SUCCESS=$?
# else
# SUCCESS=1
# fi
# ;;
"nix")
echo "Running tests under: nix ("$QBTNOX_DIR")"
if ./runners/nix.sh deps-check; then
./runners/nix.sh test
SUCCESS=$?
else
SUCCESS=1
fi
;;
"local")
echo "Running tests under: local ("$QBTNOX_DIR")"
if ./runners/.local.sh deps-check; then
./runners/local.sh test
SUCCESS=$?
else
SUCCESS=1
fi
;;
*)
echo "Autodiscovery for runner"
if ./runners/local.sh deps-check; then
echo "Running tests under: local ("$QBTNOX_DIR")"
./runners/local.sh test
SUCCESS=$?
elif ./runners/nix.sh deps-check; then
echo "Running tests under: nix ("$QBTNOX_DIR")"
./runners/nix.sh test
SUCCESS=$?
# elif ./runners/docker.sh deps-check; then
# echo "Running tests under: docker"
# ./runners/docker.sh test
# SUCCESS=$?
else
echo "Failed to find a test runner! Please setup qbittorrent-nox and bats on your system, or alternatively setup the nix package manager or the docker container manager to install them dynamically."
SUCCESS=1
fi
;;
esac
if [ -d "$QBTNOX_DIR" ]; then
rm -R "$QBTNOX_DIR"
fi
cd "$ORIGDIR"
exit $SUCCESS