Skip to content

Replace single-letter -# self-tests with a named -#test=NAME registry - #427

Merged
xroche merged 1 commit into
masterfrom
selftest-named-dispatch
Jun 26, 2026
Merged

Replace single-letter -# self-tests with a named -#test=NAME registry#427
xroche merged 1 commit into
masterfrom
selftest-named-dispatch

Conversation

@xroche

@xroche xroche commented Jun 26, 2026

Copy link
Copy Markdown
Owner

The hidden engine self-tests had grown into a pile of arbitrary single-letter and single-digit -# arms (-#0, -#A, -#W, ...) buried in the htscoremain.c option switch, with no mnemonics and a stale --help listing. This replaces them with one registry: -#test lists every self-test with its arguments and a one-line description, and -#test=NAME [args] runs one. The handlers (and the two helpers they used) move to a new htsselftest.c keyed by a {name, args, desc, fn} table; htscoremain.c keeps only a small dispatch, placed ahead of the no-URL usage gate so a bare -#test or an arg-less test no longer needs a dummy URL token. Only the unit self-tests are renamed, and their sole callers are tests/01_engine-*.test, so there is no external compatibility surface; the genuine debug knobs (-#L, -#C, -#R, ...) keep their letters.

Behavior is preserved: each test prints the same result line and exit code, which the existing assertions pin. The test suite moves to -#test=NAME, the hashtable test now asserts its success line (not just exit code) so a misrouted registry row cannot slip through, and a new dispatch test covers the list and unknown-name paths. One loose end: the vestigial --debug-testfilters alias still resolves to the removed -#0. It was already non-functional (it passes one argument where -#0 wanted two), and I left it rather than edit the alias array, which would make clang-format reflow the whole untouched table.

The hidden engine self-tests had accreted into a grab-bag of arbitrary
single-letter/-digit -# arms (-#0, -#A, -#W, ...) buried in the htscoremain.c
option switch, with no mnemonics and stale --help text. Collapse them into one
registry: -#test lists every test with a usage hint and one-line description,
and -#test=NAME [args] runs one.

The handlers and the two helpers they used (basic_selftests,
string_safety_selftests) move to a new htsselftest.c keyed by a
{name, args, desc, fn} table; htscoremain.c keeps only a small dispatch that
runs ahead of the no-URL usage gate, so a bare -#test (or an arg-less test like
copyopt/dns/cookies) no longer needs a dummy URL token to be reached. The
genuine debug knobs (-#L, -#C, -#R, -#h, ...) stay as letters in the switch;
only the unit self-tests, whose sole callers are tests/01_engine-*.test, are
renamed, so this is internal-only with no compatibility surface. Behavior is
preserved: each test prints the same result line and exit code, which the
existing assertions pin. Three now-unused includes (htscache_selftest.h,
htsdns_selftest.h, htsencoding.h) drop out of htscoremain.c.

Tests: the engine tests move to -#test=NAME; 01_engine-hashtable now asserts its
success line (not just exit code) so a misrouted registry row can't pass, and a
new 01_engine-selftest-dispatch covers the bare-list and unknown-name paths.

The --help/man "guru options" list now points at -#test instead of enumerating
a stale subset. The lone vestigial alias --debug-testfilters still resolves to
the removed -#0 (it was already non-functional: param1 supplies one argument,
-#0 required two); it is left untouched because editing that array forces
clang-format to reflow the whole untouched table.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Signed-off-by: Xavier Roche <roche@httrack.com>
@xroche
xroche merged commit bfc4a01 into master Jun 26, 2026
13 checks passed
@xroche
xroche deleted the selftest-named-dispatch branch July 27, 2026 18:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant