aboutsummaryrefslogtreecommitdiff
path: root/scripts/testing/lib/run-common.sh
diff options
context:
space:
mode:
authorCraig Jennings <c@cjennings.net>2026-07-25 15:00:44 -0500
committerCraig Jennings <c@cjennings.net>2026-07-25 15:00:44 -0500
commitd52da959bc416e09bc0f3e54994563bd80e19c64 (patch)
treeadaf2ce086e87c548c695e5b4a82eb63f7c926c8 /scripts/testing/lib/run-common.sh
parentd25711a61172ffb7b622a6a834ed17fdf52a54de (diff)
downloadarchsetup-d52da959bc416e09bc0f3e54994563bd80e19c64.tar.gz
archsetup-d52da959bc416e09bc0f3e54994563bd80e19c64.zip
refactor(test): share runner and scenario contracts
Diffstat (limited to 'scripts/testing/lib/run-common.sh')
-rw-r--r--scripts/testing/lib/run-common.sh61
1 files changed, 61 insertions, 0 deletions
diff --git a/scripts/testing/lib/run-common.sh b/scripts/testing/lib/run-common.sh
new file mode 100644
index 0000000..b5696db
--- /dev/null
+++ b/scripts/testing/lib/run-common.sh
@@ -0,0 +1,61 @@
+#!/bin/bash
+# Transport-independent polling and reporting for archsetup test runners.
+
+archsetup_process_running() { # <transport-function>
+ local transport="$1"
+ "$transport" "pgrep -f '[b]ash archsetup' > /dev/null" 2>/dev/null
+}
+
+wait_for_archsetup() { # <transport> <max-polls> <seconds> <progress-every> [callback]
+ local transport="$1" max_polls="$2" poll_seconds="$3"
+ local progress_every="$4" progress_callback="${5:-}"
+ ARCHSETUP_POLL_COUNT=0
+
+ while [ "$ARCHSETUP_POLL_COUNT" -lt "$max_polls" ]; do
+ archsetup_process_running "$transport" || return 0
+ sleep "$poll_seconds"
+ ARCHSETUP_POLL_COUNT=$((ARCHSETUP_POLL_COUNT + 1))
+ if [ "$progress_every" -gt 0 ] \
+ && [ $((ARCHSETUP_POLL_COUNT % progress_every)) -eq 0 ] \
+ && [ -n "$progress_callback" ]; then
+ "$progress_callback" "$ARCHSETUP_POLL_COUNT"
+ fi
+ done
+ return 124
+}
+
+write_archsetup_test_report() {
+ local file="$1" title="$2" test_id="$3" method="$4" context="$5"
+ local completed="$6" passed="$7" count_passed="$8" count_failed="$9"
+ shift 9
+ local count_warnings="$1" artifacts="$2" validation="FAILED"
+ [ "$passed" = "true" ] && validation="PASSED"
+
+ {
+ echo "========================================"
+ echo "$title"
+ echo "========================================"
+ echo
+ echo "Test ID: $test_id"
+ echo "Date: $(date +'%Y-%m-%d %H:%M:%S')"
+ echo "Test Method: $method"
+ if [ -n "$context" ]; then
+ echo
+ printf '%s\n' "$context"
+ fi
+ echo
+ echo "Results:"
+ echo " ArchSetup Completed: $completed (completion marker, not the installer's exit code)"
+ echo " Validation: $validation"
+ echo
+ echo "Validation Summary:"
+ echo " Passed: $count_passed"
+ echo " Failed: $count_failed"
+ echo " Warnings: $count_warnings"
+ if [ -n "$artifacts" ]; then
+ echo
+ printf '%s\n' "$artifacts"
+ fi
+ echo
+ } > "$file"
+}