Skip to content
File

Blob: src/workerd/api/node/tests/test_process_stdio.sh

bash39 lines
1#!/bin/bash
2 
3# Test script to verify process stdio output against golden files
4set -euo pipefail
5 
6# Arguments passed from Bazel
7WORKERD_BINARY="$1"
8TEST_CONFIG="$2"
9EXPECTED_STDOUT="$3"
10EXPECTED_STDERR="$4"
11 
12# Run the workerd test and capture stdout and stderr
13ACTUAL_STDOUT=$(mktemp)
14ACTUAL_STDERR=$(mktemp)
15FILTERED_STDOUT=$(mktemp)
16FILTERED_STDERR=$(mktemp)
17trap "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
22grep -vE "\[ PASS \]|\[ FAIL \]|\[ TEST \]" "$ACTUAL_STDERR" > "$FILTERED_STDERR" || true
23 
24# Compare with expected output (normalize line endings for cross-platform compatibility)
25echo "Comparing stdout..."
26if ! 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
29fi
30 
31# Compare with expected output
32echo "Comparing stderr..."
33if ! 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
36fi
37 
38echo "PASS: All stdio output matches golden files"