test: lmsensors extend unit tests, vendored framework [#769]

Moved from KNEL/PFVCluster tests/unit with repo-relative paths.

https://projects.knownelement.com/issues/769#note-4152
This commit is contained in:
2026-09-03 21:44:57 -05:00
parent 51a1c9deee
commit 7ed1017df2
22 changed files with 1108 additions and 0 deletions
+64
View File
@@ -0,0 +1,64 @@
#!/bin/bash
# Unit tests for lmsensors-extend.sh -n numeric mode [#618]
set -euo pipefail
PROJECT_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
SCRIPT="$PROJECT_ROOT/sensors/temper/lmsensors-extend.sh"
failed=0
if [[ -f "$SCRIPT" ]] && (source "$SCRIPT"); then
echo "✅ script exists + sources cleanly"
else
echo "❌ script missing or fails to source: $SCRIPT"
exit 1
fi
# shellcheck disable=SC1091
source "$SCRIPT"
# numeric_pick: TEMPer external > TEMPer internal > first native/sysfs value
test_numeric_prefers_external() {
if [[ "$(numeric_pick "22.5" "18.2" "" )" == "18.2" ]]; then
echo "✅ numeric_pick prefers external probe"
else
echo "❌ numeric_pick external preference broken"
((++failed))
fi
}
test_numeric_falls_back_internal() {
if [[ "$(numeric_pick "22.5" "" "")" == "22.5" ]]; then
echo "✅ numeric_pick falls back to internal"
else
echo "❌ numeric_pick internal fallback broken"
((++failed))
fi
}
test_numeric_uses_first_line_value() {
if [[ "$(numeric_pick "" "" "temp1: +27.5°C (high = +84.0°C)")" == "27.5" ]]; then
echo "✅ numeric_pick parses first native temp"
else
echo "❌ numeric_pick native parse broken: got '$(numeric_pick "" "" "+27.5°C")'"
((++failed))
fi
}
test_numeric_empty_is_error() {
if numeric_pick "" "" "" >/dev/null 2>&1; then
echo "❌ numeric_pick should fail on no data"
((++failed))
else
echo "✅ numeric_pick errors on no data"
fi
}
test_numeric_prefers_external
test_numeric_falls_back_internal
test_numeric_uses_first_line_value
test_numeric_empty_is_error
if ((failed > 0)); then
echo "$failed numeric-mode test(s) failed"
exit 1
fi
echo "✅ all numeric-mode tests passed"