Skip to content

Commit 93ab297

Browse files
committed
test(e2e): 202 用 here-string,别让 pipefail 把「匹配成功」读成失败
`set -o pipefail` 开着,而 `grep -q` 一匹配就退出 —— 于是 `echo "$out" | grep -q` 让 echo 往一个已关闭的管道写、吃到 SIGPIPE,整条管道报 141,**尽管匹配是成功的**。 它只在 `$out` 足够大、echo 还没写完时现形,对 `cache list` 来说就是「这台机器构建过 几个东西之后」。实测(开发机、热构建缓存,48808 字节): OLD(已发布 2026.8.10.3) 4/5 次失败 NEW(本分支) 3/5 次失败 同一个字符串 `grep -c kind` 数出 153 处匹配 ⇒ **与被测的 mcpp 无关,与本机缓存大小有关。** CI 缓存小,所以那边一直绿。 我差点把它当成本分支的回归报出去 —— 一个会随无关缓存大小失败的测试,必然会被读成 「当时手里那个改动」的回归。改成 here-string,两个二进制各跑 8 次全过。
1 parent 5919795 commit 93ab297

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

tests/e2e/202_machine_output_contract.sh

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,20 @@ check "unsupported value (pack)" 2 "$MCPP" pack --format bogus
5555
# And the supported ones must still be JSON on stdout. Asserted here because
5656
# every check above is about what does NOT happen; without this, deleting the
5757
# feature entirely would leave the file green.
58+
#
59+
# HERE-STRINGS, NOT PIPES. `set -o pipefail` is on, and `grep -q` exits the
60+
# moment it matches — so `echo "$out" | grep -q` leaves `echo` writing into a
61+
# closed pipe, takes SIGPIPE, and the pipeline reports 141 even though the
62+
# match SUCCEEDED. It only shows up once `$out` is big enough that echo has not
63+
# finished writing, which for `cache list` means "once this machine has built a
64+
# few things": measured 3-4 failures in 5 runs on a developer box with a warm
65+
# build cache, and zero on CI, with `grep -c` on the same string finding 153
66+
# matches. A test that fails on the size of an unrelated cache is a test that
67+
# will be read as a regression in whatever happens to be in flight.
5868
for cmd in "self env" "cache list"; do
5969
out=$($MCPP $cmd --format json 2>/dev/null) || { echo "FAIL: $cmd --format json exited non-zero"; fail=1; }
60-
echo "$out" | grep -q '"schemaVersion"' || { echo "FAIL: $cmd --format json has no schemaVersion"; fail=1; }
61-
echo "$out" | grep -q '"kind"' || { echo "FAIL: $cmd --format json has no kind"; fail=1; }
70+
grep -q '"schemaVersion"' <<<"$out" || { echo "FAIL: $cmd --format json has no schemaVersion"; fail=1; }
71+
grep -q '"kind"' <<<"$out" || { echo "FAIL: $cmd --format json has no kind"; fail=1; }
6272
done
6373

6474
[[ "$fail" -eq 0 ]] || exit 1

0 commit comments

Comments
 (0)