Test a tool against faulty adapters
Build portable assertions that reject incorrect output and unsuccessful status.
Test the promise, not the implementation
The classification helper promises six observable behaviours. A useful test calls that public function with representative inputs and compares what comes back. It does not inspect the helper's source or require a particular case statement, so a different correct implementation can pass.
An assertion needs both the output and exit status. A function that prints the expected word and then fails has not fulfilled the contract. Capture it in a conditional, save the status and count the assertion as passed only when both observations match. Keep running after a failed assertion to provide a complete summary.
Include uncertainty boundaries
Success-only tests can miss the most consequential mistake: turning a timeout into evidence of a safe restriction. Include open under both policies, refusal under both policies, and inconclusive or missing observations. The automatic checker swaps in deliberately faulty helpers to prove that your test harness notices these errors.
The harness's text summary is for the learner. It cannot award course completion: the browser's trusted checker evaluates exit status and expected output independently. The fixtures also include a helper that prints a correct answer but returns a failure, ensuring the harness does not trust appearance alone. This same boundary-testing habit applies to a future real network adapter, while keeping tests offline and deterministic.
source lib/classify.sh
if value=$(classify timed_out yes);then printf 'result=%s\n' "$value";fi
Put it into practice.
Source lib/classify.sh and run exactly six checks: (open,yes)->expected_open; (open,no)->unexpected_open; (refused,yes)->unavailable; (refused,no)->expected_refusal; (timed_out,yes)->unknown; (missing,no)->unknown. A check passes only when classify exits 0 and its output, after command substitution removes trailing newlines, exactly matches. Run all six even after failure. Print tests=6, passed=N, failed=N on separate lines. Exit 0 only if all six pass, otherwise 1. Do not overwrite the supplied helper or let its printed output determine course completion.
See an explained solution
source lib/classify.sh
passed=0;failed=0
assert_result(){
local actual status
if actual=$(classify "$1" "$2");then status=0;else status=$?;fi
if [ "$status" -eq 0 ] && [ "$actual" = "$3" ];then passed=$((passed+1));else failed=$((failed+1));fi
}
assert_result open yes expected_open
assert_result open no unexpected_open
assert_result refused yes unavailable
assert_result refused no expected_refusal
assert_result timed_out yes unknown
assert_result missing no unknown
printf 'tests=6\npassed=%s\nfailed=%s\n' "$passed" "$failed"
[ "$failed" -eq 0 ]
The harness measures behaviour rather than source structure. Both status and exact output matter, all assertions run, and uncertainty cases detect an adapter that would otherwise turn incomplete evidence into a misleading assessment.