Skip to content

Commit 001d62c

Browse files
committed
test(bats): widen the comments describing the errexit exemption
Six suites explain why they avoid `! cmd` by saying errexit is suppressed for a "negated pipeline". The exemption is not about pipelines: a bare `! true`, a negated `[ ... ]`, one inside a `for` body or a brace group, one in a case branch, and one following `;`, `&`, `&&` or `||` are all exempt too. Anyone reading the narrower wording could conclude the other shapes are safe. One of the six carries the sentence twice, and the second copy is split across two physical lines -- `` `!` `` ending one and `pipeline)` opening the next -- so a line-oriented search for the phrase does not see it. Prose wraps; a grep for it has to fold the lines first. Comment text only; every one of these files already uses the working form the comment recommends. Assisted-By: Claude <noreply@anthropic.com> Signed-off-by: Aleksei Sviridkin <3811295@gmail.com>
1 parent e510d20 commit 001d62c

6 files changed

Lines changed: 25 additions & 18 deletions

hack/build-matrix_test.bats

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,10 @@
1717

1818
@test "talos and installer are excluded from the parallel matrix" {
1919
out=$(hack/build-matrix.sh)
20-
# `! cmd` would be vacuous: cozytest.sh runs each @test under `set -e`, which
21-
# is suppressed for a `!`-negated pipeline, so a regression that wrongly
22-
# included these paths would not fail the test. Assert via `if cmd; then ...`.
20+
# `! cmd` would be vacuous: cozytest.sh runs each @test under `set -e`,
21+
# which is suppressed for any command whose status is inverted with `!`, so
22+
# a regression that wrongly included these paths would not fail the test.
23+
# Assert via `if cmd; then ...`.
2324
if echo "$out" | grep -q '"packages/core/talos"'; then echo "FAIL: packages/core/talos must be excluded from the parallel matrix"; false; fi
2425
if echo "$out" | grep -q '"packages/core/installer"'; then echo "FAIL: packages/core/installer must be excluded from the parallel matrix"; false; fi
2526
}

hack/capture-dataplane.bats

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -235,9 +235,10 @@ EOF
235235
[ "$(printf '%s\n' "$out" | grep -c .)" -eq 2 ]
236236
printf '%s\n' "$out" | grep -q '^tenant|app|LoadBalancer|192.0.2.50|'
237237
printf '%s\n' "$out" | grep -q '^tenant|db|LoadBalancer|192.0.2.51|'
238-
# `! cmd` is vacuous under cozytest's `set -e` (errexit is suppressed for a
239-
# `!`-negated pipeline), so a filter regression that let these rows through
240-
# would not fail the test. Assert the absence via `if cmd; then ...; false`.
238+
# `! cmd` is vacuous under cozytest's `set -e` (errexit is suppressed for
239+
# any command whose status is inverted with `!`), so a filter regression
240+
# that let these rows through would not fail the test. Assert the absence
241+
# via `if cmd; then ...; false`.
241242
if printf '%s\n' "$out" | grep -q 'kube-dns'; then echo "FAIL: lb_filter_services must drop the kube-dns row"; false; fi
242243
if printf '%s\n' "$out" | grep -q 'pending'; then echo "FAIL: lb_filter_services must drop the pending (no external IP) row"; false; fi
243244
}

hack/capture-previous-logs.bats

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,10 @@ E2E_CAPTURE_PREVLOGS_LIB=1
5555
[ "$(printf '%s\n' "$out" | grep -c .)" -eq 2 ]
5656
printf '%s\n' "$out" | grep -q '^tenant-test|mariadb-test-0|mariadb|container|3$'
5757
printf '%s\n' "$out" | grep -q '^tenant-test|mariadb-test-0|init-datadir|init|2$'
58-
# `! cmd` is vacuous under cozytest's `set -e` (errexit is suppressed for a
59-
# `!`-negated pipeline), so a filter regression that let these rows through
60-
# would not fail the test. Assert the absence via `if cmd; then ...; false`.
58+
# `! cmd` is vacuous under cozytest's `set -e` (errexit is suppressed for
59+
# any command whose status is inverted with `!`), so a filter regression
60+
# that let these rows through would not fail the test. Assert the absence
61+
# via `if cmd; then ...; false`.
6162
if printf '%s\n' "$out" | grep -q 'mariadb-test-1'; then echo "FAIL: must drop the zero-restart replica"; false; fi
6263
if printf '%s\n' "$out" | grep -q 'cozy-system'; then echo "FAIL: must drop the zero-restart system pod"; false; fi
6364
}

