#!/bin/bash set -euo pipefail shopt -s inherit_errexit usage() { cat <&2 echo "Try '$(basename "$0") --help' for more information." >&2 exit 1 ;; *) ONLY_TESTS+=("$1") shift ;; esac done # Find and run test scripts if [[ ${#ONLY_TESTS[@]} -gt 0 ]]; then tests=() for name in "${ONLY_TESTS[@]}"; do testfile="test-${name}.sh" if [[ ! -f "${testfile}" ]]; then echo "Error: Test not found: ${testfile}" >&2 exit 1 fi tests+=("${testfile}") done else tests=( test-*.sh ) fi total=${#tests[@]} passed=0 failed=0 failed_tests=() echo "" echo "Running ${total} e2e test(s)..." echo "" for test in "${tests[@]}"; do echo "=== Running ${test} ===" test_name="${test%.sh}" # Create per-test output directory and export for the test script test_output_dir="${output_dir}/${test_name}" mkdir -p "${test_output_dir}" export OUTPUT_DIR="${test_output_dir}" TMPDIR=$(mktemp -d) export TMPDIR abstest=$(realpath "${test}") if [[ ${VERBOSE} == true ]]; then exec 3>&2 else exec 3>"${test_output_dir}/output.log" fi if (cd "${TMPDIR}" && bash "${abstest}") >&3 2>&3; then echo "=== PASSED: ${test} ===" passed=$((passed+1)) else echo "=== FAILED: ${test} ===" failed=$((failed+1)) failed_tests+=("${test}") if [[ ${VERBOSE} == false ]]; then echo "--- Test output ---" cat "${test_output_dir}/output.log" echo "--- End output ---" fi fi exec 3>&- rm -rf "${TMPDIR}" unset TMPDIR echo "" done echo "========================================" echo "Results: ${passed} passed, ${failed} failed" echo "========================================" if [[ "${failed}" -gt 0 ]]; then echo "Failed tests:" for t in "${failed_tests[@]}"; do echo " - ${t}" done exit 1 fi