specs/forgecheck/test_tests.sh

73 lines
2.3 KiB
Bash
Executable File

#! /usr/bin/env bash
# If you give first argument it will be a path to already cloned whck
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 spec
testOrError "forgecheck/test.sh with implicit ../bin/cli" forgecheck/test.sh
testOrError "forgecheck/test.sh with explicit result from ../bin/cli" forgecheck/test.sh "$(../bin/cli)"
testOrError "test.sh called from spec submodule" ../bin/test.sh
cd forgecheck
testOrError "bin/test.sh from spec/forgecheck folder" ../../bin/test.sh
testOrError "forgecheck/test.sh from spec/forgecheck folder with implicit ../../bin/cli" ./test.sh
testOrError "forgecheck/test.sh from spec/forgecheck folder with explicit result from ../../bin.cli" ./test.sh "$(../../bin/cli)"
cd tests
testOrError "bin/test.sh from spec/forgecheck/tests" ../../../bin/test.sh
testOrError "forgecheck/test.sh from spec/forgecheck/tests" ../test.sh
testOrError "forgecheck/test.sh from spec/forgehook/tests folder with explicit result from ../../../bin/cli" ../test.sh "$(../../../bin/cli)"
}
ORIGDIR="$(pwd)"
if [ -z "$1" ]; then
# When no explicit dir, try ./ first, otherwise make a temporary dir
if [ -x bin/cli ]; then
testVariousScenarios
elif [ -x ../bin/cli ]; then
cd ..
testVariousScenarios
elif [ -x ../../bin/cli ]; then
cd ../..
testVariousScenarios
elif [ -x whck/bin/cli ]; then
cd whck
testVariousScenarios
elif [ -x ../whck/bin/cli ]; then
cd ../whck
testVariousScenarios
else
TMPDIR="$(mktemp -d)"
cd "$TMPDIR"
git clone --recursive https://tildegit.org/forge/whck
cd whck
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"