hack/common-envs_test.bats

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@
1717
# relative `make -C packages/...` calls resolve against that cwd. This is NOT
1818
# real bats — no run/$status/$output/setup(); use plain $(...) capture + grep,
1919
# and the build-matrix_test.bats `if grep -q …; then echo FAIL; false; fi`
20-
# negation idiom (cozytest runs each @test under `set -e`, which suppresses a
21-
# bare `!`-negated pipeline, so a regression would silently pass a `! grep`).
20+
# negation idiom (cozytest runs each @test under `set -e`, which suppresses any
21+
# command whose status is inverted with `!`, so a regression would silently pass
22+
# a `! grep`).
2223

2324
@test "cozystack-controller exports one OCI archive and never pushes under OCI_EXPORT_DIR" {
2425
out=$(make -n -C packages/system/cozystack-controller image OCI_EXPORT_DIR=/tmp/ocitest IMAGE_TAG=pr-1-abc BUILDER=b)

hack/cozyreport.bats

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1334,9 +1334,10 @@ STUB
13341334
@test "pods not ready drops a fully ready running pod" {
13351335
out="$(printf '%s\n' "$SNAPSHOT" | cozyreport_pods_not_ready)"
13361336

1337-
# `! cmd` is vacuous under cozytest's `set -e` (errexit is suppressed for a
1338-
# `!`-negated pipeline), so a regression that let this row through would not
1339-
# fail the test. Assert the absence via `if cmd; then ...; false`.
1337+
# `! cmd` is vacuous under cozytest's `set -e` (errexit is suppressed for
1338+
# any command whose status is inverted with `!`), so a regression that let
1339+
# this row through would not fail the test. Assert the absence via
1340+
# `if cmd; then ...; false`.
13401341
if printf '%s\n' "$out" | grep -q 'coredns-abc'; then echo "FAIL: a ready pod must not be collected"; false; fi
13411342
}
13421343

hack/e2e-install-cozystack.bats

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -496,8 +496,9 @@ EOF
496496
echo "$output" | grep -q "tenant names must"
497497
# And assert kubectl did NOT report creation — if validation regressed
498498
# into a "warn" variant, the server could still accept the object. A bare
499-
# `! echo | grep` is vacuous under cozytest's `set -e` (suppressed for a `!`
500-
# pipeline), so the regression would slip through; assert via `if ...; false`.
499+
# `! echo | grep` is vacuous under cozytest's `set -e` (suppressed for any
500+
# command whose status is inverted with `!`), so the regression would slip
501+
# through; assert via `if ...; false`.
501502
if echo "$output" | grep -qi "created"; then echo "FAIL: kubectl reported the tenant as created — validation must reject it, not warn"; false; fi
502503

503504
# Post-condition cleanup: even though we expect validation to reject the
@@ -614,8 +615,9 @@ EOF
614615
-o jsonpath='{.data.version}')
615616
kubectl delete configmap cozystack-version -n cozy-system
616617
# A bare `! kubectl get` is vacuous under cozytest's `set -e` (errexit is
617-
# suppressed for a `!` pipeline), so a delete that silently failed would not
618-
# fail the test; assert the absence via `if kubectl get; then ...; false`.
618+
# suppressed for any command whose status is inverted with `!`), so a
619+
# delete that silently failed would not fail the test; assert the absence
620+
# via `if kubectl get; then ...; false`.
619621
if kubectl get configmap cozystack-version -n cozy-system 2>/dev/null; then echo "FAIL: cozystack-version configmap must be gone after delete with the no-delete label removed"; false; fi
620622
# Reconstruct: declarative apply matches the chart template at
621623
# packages/core/platform/templates/cozystack-version.yaml — same label set

0 commit comments

Comments
 (0)