fix(test): fail a run_test line that names no function #88

Merged
claudiomaradonna merged 1 commit from fix/harness-missing-test into master 2026-11-23 12:12:57 +01:00
Collaborator

Why

Every test file registers its tests with run_test <name> from the
shared harness, tests/harness.sh. A line left behind by a rename, or
a misspelled one, named a function that does not exist: the harness
printed the shell's command not found, then ok, and the suite
passed while the test it meant never ran. This showed during the work
on #86, when a renamed test kept its old run_test line.

What changed

run_test now fails a name with no function behind it, before setup
runs: it prints FAIL: <name>: no such test function, counts the test
as failed, and the file exits 1. Before, it printed ok and the file
exited 0.

Tests that exist run as before; a test still fails only by calling
fail.

How to verify

The tests need no setup. Base is f59aef7, branch is 99799b7.

Write a file with one test that exists and one that does not, from the
repository root:

$ printf '%s\n' 'source tests/harness.sh' 'test_alpha_one() { :; }' 'run_test test_alpha_one' 'run_test test_missing' 'finish' > /tmp/fixture.sh
$ bash /tmp/fixture.sh; echo "exit=$?"

On the base it prints test_missing: command not found,
ok test_missing, 2 test(s), 0 failure(s), and exit=0. On the
branch it prints FAIL: test_missing: no such test function,
2 test(s), 1 failure(s), and exit=1. Run with these results.

The regression test:

$ make test TESTS=harness FILTER='names_no_function'
    ok  test_a_run_test_line_that_names_no_function_fails_and_names_it
  1 test(s), 0 failure(s)

It passes on the branch, and fails on the base's code at its output
assertion.

make lint && .agents/hooks/shellcheck.sh repo && make test passed on
the branch: 344 tests, 0 failures, so every run_test line of the
suite names a function that exists.

Considerations

A test file that registers a missing test now fails where it passed
before; none does today.

## Why Every test file registers its tests with `run_test <name>` from the shared harness, `tests/harness.sh`. A line left behind by a rename, or a misspelled one, named a function that does not exist: the harness printed the shell's `command not found`, then `ok`, and the suite passed while the test it meant never ran. This showed during the work on #86, when a renamed test kept its old `run_test` line. ## What changed `run_test` now fails a name with no function behind it, before `setup` runs: it prints `FAIL: <name>: no such test function`, counts the test as failed, and the file exits 1. Before, it printed `ok` and the file exited 0. Tests that exist run as before; a test still fails only by calling `fail`. ## How to verify The tests need no setup. Base is `f59aef7`, branch is `99799b7`. Write a file with one test that exists and one that does not, from the repository root: ```console $ printf '%s\n' 'source tests/harness.sh' 'test_alpha_one() { :; }' 'run_test test_alpha_one' 'run_test test_missing' 'finish' > /tmp/fixture.sh $ bash /tmp/fixture.sh; echo "exit=$?" ``` On the base it prints `test_missing: command not found`, `ok test_missing`, `2 test(s), 0 failure(s)`, and `exit=0`. On the branch it prints `FAIL: test_missing: no such test function`, `2 test(s), 1 failure(s)`, and `exit=1`. Run with these results. The regression test: ```console $ make test TESTS=harness FILTER='names_no_function' ok test_a_run_test_line_that_names_no_function_fails_and_names_it 1 test(s), 0 failure(s) ``` It passes on the branch, and fails on the base's code at its output assertion. `make lint && .agents/hooks/shellcheck.sh repo && make test` passed on the branch: 344 tests, 0 failures, so every `run_test` line of the suite names a function that exists. ## Considerations A test file that registers a missing test now fails where it passed before; none does today.
run_test called the name and judged the test only by fail, so a line
left behind by a rename, or a misspelled one, printed the shell's
"command not found" and then "ok": the test it meant never ran and the
suite passed.

run_test now fails such a name before setup, and counts it.
claudiomaradonna deleted branch fix/harness-missing-test 2026-11-23 12:13:04 +01:00
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
claudiomaradonna/azkaban!88
No description provided.