Three of the four refusals of is_sql_literal assert nothing, including the quote and the backslash #18

Closed
opened 2026-09-28 05:27:55 -03:00 by marcos-mendez · 0 comments
marcos-mendez commented 2026-09-28 05:27:55 -03:00 (Migrated from github.com)

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 on its own line decides the test when it is the final command of the body and is inert everywhere else.

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

tests/boot-test.bats, lines 516–518:

@test "is_sql_literal: a generated password, and nothing needing an escape" {
    bt_is_sql_literal abcXYZ019
    bt_is_sql_literal 'fc42:5009:ba4b:5ab0:%'
    ! bt_is_sql_literal ""            # line 516 — inert
    ! bt_is_sql_literal "it's"        # line 517 — inert
    ! bt_is_sql_literal 'back\slash'  # line 518 — inert
    ! bt_is_sql_literal 'two words'   # line 519 — last, asserts
}

Three of the four refusals did not run, and they include the two that matter: a value carrying a single quote and a value carrying a backslash. bt_is_sql_literal is what stops the boot test putting a value it did not generate inside single quotes in a statement — its own comment says so — and its quote and backslash cases were not being checked.

The same file already uses run ! at line 510, so the form and the bats_require_minimum_version 1.5.0 declaration are already here; these four lines were simply written the other way.

tests/hook.bats line 163 is in final position and does assert.

What to do

Write every negation run ! cmd, the ones in final position included, so that no line's meaning depends on its position.

Test plan

  • shellcheck --severity=error --include=SC2314 over tests/*.bats reports nothing.
  • bats tests/*.bats green with the three inert assertions live.
  • tests/coverage.sh at or above the committed threshold of 95.
  • Tests ship nothing, so package / changelog passes by reporting that nothing that ships changed.
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` on its own line decides the test when it is the final command of the body and is **inert everywhere else**. shellcheck -f gcc --shell=bash tests/*.bats | grep SC2314 `tests/boot-test.bats`, lines 516–518: @test "is_sql_literal: a generated password, and nothing needing an escape" { bt_is_sql_literal abcXYZ019 bt_is_sql_literal 'fc42:5009:ba4b:5ab0:%' ! bt_is_sql_literal "" # line 516 — inert ! bt_is_sql_literal "it's" # line 517 — inert ! bt_is_sql_literal 'back\slash' # line 518 — inert ! bt_is_sql_literal 'two words' # line 519 — last, asserts } Three of the four refusals did not run, and they include the two that matter: a value carrying a single quote and a value carrying a backslash. `bt_is_sql_literal` is what stops the boot test putting a value it did not generate inside single quotes in a statement — its own comment says so — and its quote and backslash cases were not being checked. The same file already uses `run !` at line 510, so the form and the `bats_require_minimum_version 1.5.0` declaration are already here; these four lines were simply written the other way. `tests/hook.bats` line 163 is in final position and does assert. ## What to do Write every negation `run ! cmd`, the ones in final position included, so that no line's meaning depends on its position. ## Test plan - `shellcheck --severity=error --include=SC2314` over `tests/*.bats` reports nothing. - `bats tests/*.bats` green with the three inert assertions live. - `tests/coverage.sh` at or above the committed threshold of 95. - Tests ship nothing, so `package / changelog` passes by reporting that nothing that ships changed.
Sign in to join this conversation.
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
Keel-Linux/keel-mariadb#18
No description provided.