Skip to content

Commit a9e39c9

Browse files
test(e2e): clean up the resolver suite without EXIT traps
hack/bats-no-exit-trap.bats, added to main after this branch opened, is red on this file: eleven tests install `trap 'rm -rf "$tmp"' EXIT` and the file declares no debt, so `bats-unit-tests` fails, which skips `finalize` and with it both the required `E2E Tests` check and this PR's own lane. Convert rather than declare the debt. A handler installed inside an @test replaces the one the bats binary keeps for its own bookkeeping, and a test that then fails prints no TAP line at all — not `not ok`, nothing — so the suite reads green while a case is failing. Removing the scratch directory as the last statement of the body is the documented alternative: both runners set -e, so on failure the removal is unreachable and the directory survives for inspection, which is what a failed test wants anyway. The file header now says so, next to the cleanup it explains, so the next person adding a test here copies the right shape. Verified: hack/bats-no-exit-trap.bats green, and all eleven cases in this suite still pass. Assisted-By: Claude <[email protected]> Signed-off-by: Myasnikov Daniil <[email protected]>
1 parent 22b39d6 commit a9e39c9

1 file changed

Lines changed: 19 additions & 11 deletions

File tree

‎hack/upgrade-prev-version_test.bats‎

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,14 @@
99
# file and passes it as the resolver's TAGS_FILE arg, so no real git history is
1010
# touched and results are deterministic. Auto-discovered by the Makefile's
1111
# bats-unit-tests target (it is NOT an hack/e2e-*.bats, so it is included).
12+
#
13+
# Each test removes its scratch directory as the last statement of its body
14+
# rather than from an EXIT handler. A handler installed inside an @test replaces
15+
# the one the bats binary keeps for its own bookkeeping, and a test that then
16+
# fails prints no TAP line at all -- not `not ok`, nothing -- so the suite reads
17+
# green. Both runners set -e, so on failure the removal is unreachable and the
18+
# directory survives for inspection, which is what a failed test wants anyway.
19+
# hack/bats-no-exit-trap.bats enforces this tree-wide.
1220
# -----------------------------------------------------------------------------
1321

1422
# Fixture: a representative multi-line tag set covering several minor lines,
@@ -30,100 +38,100 @@ EOF
3038

3139
@test "rc target resolves to previous minor's latest stable" {
3240
tmp=$(mktemp -d)
33-
trap 'rm -rf "$tmp"' EXIT
3441
_fixture > "$tmp/tags"
3542
output=$(hack/upgrade-prev-version.sh v1.6.0-rc.1 "$tmp/tags")
3643
[ "$output" = "v1.5.3" ]
44+
rm -rf "$tmp"
3745
}
3846

3947
@test "stable .0 target resolves to previous minor's latest stable" {
4048
tmp=$(mktemp -d)
41-
trap 'rm -rf "$tmp"' EXIT
4249
_fixture > "$tmp/tags"
4350
output=$(hack/upgrade-prev-version.sh v1.6.0 "$tmp/tags")
4451
[ "$output" = "v1.5.3" ]
52+
rm -rf "$tmp"
4553
}
4654

4755
@test "patch target resolves to the PREVIOUS minor, not same-line patches" {
4856
# Promoting v1.5.4 must upgrade FROM the 1.4 line's latest stable (previous
4957
# minor), never from an earlier 1.5 patch.
5058
tmp=$(mktemp -d)
51-
trap 'rm -rf "$tmp"' EXIT
5259
_fixture > "$tmp/tags"
5360
output=$(hack/upgrade-prev-version.sh v1.5.4 "$tmp/tags")
5461
[ "$output" = "v1.4.6" ]
62+
rm -rf "$tmp"
5563
}
5664

5765
@test "leading-v optional in target" {
5866
tmp=$(mktemp -d)
59-
trap 'rm -rf "$tmp"' EXIT
6067
_fixture > "$tmp/tags"
6168
output=$(hack/upgrade-prev-version.sh 1.6.0-rc.2 "$tmp/tags")
6269
[ "$output" = "v1.5.3" ]
70+
rm -rf "$tmp"
6371
}
6472

