diff --git a/scripts/pr-watch-test.sh b/scripts/pr-watch-test.sh index 685a034f..5293388e 100755 --- a/scripts/pr-watch-test.sh +++ b/scripts/pr-watch-test.sh @@ -20,14 +20,14 @@ run_case() { [ "$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() { - local name="$1" want="$2" dir="$3"; shift 3 - local out="$work/output.txt" - PR_WATCH_FIXTURE_DIR="$dir" "$WATCH" 1 --interval 0 --timeout 1 "$@" >"$out" 2>&1 + local name="$1" want="$2" dir="$3" outfile="$4"; shift 4 + PR_WATCH_FIXTURE_DIR="$dir" "$WATCH" 1 --interval 0 --timeout 1 "$@" >"$outfile" 2>&1 local got=$? [ "$got" = "$want" ] && ok "$name" || bad "$name" "$got" "$want" - cat "$out" } mk() { mkdir -p "$1"; cat > "$1/$2"; } @@ -84,16 +84,16 @@ mk "$work/green-reviews" last.json <<'EOF' {"name":"build","status":"COMPLETED","conclusion":"SUCCESS"}]} EOF mk_reviews_with_review "$work/green-reviews" "aaaaaaaaaaaa" "aaaaaaaaaaaa" -out=$(run_case_capture "green with reviews shows review output" 0 "$work/green-reviews") -if echo "$out" | grep -q "pr-reviews:"; then +run_case_capture "green with reviews shows review output" 0 "$work/green-reviews" "$work/out1.txt" +if grep -q "pr-reviews:" "$work/out1.txt"; then ok "green with reviews prints pr-reviews output" else bad "green with reviews prints pr-reviews output" "no pr-reviews output" "pr-reviews: in output" fi # --no-reviews skips the review printout -out=$(run_case_capture "--no-reviews skips review output" 0 "$work/green-reviews" --no-reviews) -if echo "$out" | grep -q "pr-reviews:"; then +run_case_capture "--no-reviews skips review output" 0 "$work/green-reviews" "$work/out2.txt" --no-reviews +if grep -q "pr-reviews:" "$work/out2.txt"; then bad "--no-reviews skips review output" "pr-reviews in output" "no pr-reviews" else ok "--no-reviews actually skips review output"