Skip to content

Instantly share code, notes, and snippets.

@tehranian
Created February 16, 2026 05:47
Show Gist options
  • Select an option

  • Save tehranian/aa621dd08f63ebaa6fa9aaa6bb548a3e to your computer and use it in GitHub Desktop.

Select an option

Save tehranian/aa621dd08f63ebaa6fa9aaa6bb548a3e to your computer and use it in GitHub Desktop.
TDD test script for AqualinkD script/Makefile bug fixes — verifies 4 bugs before and after fix
#!/bin/bash
#
# Tests for known bugs in shell scripts and Makefile.
# Run from repo root: bash tests/test_script_bugs.sh
#
PASS=0
FAIL=0
assert_eq() {
local desc="$1" expected="$2" actual="$3"
if [[ "$expected" == "$actual" ]]; then
echo " PASS: $desc"
((PASS++))
else
echo " FAIL: $desc (expected '$expected', got '$actual')"
((FAIL++))
fi
}
# ================================================================
# Test 1: FROM_CURL should be initialized to $FALSE, not $FASE
# ================================================================
# Bug: Line 37 sets FROM_CURL=$FASE but FASE is undefined (typo).
# FROM_CURL ends up as empty string instead of 1.
test_from_curl_variable() {
echo "--- Test: FROM_CURL should be initialized to \$FALSE ---"
local result
result=$(bash << 'INNER'
eval "$(grep -E '^(TRUE|FALSE|FROM_CURL)=' release/remote_install.sh)"
if [[ "$FROM_CURL" == "$FALSE" ]]; then
echo "valid"
else
echo "invalid"
fi
INNER
)
assert_eq "FROM_CURL should equal \$FALSE (1)" "valid" "$result"
}
# ================================================================
# Test 2: check_can_upgrade else/elif control flow
# ================================================================
# Bug: "else [[ condition ]]" should be "elif [[ condition ]]; then".
# In bash, "else [[ ... ]]" is valid syntax but the test result is
# ignored — the else block ALWAYS executes, even when output is empty.
# This means logerr("") fires when there are no actual errors.
test_else_elif_logic() {
echo "--- Test: check_can_upgrade should NOT log errors when output is empty ---"
local result
result=$(bash << 'INNER'
TRUE=0
FALSE=1
logerr_called="no"
logerr() { logerr_called="yes"; }
# Simulate: no errors found (output=""), but no version either (REL_VERSION="")
# The function should silently fall through — NOT call logerr.
output=""
REL_VERSION=""
# This is the exact control flow from remote_install.sh lines 228-235.
eval "$(sed -n '228,235p' release/remote_install.sh)"
echo "$logerr_called"
INNER
)
assert_eq "logerr should NOT be called when output is empty" "no" "$result"
}
# ================================================================
# Test 3: Makefile $(shell ...) calls should have balanced parens
# ================================================================
# Bug: Line 227 has $(shell ... without a closing ).
test_makefile_shell_balanced() {
echo "--- Test: Makefile \$(shell ...) should have balanced parens ---"
local unbalanced=0
while IFS= read -r line; do
local opens closes
opens=$(echo "$line" | tr -cd '(' | wc -c | tr -d ' ')
closes=$(echo "$line" | tr -cd ')' | wc -c | tr -d ' ')
if [[ "$opens" -ne "$closes" ]]; then
echo " Unbalanced line: $line"
((unbalanced++))
fi
done < <(grep '$(shell' Makefile)
assert_eq "All \$(shell ...) lines should have balanced parens" "0" "$unbalanced"
}
# ================================================================
# Test 4: Makefile should not contain 'realease' typo
# ================================================================
test_makefile_no_typos() {
echo "--- Test: Makefile should not contain 'realease' typo ---"
local count
count=$(grep -c 'realease' Makefile || true)
assert_eq "No 'realease' typos in Makefile" "0" "$count"
}
# ================================================================
# Run all tests
# ================================================================
echo "Running script bug tests..."
echo ""
test_from_curl_variable
test_else_elif_logic
test_makefile_shell_balanced
test_makefile_no_typos
echo ""
echo "Results: $PASS passed, $FAIL failed"
if [[ $FAIL -gt 0 ]]; then
exit 1
else
exit 0
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment