A negated command only asserts in final position #19

Merged
marcos-mendez merged 2 commits from test/negations-that-assert into main 2026-09-29 00:59:05 -03:00
marcos-mendez commented 2026-09-28 05:28:24 -03:00 (Migrated from github.com)

The four refusals of bt_is_sql_literal now assert wherever they stand. Three of them did not assert at all.

Closes #18. Part of Keel-Linux/tracker#19, which has the organization-wide sweep.

Why a bare ! is inert

A bats test body has no assertions of its own: its verdict is the exit status of the last command it ran. Bash does not apply errexit to a negated command, so ! cmd decides the test in final position and is inert everywhere else. shellcheck grades the two apart, error: for the inert ones and note: for the rest:

shellcheck -f gcc --shell=bash tests/*.bats | grep SC2314

What was not being checked

tests/boot-test.bats lines 516–518: the empty string, a value with a single quote in it, and a value with a backslash. Only two words, last in the body, decided anything.

bt_is_sql_literal is the predicate that keeps the boot test from putting a value it did not generate inside single quotes in a statement — "a test that has to escape is a test building SQL out of something it did not generate", as the function's own comment puts it. Its quote and backslash cases are exactly the two that make that claim true, and neither was being run.

All four become run !, and so does the one in tests/hook.bats, which was in final position and did assert: a line whose meaning depends on its position is the trap itself. The file already used run ! at line 510, so the form and the 1.5.0 declaration were already here.

What was found

Nothing broken. The four values were run against bt_is_sql_literal by hand before the conversion, and all four are refused: [[ $value =~ ^[A-Za-z0-9:%._-]+$ ]] admits neither a quote, nor a backslash, nor a space, and the empty string is refused explicitly above it. The assertions were dead, not wrong.

Test plan

  • The four values verified against the predicate by hand, before the conversion.

  • shellcheck -f gcc --shell=bash --severity=error --include=SC2314 tests/*.bats reports nothing.

  • bats tests/*.bats green, 127 tests. No assertion changed its verdict.

  • tests/coverage.sh, threshold 95, unchanged:

    100.00  43/43    mariadb.sh
     95.45  21/22    35mysqlpass
    100.00  285/285  boot-test-lib.sh
    100.00  54/54    keel-archive-check
    
  • Tests ship nothing, so package / changelog passes by reporting that nothing that ships changed. No changelog entry and no version bump.

  • appliance / build-and-boot is gated on KEEL_LXC_RUNNER and is unaffected: nothing outside tests/*.bats changed.

The four refusals of `bt_is_sql_literal` now assert wherever they stand. Three of them did not assert at all. Closes #18. Part of Keel-Linux/tracker#19, which has the organization-wide sweep. ## Why a bare `!` is inert A bats test body has no assertions of its own: its verdict is the exit status of the last command it ran. Bash does not apply errexit to a negated command, so `! cmd` decides the test in final position and is inert everywhere else. shellcheck grades the two apart, `error:` for the inert ones and `note:` for the rest: shellcheck -f gcc --shell=bash tests/*.bats | grep SC2314 ## What was not being checked `tests/boot-test.bats` lines 516–518: the empty string, a value with a single quote in it, and a value with a backslash. Only `two words`, last in the body, decided anything. `bt_is_sql_literal` is the predicate that keeps the boot test from putting a value it did not generate inside single quotes in a statement — "a test that has to escape is a test building SQL out of something it did not generate", as the function's own comment puts it. Its quote and backslash cases are exactly the two that make that claim true, and neither was being run. All four become `run !`, and so does the one in `tests/hook.bats`, which was in final position and did assert: a line whose meaning depends on its position is the trap itself. The file already used `run !` at line 510, so the form and the 1.5.0 declaration were already here. ## What was found Nothing broken. The four values were run against `bt_is_sql_literal` by hand before the conversion, and all four are refused: `[[ $value =~ ^[A-Za-z0-9:%._-]+$ ]]` admits neither a quote, nor a backslash, nor a space, and the empty string is refused explicitly above it. The assertions were dead, not wrong. ## Test plan - [x] The four values verified against the predicate by hand, before the conversion. - [x] `shellcheck -f gcc --shell=bash --severity=error --include=SC2314 tests/*.bats` reports nothing. - [x] `bats tests/*.bats` green, 127 tests. No assertion changed its verdict. - [x] `tests/coverage.sh`, threshold 95, unchanged: 100.00 43/43 mariadb.sh 95.45 21/22 35mysqlpass 100.00 285/285 boot-test-lib.sh 100.00 54/54 keel-archive-check - [x] Tests ship nothing, so `package / changelog` passes by reporting that nothing that ships changed. No changelog entry and no version bump. - [ ] `appliance / build-and-boot` is gated on `KEEL_LXC_RUNNER` and is unaffected: nothing outside `tests/*.bats` changed.
marcos-mendez commented 2026-09-29 00:54:32 -03:00 (Migrated from github.com)

Reviewed: every converted refutation goes red when the code under test accepts that call, and each fails with status 1. No changes needed; merged main so the renamed appliance check runs on this head.

Reviewed: every converted refutation goes red when the code under test accepts that call, and each fails with status 1. No changes needed; merged main so the renamed appliance check runs on this head.
Sign in to join this conversation.
No description provided.