warpgate/tests/run-all.sh
grabbit 46e592c3a4 Flatten project structure: move warpgate/ contents to repo root
Single-crate project doesn't need a subdirectory. Moves Cargo.toml,
src/, templates/ to root for standard Rust project layout. Updates
.gitignore and test harness binary paths accordingly.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-18 11:25:15 +08:00

152 lines
3.8 KiB
Bash
Executable File

#!/usr/bin/env bash
# Warpgate Integration Test Runner
#
# Runs all test scripts across all categories and outputs TAP format results.
#
# Usage:
# sudo ./tests/run-all.sh # run all tests
# sudo WARPGATE_TEST_LONG=1 ./tests/run-all.sh # include slow tests
# sudo ./tests/run-all.sh 05-cache # run only one category
#
# Environment:
# WARPGATE_BIN Path to warpgate binary (default: auto-detect)
# WARPGATE_TEST_DIR Temp directory for tests (default: /tmp/warpgate-test)
# WARPGATE_TEST_LONG Set to 1 to run slow tests
# WARPGATE_TEST_BTRFS Path to btrfs block device for fs tests
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
PROJECT_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
# Auto-detect warpgate binary
if [[ -z "${WARPGATE_BIN:-}" ]]; then
if [[ -x "$PROJECT_ROOT/target/release/warpgate" ]]; then
export WARPGATE_BIN="$PROJECT_ROOT/target/release/warpgate"
elif [[ -x "$PROJECT_ROOT/target/debug/warpgate" ]]; then
export WARPGATE_BIN="$PROJECT_ROOT/target/debug/warpgate"
else
echo "ERROR: warpgate binary not found. Build with: cargo build --release" >&2
echo " Or set WARPGATE_BIN=/path/to/warpgate" >&2
exit 1
fi
fi
echo "# Warpgate Integration Test Suite"
echo "# Binary: $WARPGATE_BIN"
echo "# Date: $(date -Iseconds)"
echo "# User: $(whoami)"
echo "#"
# Ensure test temp directory exists
mkdir -p "${WARPGATE_TEST_DIR:-/tmp/warpgate-test}"
# Test categories in execution order
CATEGORIES=(
01-config
02-lifecycle
03-signal
04-supervision
05-cache
06-writeback
07-network
08-crash-recovery
09-cli
)
# Filter to specific category if requested
if [[ -n "${1:-}" ]]; then
found=0
for cat in "${CATEGORIES[@]}"; do
if [[ "$cat" == "$1" ]]; then
found=1
break
fi
done
if [[ $found -eq 0 ]]; then
echo "ERROR: unknown category: $1" >&2
echo "Available: ${CATEGORIES[*]}" >&2
exit 1
fi
CATEGORIES=("$1")
fi
# Collect all test scripts
ALL_TESTS=()
for category in "${CATEGORIES[@]}"; do
category_dir="$SCRIPT_DIR/$category"
if [[ ! -d "$category_dir" ]]; then
continue
fi
while IFS= read -r -d '' test_script; do
ALL_TESTS+=("$test_script")
done < <(find "$category_dir" -name 'test-*.sh' -type f -print0 | sort -z)
done
total=${#ALL_TESTS[@]}
if [[ $total -eq 0 ]]; then
echo "No tests found."
exit 0
fi
# TAP header
echo "1..$total"
passed=0
failed=0
skipped=0
test_num=0
for test_script in "${ALL_TESTS[@]}"; do
test_num=$((test_num + 1))
# Extract category and test name
rel_path="${test_script#$SCRIPT_DIR/}"
test_name="${rel_path%.sh}"
# Run the test, capturing output and exit code
test_output=""
test_exit=0
test_start=$(date +%s)
test_output=$(bash "$test_script" 2>&1) || test_exit=$?
test_end=$(date +%s)
test_duration=$((test_end - test_start))
if echo "$test_output" | grep -qi "^SKIP"; then
echo "ok $test_num - $test_name # SKIP ${test_duration}s"
skipped=$((skipped + 1))
elif [[ $test_exit -eq 0 ]]; then
echo "ok $test_num - $test_name # ${test_duration}s"
passed=$((passed + 1))
else
echo "not ok $test_num - $test_name # ${test_duration}s"
failed=$((failed + 1))
# Print failure details as TAP diagnostics
while IFS= read -r line; do
echo " # $line"
done <<< "$test_output"
fi
done
# Summary
echo "#"
echo "# =============================="
echo "# Test Summary"
echo "# =============================="
echo "# Total: $total"
echo "# Passed: $passed"
echo "# Failed: $failed"
echo "# Skipped: $skipped"
echo "#"
if [[ $failed -gt 0 ]]; then
echo "# RESULT: FAIL"
exit 1
else
echo "# RESULT: PASS"
exit 0
fi