6573
@test "pre-release tags are never selected as the baseline" {
6674
# Only v1.5.x stable tags exist below 1.6; the 1.6 rc tags must be ignored.
6775
tmp=$(mktemp -d)
68-
trap 'rm -rf "$tmp"' EXIT
6976
_fixture > "$tmp/tags"
7077
output=$(hack/upgrade-prev-version.sh v1.6.0-rc.1 "$tmp/tags")
7178
case "$output" in *-*) echo "FAIL: selected a pre-release: $output" >&2; false ;; esac
79+
rm -rf "$tmp"
7280
}
7381

7482
@test "skips a minor line that never shipped a stable release" {
7583
# 1.5 line has only a pre-release; target 1.6 must fall through to 1.4.
7684
tmp=$(mktemp -d)
77-
trap 'rm -rf "$tmp"' EXIT
7885
cat > "$tmp/tags" <<'EOF'
7986
v1.4.6
8087
v1.5.0-rc.1
8188
v1.6.0-rc.1
8289
EOF
8390
output=$(hack/upgrade-prev-version.sh v1.6.0-rc.1 "$tmp/tags")
8491
[ "$output" = "v1.4.6" ]
92+
rm -rf "$tmp"
8593
}
8694

8795
@test "line match is dot-anchored (1.5 does not match v155.x)" {
8896
tmp=$(mktemp -d)
89-
trap 'rm -rf "$tmp"' EXIT
9097
cat > "$tmp/tags" <<'EOF'
9198
v1.5.3
9299
v155.0.0
93100
v1.6.0-rc.1
94101
EOF
95102
output=$(hack/upgrade-prev-version.sh v1.6.0-rc.1 "$tmp/tags")
96103
[ "$output" = "v1.5.3" ]
104+
rm -rf "$tmp"
97105
}
98106

99107
@test "empty target falls back to the highest stable tag overall" {
100108
tmp=$(mktemp -d)
101-
trap 'rm -rf "$tmp"' EXIT
102109
_fixture > "$tmp/tags"
103110
output=$(hack/upgrade-prev-version.sh "" "$tmp/tags")
104111
[ "$output" = "v1.5.3" ]
112+
rm -rf "$tmp"
105113
}
106114

107115
@test "no previous minor (major 0, minor 0) is an error" {
108116
tmp=$(mktemp -d)
109-
trap 'rm -rf "$tmp"' EXIT
110117
cat > "$tmp/tags" <<'EOF'
111118
v0.0.1
112119
EOF
113120
if out=$(hack/upgrade-prev-version.sh v0.0.5 "$tmp/tags" 2>/dev/null); then
114121
echo "FAIL: expected non-zero exit, got '$out'" >&2
115122
false
116123
fi
124+
rm -rf "$tmp"
117125
}
118126

119127
@test "unparseable target is an error" {
120128
tmp=$(mktemp -d)
121-
trap 'rm -rf "$tmp"' EXIT
122129
_fixture > "$tmp/tags"
123130
if out=$(hack/upgrade-prev-version.sh "not-a-version" "$tmp/tags" 2>/dev/null); then
124131
echo "FAIL: expected non-zero exit, got '$out'" >&2
125132
false
126133
fi
134+
rm -rf "$tmp"
127135
}
128136

129137
# A target naming only a major ("v1") is not a version this resolver can act on,
@@ -135,7 +143,6 @@ EOF
135143
# upgrade path nobody asked for.
136144
@test "a target naming only a major version is an error, not a guess" {
137145
tmp=$(mktemp -d)
138-
trap 'rm -rf "$tmp"' EXIT
139146

140147
# NOT _fixture: it ships no v1.0.x/v1.1.x tag, so the buggy reading of "v1"
141148
# as v1.1 walked down to an empty v1.0 line and errored for the WRONG reason —
@@ -160,4 +167,5 @@ EOF
160167
# rejects a missing minor, not a missing patch.
161168
out=$(hack/upgrade-prev-version.sh "v1.6" "$tmp/tags")
162169
[ -n "$out" ]
170+
rm -rf "$tmp"
163171
}

0 commit comments

Comments
 (0)