74 lines
2.2 KiB
Bash
Executable File
74 lines
2.2 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
root_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
|
|
tmp_dir="$(mktemp -d)"
|
|
trap 'rm -rf "$tmp_dir"' EXIT
|
|
project_dir="$tmp_dir/project"
|
|
cp -a "$root_dir" "$project_dir"
|
|
rm -rf "$project_dir/.git" "$project_dir/.godot" "$project_dir/artifacts"
|
|
|
|
fake_godot="$tmp_dir/godot4"
|
|
cat > "$fake_godot" <<'FAKE_GODOT'
|
|
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
printf '%s\n' "$*" >> "$FAKE_GODOT_LOG"
|
|
if [[ " $* " == *" --import "* ]]; then
|
|
printf '%s\n' "fake import output" >&2
|
|
exit "${FAKE_IMPORT_STATUS:-0}"
|
|
fi
|
|
if [[ " $* " == *" --capture "* || " $* " == *" --capture-exit "* ]]; then
|
|
if [[ " $* " == *" --capture-exit "* ]]; then
|
|
capture_name="visual-check-exit.png"
|
|
else
|
|
capture_name="visual-check.png"
|
|
fi
|
|
python3 - "$capture_name" <<'PY'
|
|
import os
|
|
import struct
|
|
import sys
|
|
|
|
os.makedirs("artifacts", exist_ok=True)
|
|
with open(f"artifacts/{sys.argv[1]}", "wb") as capture:
|
|
capture.write(b"\x89PNG\r\n\x1a\n")
|
|
capture.write(struct.pack(">I4sII5B", 13, b"IHDR", 1280, 720, 8, 2, 0, 0, 0))
|
|
PY
|
|
fi
|
|
exit 0
|
|
FAKE_GODOT
|
|
chmod +x "$fake_godot"
|
|
|
|
assert_import_precedes_run() {
|
|
local runner="$1"
|
|
local log="$tmp_dir/${runner}.log"
|
|
FAKE_GODOT_LOG="$log" GODOT_BIN="$fake_godot" DISPLAY=:99 "$project_dir/scripts/$runner"
|
|
local first_line
|
|
first_line="$(head -n 1 "$log")"
|
|
[[ "$first_line" == *"--headless"* && "$first_line" == *"--import"* ]] || {
|
|
echo "$runner did not invoke headless import before its runner command" >&2
|
|
return 1
|
|
}
|
|
[[ "$(wc -l < "$log")" -ge 2 ]] || {
|
|
echo "$runner did not invoke its runner command after importing" >&2
|
|
return 1
|
|
}
|
|
}
|
|
|
|
assert_import_precedes_run test-unit.sh
|
|
assert_import_precedes_run test-e2e.sh
|
|
assert_import_precedes_run run-visual-check.sh
|
|
|
|
failure_log="$tmp_dir/import-failure.log"
|
|
set +e
|
|
failure_output="$(FAKE_GODOT_LOG="$failure_log" FAKE_IMPORT_STATUS=42 GODOT_BIN="$fake_godot" "$project_dir/scripts/test-unit.sh" 2>&1)"
|
|
failure_status=$?
|
|
set -e
|
|
[[ "$failure_status" -eq 42 ]] || {
|
|
echo "test-unit.sh did not return the import failure status" >&2
|
|
exit 1
|
|
}
|
|
[[ "$failure_output" == *"fake import output"* ]] || {
|
|
echo "test-unit.sh did not preserve import error output" >&2
|
|
exit 1
|
|
}
|