phoebus_os/installer/tests/lib.sh
Phoebus 38214ea9e7 chore: import Phoebus OS installer and Rust migration
Initial public import of the proven Bash installer (installer/) and the production Rust workspace (installer-rs/). The reference ISO, build output and local agent transcripts are gitignored.

Verified: installer/tests/run_tests.sh and cargo test --workspace both pass.
2026-09-20 02:07:33 -07:00

81 lines
2.3 KiB
Bash

#!/usr/bin/env bash
# shellcheck shell=bash
#
# Minimal test harness. No external test framework is required (the live image
# has none, and the backend must be testable on any machine).
TESTS_RUN=0
TESTS_FAILED=0
TEST_NAME="unknown"
phoebus_test_setup() {
# shellcheck source=/dev/null
PHOEBUS_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
export PHOEBUS_ROOT
STATE_DIR="$(mktemp -d "${TMPDIR:-/tmp}/phoebus-test.XXXXXX")"
export STATE_DIR
PHOEBUS_LOG_FILE="$STATE_DIR/test.log"
export PHOEBUS_LOG_FILE
: >"$PHOEBUS_LOG_FILE"
PHOEBUS_LOG_ECHO=no
export PHOEBUS_LOG_ECHO
local lib
for lib in state logging confirm hardware disks validation plan pkgpolicy \
portage partitions filesystem encryption btrfs network kernel \
boot users desktop opencode ai install; do
# shellcheck source=/dev/null
source "$PHOEBUS_ROOT/lib/$lib.sh"
done
config_load_defaults "$PHOEBUS_ROOT/config/defaults.conf"
}
_assert() {
local ok="$1" message="$2"
TESTS_RUN=$((TESTS_RUN + 1))
if [[ "$ok" == "1" ]]; then
printf ' ok %s\n' "$message"
else
TESTS_FAILED=$((TESTS_FAILED + 1))
printf ' FAIL %s\n' "$message"
fi
}
assert_eq() {
local expected="$1" actual="$2" message="${3:-equal}"
if [[ "$expected" == "$actual" ]]; then _assert 1 "$message"; else
_assert 0 "$message (expected '$expected', got '$actual')"; fi
}
assert_neq() {
local a="$1" b="$2" message="${3:-not equal}"
if [[ "$a" != "$b" ]]; then _assert 1 "$message"; else
_assert 0 "$message (both '$a')"; fi
}
assert_contains() {
local haystack="$1" needle="$2" message="${3:-contains}"
if [[ "$haystack" == *"$needle"* ]]; then _assert 1 "$message"; else
_assert 0 "$message (missing '$needle')"; fi
}
assert_not_contains() {
local haystack="$1" needle="$2" message="${3:-not contains}"
if [[ "$haystack" != *"$needle"* ]]; then _assert 1 "$message"; else
_assert 0 "$message (unexpectedly found '$needle')"; fi
}
assert_success() {
local message="$1"; shift
if "$@" >/dev/null 2>&1; then _assert 1 "$message"; else _assert 0 "$message"; fi
}
assert_failure() {
local message="$1"; shift
if "$@" >/dev/null 2>&1; then _assert 0 "$message"; else _assert 1 "$message"; fi
}
phoebus_test_report() {
printf '\n%s: %d run, %d failed\n' "$TEST_NAME" "$TESTS_RUN" "$TESTS_FAILED"
[[ "$TESTS_FAILED" -eq 0 ]]
}