mirror of
https://github.com/oSoWoSo/DistroHopper.git
synced 2026-06-14 17:36:40 +00:00
qget: - Add QGET_TEST_MODE guard so the script can be sourced for unit testing without executing the main logic dh: - Auto-detect getter tool (qget preferred, quickget fallback) in set_variables(); export as GETTER - Add getter_list_os() wrapper using GETTER --list for portable OS enumeration - Replace hard-coded quickget calls with $GETTER in renew_supported_vms(), renew_ready_vms(), and execmd strings - Fix releases/editions/description parsing (sed instead of cut -f2 which fails on colon-space separators) - Add DH_TEST_MODE guard to prevent execution when sourcing for tests action: - Auto-detect getter tool at startup; export as GETTER - Add --qget / -q and --quickget / -Q flags to override detection tests/: - tests/lib.sh: shared assert helpers (assert_eq, assert_ne, assert_match, assert_cmd, assert_fn_exists) with pass/fail counting - tests/test_dh.sh: 31 unit tests covering set_variables, GETTER, getter_list_os, root_check, wayland_check, and all required function definitions - tests/test_qget.sh: 23 unit tests covering os_support, test_result formatting, is_valid_language, check_hash, and all utility functions - tests/test_action_files.sh: 784 structural tests verifying every action file has OSNAME, PRETTY, HOMEPAGE (valid URL), DESCRIPTION, releases_() and get_() functions - tests/run_tests.sh: top-level runner executing all three suites https://claude.ai/code/session_01M2UXTtQwzcGCNRnFiP2efQ
81 lines
1.6 KiB
Bash
Executable file
81 lines
1.6 KiB
Bash
Executable file
#!/usr/bin/env bash
|
|
# Shared test helpers for DistroHopper test suite
|
|
|
|
PASS=0
|
|
FAIL=0
|
|
declare -a FAIL_MSGS=()
|
|
|
|
_green='\033[0;32m'
|
|
_red='\033[0;31m'
|
|
_nc='\033[0m'
|
|
|
|
pass() {
|
|
echo -e " ${_green}✓${_nc} $1"
|
|
((PASS++))
|
|
}
|
|
|
|
fail() {
|
|
echo -e " ${_red}✗${_nc} $1"
|
|
((FAIL++))
|
|
FAIL_MSGS+=("$1")
|
|
}
|
|
|
|
assert_eq() {
|
|
local desc="$1" expected="$2" actual="$3"
|
|
if [ "$expected" = "$actual" ]; then
|
|
pass "$desc"
|
|
else
|
|
fail "$desc (expected='$expected', got='$actual')"
|
|
fi
|
|
}
|
|
|
|
assert_ne() {
|
|
local desc="$1" notexpected="$2" actual="$3"
|
|
if [ "$notexpected" != "$actual" ]; then
|
|
pass "$desc"
|
|
else
|
|
fail "$desc (should not be '$notexpected')"
|
|
fi
|
|
}
|
|
|
|
assert_match() {
|
|
local desc="$1" pattern="$2" actual="$3"
|
|
if [[ "$actual" =~ $pattern ]]; then
|
|
pass "$desc"
|
|
else
|
|
fail "$desc (pattern='$pattern' not matched in: '$actual')"
|
|
fi
|
|
}
|
|
|
|
assert_cmd() {
|
|
local desc="$1"
|
|
shift
|
|
if "$@" >/dev/null 2>&1; then
|
|
pass "$desc"
|
|
else
|
|
fail "$desc (command failed: $*)"
|
|
fi
|
|
}
|
|
|
|
assert_fn_exists() {
|
|
local desc="$1" fn="$2"
|
|
if declare -f "$fn" >/dev/null 2>&1; then
|
|
pass "$desc"
|
|
else
|
|
fail "$desc (function '$fn' not defined)"
|
|
fi
|
|
}
|
|
|
|
summary() {
|
|
local total=$((PASS + FAIL))
|
|
echo ""
|
|
if [ $FAIL -eq 0 ]; then
|
|
echo -e "${_green}All $total tests passed${_nc}"
|
|
else
|
|
echo -e "${_red}$FAIL / $total tests failed:${_nc}"
|
|
for msg in "${FAIL_MSGS[@]}"; do
|
|
echo " - $msg"
|
|
done
|
|
fi
|
|
[ $FAIL -eq 0 ]
|
|
}
|