File
Blob: src/workerd/api/node/tests/test_process_stdio.sh
| 1 | #!/bin/bash |
| 2 | |
| 3 | # Test script to verify process stdio output against golden files |
| 4 | set -euo pipefail |
| 5 | |
| 6 | # Arguments passed from Bazel |
| 7 | WORKERD_BINARY="$1" |
| 8 | TEST_CONFIG="$2" |
| 9 | EXPECTED_STDOUT="$3" |
| 10 | EXPECTED_STDERR="$4" |
| 11 | |
| 12 | # Run the workerd test and capture stdout and stderr |
| 13 | ACTUAL_STDOUT=$(mktemp) |
| 14 | ACTUAL_STDERR=$(mktemp) |
| 15 | FILTERED_STDOUT=$(mktemp) |
| 16 | FILTERED_STDERR=$(mktemp) |
| 17 | trap "rm -f $ACTUAL_STDOUT $ACTUAL_STDERR $FILTERED_STDOUT $FILTERED_STDERR" EXIT |
| 18 | |
| 19 | "$WORKERD_BINARY" test "$TEST_CONFIG" --experimental >"$ACTUAL_STDOUT" 2>"$ACTUAL_STDERR" --compat-date 2025-05-01 |
| 20 | |
| 21 | # Remove [ PASS ] [ TEST ] [ FAIL ] lines from stderr |
| 22 | grep -vE "\[ PASS \]|\[ FAIL \]|\[ TEST \]" "$ACTUAL_STDERR" > "$FILTERED_STDERR" || true |
| 23 | |
| 24 | # Compare with expected output (normalize line endings for cross-platform compatibility) |
| 25 | echo "Comparing stdout..." |
| 26 | if ! diff -u <(tr -d '\r' < "$EXPECTED_STDOUT") <(tr -d '\r' < "$ACTUAL_STDOUT"); then |
| 27 | echo "FAIL: stdout does not match expected output" |
| 28 | exit 1 |
| 29 | fi |
| 30 | |
| 31 | # Compare with expected output |
| 32 | echo "Comparing stderr..." |
| 33 | if ! diff -u <(tr -d '\r' < "$EXPECTED_STDERR") <(tr -d '\r' < "$FILTERED_STDERR"); then |
| 34 | echo "FAIL: stderr does not match expected output" |
| 35 | exit 1 |
| 36 | fi |
| 37 | |
| 38 | echo "PASS: All stdio output matches golden files" |