Repository navigation
A negated command only asserts in final position - #10
Merged
Merged
Conversation
`! cmd` on its own line asserts nothing in a bats body unless it happens to
be the last command of that body: bash does not apply errexit to a negated
command, so the verdict is the exit status of the final command and every
earlier `! cmd` is inert. shellcheck names the class SC2314 and grades the
two cases apart, error for the inert ones and note for the rest:
shellcheck -f gcc --shell=bash tests/*.bats | grep SC2314
`tests/postfix-local.bats` has three bare negations. One is inert, line 96,
`! logged smtpd_banner` in "stops at the first failing postconf": that test
would pass on a script that carried on past the failing postconf and wrote
the banner anyway. The other two, lines 66 and 97, are last in their bodies
and do assert.
All three become `run !`, the form that asserts wherever it stands,
including the two that already did: a line whose meaning depends on its
position is the trap itself. That form needs bats 1.5.0, declared at the top
of the file as the other suites in the organization declare it.
No assertion changed its verdict; the suite is green with the inert one
live. Coverage unchanged: postfix-local 100.00 percent, 17 of 17 lines,
threshold 100.
COVERAGE.md records the rule, and corrects a statement made on
fix/keel-apt-identity that all three negations were inert.
Collaborator
Author
added 2 commits
September 29, 2026 03:55
#8 landed on 19.x with its own paragraph on bare negations, which said the inert one in tests/postfix-local.bats was left for the pull request that owns that file. This is that pull request, and the merge kept both paragraphs. The first one now ends with what this branch did, and the second is gone.
marcos-mendez
added a commit
that referenced
this pull request
Sep 29, 2026
…ning 19.x gained #8 and #10, and tests/coverage.sh in #8's shape: one kcov run per measured file, each with the suite that exercises it. This branch had rewritten it into one run over a list; its files move into #8's shape as targets (samba-rootpass, rootpass, webmin-enable, webmin-pam, each with its own suite, all at 100), and the two suites that measure no file of their own, before-firstboot.bats and pam-unix.bats, run after the loop so they still gate. The changelog keeps both sides' entries; COVERAGE.md keeps this branch's section under 19.x's baseline heading. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01SfWQScmDZ94KCS5DMYrfe6
marcos-mendez
added a commit
that referenced
this pull request
Sep 29, 2026
A negated command only asserts in final position
marcos-mendez
added a commit
that referenced
this pull request
Sep 29, 2026
…ning 19.x gained #8 and #10, and tests/coverage.sh in #8's shape: one kcov run per measured file, each with the suite that exercises it. This branch had rewritten it into one run over a list; its files move into #8's shape as targets (samba-rootpass, rootpass, webmin-enable, webmin-pam, each with its own suite, all at 100), and the two suites that measure no file of their own, before-firstboot.bats and pam-unix.bats, run after the loop so they still gate. The changelog keeps both sides' entries; COVERAGE.md keeps this branch's section under 19.x's baseline heading.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The three negations in
tests/postfix-local.batsnow assert wherever they stand. One of them did not assert at all.Closes #9. Part of Keel-Linux/tracker#19, which has the organization-wide sweep.
Why a bare
!is inertA 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
! cmddecides the test in final position and is inert everywhere else. shellcheck grades the two apart,error:for the inert ones andnote:for the rest:What was not being checked
Line 96, in "stops at the first failing postconf". The test is named for stopping at the first failure, and
! logged smtpd_banneris the assertion that says it stopped — a script that carried on past the failingpostconfand set the banner anyway would have passed. Lines 66 and 97 are last in their bodies and did assert.All three are
run !now, the two that already asserted included: a line whose meaning depends on its position is the trap itself.The COVERAGE.md correction
COVERAGE.mdonfix/keel-apt-identity(#8) states:That is wrong about two of the three: 66 and 97 are in final position and do assert. This PR puts the accurate statement on
19.x, in the same place, so the branch is the record:That will conflict with #8, deliberately: the same paragraph in the same position, so whoever rebases #8 has to reconcile it rather than silently restore the wrong sentence. #8's version should be dropped on rebase.
Test plan
shellcheck -f gcc --shell=bash --severity=error --include=SC2314 tests/*.batsreports nothing.bats tests/postfix-local.batsgreen, 7 tests, with the inert assertion live. No assertion changed its verdict.tests/coverage.sh:postfix-local: 100.00 percent (17 of 17 lines) covered, threshold 100. Unchanged.COVERAGE.mdship nothing, sopackage / changelogpasses by reporting that nothing that ships changed. No changelog entry and no version bump.