Repository navigation
A negated command only asserts in final position - #5
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. Four negations here were inert, and they are the refutations this component exists to make: - conf.bats, the bind fragment: that it never says `localhost`. That is the exact line docs/traps.md records the PostgreSQL appliance getting wrong, and the test that was put there to stop it happening again did not run. - conf.bats, the acl fragment: that it declares no `admin` user and no `requirepass`. Those two are what make the duplicate user declaration impossible and keep the password off the disk at build time; only the third refusal, `+@all`, ran. - unit.bats, the shipped tree: that no `requirepass` line is anywhere in the overlay. The comment above it calls this "the one property the whole design rests on". All of them become `run !`, together with the six that were in final position and did assert, because a line whose meaning depends on its position is the trap itself. No assertion changed its verdict: the fragments and the overlay are as the tests believed. Suite green, 70 tests. Coverage unchanged at 100.00 percent, 35redispass 31 of 31 lines and redis.sh 56 of 56, threshold 100.
Contributor
Author
|
Reviewed: every converted refutation goes red when its property is broken; adding |
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.
Every negation in these suites now asserts wherever it stands. Four did not assert at all, and they were the refutations this component exists to make.
Closes #4. 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
localhost. That is the exact linedocs/traps.mdrecords the PostgreSQL appliance getting wrong — "On Debian,localhostis not an IPv6 name" — and the test written to stop it happening again did not run.adminuser and norequirepass. Those two are what make the duplicate user declaration impossible and keep the password off the disk at build time, which is the otherdocs/traps.mdentry. Only the third refusal,+@all, ran.requirepassline is anywhere in the shipped overlay. The comment above it calls this "the one property the whole design rests on".Two traps had a test each, and in both cases the test was inert. That is the shape of this defect: the refutation is the part a reader trusts most and the part the shell runs least.
All four become
run !, together with the six that were in final position and did assert: a line whose meaning depends on its position is the trap itself.tests/unit.batsgains thebats_require_minimum_version 1.5.0declaration the other two files already had.What was found
Nothing broken. Both fragments were rendered and read directly before the conversion: the bind fragment is
bind ::1 127.0.0.1and names no host, the acl fragment declaresuser default on nopass +infoand nothing else, and the overlay carries norequirepassand nomasterauth. The assertions were dead, not wrong.Test plan
Both rendered fragments and the shipped overlay read directly, before the conversion.
shellcheck -f gcc --shell=bash --severity=error --include=SC2314 tests/*.batsreports nothing.Every converted site audited for
runclobbering$output/$status/$lines; none here does.bats tests/*.batsgreen, 70 tests. No assertion changed its verdict.tests/coverage.sh: 100.00 percent, threshold 100. Unchanged.Tests ship nothing, so no changelog entry and no version bump.