fix(pr-watch-test): run_case_capture in parent shell, not subshell
The run_case_capture helper was being called in command substitution
(out=$(run_case_capture ...)), which runs it in a subshell. This caused
the ok/bad updates to the pass/fail counters to be discarded.
Fix by having the helper write output to a caller-provided file parameter,
then reading from that file in the caller. This keeps the helper in the
parent shell where counter updates are preserved.
Addresses Codex P2 review on commit ec30c8a7.
Co-authored-by: Ed Langley <fiddlerwoaroof@users.noreply.github.com>
This commit is contained in:
@@ -20,14 +20,14 @@ run_case() {
|
|||||||
[ "$got" = "$want" ] && ok "$name" || bad "$name" "$got" "$want"
|
[ "$got" = "$want" ] && ok "$name" || bad "$name" "$got" "$want"
|
||||||
}
|
}
|
||||||
|
|
||||||
# Like run_case but captures stdout for content checks
|
# Like run_case but writes output to a caller-provided file.
|
||||||
|
# Caller must NOT use command substitution (subshell loses ok/bad counters).
|
||||||
|
# $1 name, $2 expected exit, $3 fixture dir, $4 output file, rest: extra args
|
||||||
run_case_capture() {
|
run_case_capture() {
|
||||||
local name="$1" want="$2" dir="$3"; shift 3
|
local name="$1" want="$2" dir="$3" outfile="$4"; shift 4
|
||||||
local out="$work/output.txt"
|
PR_WATCH_FIXTURE_DIR="$dir" "$WATCH" 1 --interval 0 --timeout 1 "$@" >"$outfile" 2>&1
|
||||||
PR_WATCH_FIXTURE_DIR="$dir" "$WATCH" 1 --interval 0 --timeout 1 "$@" >"$out" 2>&1
|
|
||||||
local got=$?
|
local got=$?
|
||||||
[ "$got" = "$want" ] && ok "$name" || bad "$name" "$got" "$want"
|
[ "$got" = "$want" ] && ok "$name" || bad "$name" "$got" "$want"
|
||||||
cat "$out"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
mk() { mkdir -p "$1"; cat > "$1/$2"; }
|
mk() { mkdir -p "$1"; cat > "$1/$2"; }
|
||||||
@@ -84,16 +84,16 @@ mk "$work/green-reviews" last.json <<'EOF'
|
|||||||
{"name":"build","status":"COMPLETED","conclusion":"SUCCESS"}]}
|
{"name":"build","status":"COMPLETED","conclusion":"SUCCESS"}]}
|
||||||
EOF
|
EOF
|
||||||
mk_reviews_with_review "$work/green-reviews" "aaaaaaaaaaaa" "aaaaaaaaaaaa"
|
mk_reviews_with_review "$work/green-reviews" "aaaaaaaaaaaa" "aaaaaaaaaaaa"
|
||||||
out=$(run_case_capture "green with reviews shows review output" 0 "$work/green-reviews")
|
run_case_capture "green with reviews shows review output" 0 "$work/green-reviews" "$work/out1.txt"
|
||||||
if echo "$out" | grep -q "pr-reviews:"; then
|
if grep -q "pr-reviews:" "$work/out1.txt"; then
|
||||||
ok "green with reviews prints pr-reviews output"
|
ok "green with reviews prints pr-reviews output"
|
||||||
else
|
else
|
||||||
bad "green with reviews prints pr-reviews output" "no pr-reviews output" "pr-reviews: in output"
|
bad "green with reviews prints pr-reviews output" "no pr-reviews output" "pr-reviews: in output"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# --no-reviews skips the review printout
|
# --no-reviews skips the review printout
|
||||||
out=$(run_case_capture "--no-reviews skips review output" 0 "$work/green-reviews" --no-reviews)
|
run_case_capture "--no-reviews skips review output" 0 "$work/green-reviews" "$work/out2.txt" --no-reviews
|
||||||
if echo "$out" | grep -q "pr-reviews:"; then
|
if grep -q "pr-reviews:" "$work/out2.txt"; then
|
||||||
bad "--no-reviews skips review output" "pr-reviews in output" "no pr-reviews"
|
bad "--no-reviews skips review output" "pr-reviews in output" "no pr-reviews"
|
||||||
else
|
else
|
||||||
ok "--no-reviews actually skips review output"
|
ok "--no-reviews actually skips review output"
|
||||||
|
|||||||
Reference in New Issue
Block a user