Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions tests/network/test-lib-self-test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env bash
# Regression checks for test assertions: matching error output must not pass.
set -euo pipefail
cd "$(dirname "$0")"
source ./test-lib.sh

LOG_DIR=$(mktemp -d)
trap 'test_cleanup; rm -rf "$LOG_DIR"' EXIT
CURRENT_LOG="$LOG_DIR/assertions.log"
: > "$CURRENT_LOG"

assert_output_contains "printf 'ready\\n'" ready "successful output matches"
if assert_output_contains "printf 'ready\\n'; exit 7" ready "failed command must not match"; then
echo 'assert_output_contains accepted a failed command' >&2
exit 1
fi
if assert_output_contains "printf 'not-ready\\n'" '^ready$' "missing pattern must not match"; then
echo 'assert_output_contains accepted a missing pattern' >&2
exit 1
fi
[ "$TESTS_RUN" -eq 3 ] && [ "$TESTS_PASSED" -eq 1 ] && [ "$TESTS_FAILED" -eq 2 ]
echo 'network assertion self-test passed'
10 changes: 6 additions & 4 deletions tests/network/test-lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -188,18 +188,20 @@ assert_output_contains() {
echo " Expected pattern: $pattern" >> "$CURRENT_LOG"

local output
output=$(eval "$cmd" 2>&1)
local command_status=0
output=$(eval "$cmd" 2>&1) || command_status=$?
echo " Exit status: $command_status" >> "$CURRENT_LOG"
echo " Output: $output" >> "$CURRENT_LOG"
if echo "$output" | grep -q "$pattern"; then

if [ "$command_status" -eq 0 ] && grep -q "$pattern" <<< "$output"; then
TESTS_PASSED=$((TESTS_PASSED + 1))
echo -e " ${GREEN}✓${NC} $msg"
echo " Result: PASS" >> "$CURRENT_LOG"
return 0
else
TESTS_FAILED=$((TESTS_FAILED + 1))
echo -e " ${RED}✗${NC} $msg"
echo " Result: FAIL (pattern not found)" >> "$CURRENT_LOG"
echo " Result: FAIL (exit status $command_status or pattern not found)" >> "$CURRENT_LOG"
return 1
fi
}
Expand Down
Loading