Files
gitea-custom/hooks/test/common/functions
Bart van der Braak 4c9690a353 Hooks: Rename directory and deny binary script (#20)
To make it more consistent with other hook scripts and we also rename `docker-compose.yml` to `compose.yml`

Reviewed-on: https://projects.blender.org/infrastructure/gitea-custom/pulls/20
2026-01-14 15:13:14 +01:00

46 lines
1.1 KiB
Plaintext

# Run single test provided via $1.
# Prints "ok" on success, "FAIL" on failure, and returns the appropriate status code.
run_test() {
local TEST_SCRIPT=$1
printf '%s' "Running $(basename "${TEST_SCRIPT}")... "
# Run test silently.
# Return 0 on success, 1 on failure.
if "${TEST_SCRIPT}" > /dev/null 2>&1; then
echo "ok"
return 0
else
echo "FAIL"
return 1
fi
}
# Run all tests in the given directory (specified as $1).
# All .sh tests are executed in sorted order.
# The script reports how many tests failed and exits with non-zero status if any did.
run_tests_in_directory() {
local DIR=$1
local failed=0
echo "== Running tests in directory $(basename "${DIR}") =="
# Iterate over all .sh files and run them one by one.
for test_script in $(ls "${DIR}" | sort); do
case "${test_script}" in
*.sh)
if ! run_test "${DIR}/${test_script}"; then
failed=$((failed + 1))
fi
;;
esac
done
# After running all tests, report overall result.
if [ "$failed" -ne 0 ]; then
echo "$failed test(s) failed."
exit 1
else
echo "All tests passed."
fi
}