specs/forgehook/test_tests.sh

69 lines
2.2 KiB
Bash
Executable File

#! /usr/bin/env bash
# If you give first argument it will be a path to already cloned endpoint
function testOrError() {
message="$1"
shift
bin="$1"
shift
output="$("$bin" "$@" 2>&1)"
if [ ! $? -eq 0 ]; then
echo "FAILURE: "$message""
echo "$output" | sed 's/^/ /g'
return 1
fi
echo "SUCCESS: "$message""
}
# TODO: save exit codes of various tests so we can know how many failed
function testVariousScenarios() {
echo "Running various tests from "$(pwd)""
testOrError "bin/test.sh running from repo" bin/test.sh
cd specs
testOrError "forgehook/test.sh with implicit ../bin/server" forgehook/test.sh
testOrError "forgehook/test.sh with explicit result from ../bin/server" forgehook/test.sh "$(../bin/server)"
testOrError "test.sh called from specs submodule" ../bin/test.sh
cd forgehook
testOrError "bin/test.sh from specs/forgehook folder" ../../bin/test.sh
testOrError "forgehook/test.sh from specs/forgehook folder with implicit ../../bin/server" ./test.sh
testOrError "forgehook/test.sh from specs/forgehook folder with explicit result from ../../bin/server" ./test.sh "$(../../bin/server)"
cd tests
testOrError "bin/test.sh from specs/forgehook/tests" ../../../bin/test.sh
testOrError "forgehook/test.sh from specs/forgehook/tests" ../test.sh
testOrError "forgehook/test.sh from specs/forgehook/tests folder with explicit result from ../../../bin/server" ../test.sh "$(../../../bin/server)"
}
ORIGDIR="$(pwd)"
if [ -z "$1" ]; then
# When no explicit dir, try ./ first, otherwise ../, otherwise make a temporary dir
if [ -x bin/server ]; then
testVariousScenarios
elif [ -x ../bin/server ]; then
cd ..
testVariousScenarios
elif [ -x ../../bin/server ]; then
cd ../..
testVariousScenarios
else
TMPDIR="$(mktemp -d)"
cd "$TMPDIR"
git clone --recursive https://tildegit.org/forge/endpoints.php
cd endpoints.php
testVariousScenarios
cd "$ORIGDIR"
rm -rf "$TMPDIR"
fi
else
if [ ! -d "$1" ]; then
echo "Wrong repo: "$1""
exit 1
fi
cd "$1"
testVariousScenarios
fi
cd "$ORIGDIR"