Skip to content

Commit 37d4417

Browse files
committed
fix(test-vm): handle timeout portability on Windows/Linux
1 parent 4fcba50 commit 37d4417

1 file changed

Lines changed: 26 additions & 3 deletions

File tree

test-vm.sh

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,24 @@ shopt -s nullglob
1111

1212
TIMEOUT_SEC=5
1313

14+
# Use GNU timeout if available; Windows timeout.exe is incompatible with
15+
# `timeout N command ...` and can make every test look like a failure.
16+
TIMEOUT_BIN=""
17+
if command -v timeout >/dev/null 2>&1; then
18+
if timeout --version 2>/dev/null | grep -qi "coreutils"; then
19+
TIMEOUT_BIN="timeout"
20+
fi
21+
fi
22+
23+
# macOS users often install coreutils as gtimeout.
24+
if [[ -z "$TIMEOUT_BIN" ]] && command -v gtimeout >/dev/null 2>&1; then
25+
TIMEOUT_BIN="gtimeout"
26+
fi
27+
28+
if [[ -z "$TIMEOUT_BIN" ]]; then
29+
echo "⚠️ GNU timeout not found; running without per-test timeout."
30+
fi
31+
1432
cargo fmt --all
1533

1634
echo "🔍 Running clippy... (warnings ignored)"
@@ -41,12 +59,17 @@ for f in "${examples[@]}"; do
4159
fi
4260

4361
echo "testing $f"
44-
output=$(timeout "$TIMEOUT_SEC" "${cmd[@]}" 2>&1)
45-
rc=$?
62+
if [[ -n "$TIMEOUT_BIN" ]]; then
63+
output=$($TIMEOUT_BIN "$TIMEOUT_SEC" "${cmd[@]}" 2>&1)
64+
rc=$?
65+
else
66+
output=$("${cmd[@]}" 2>&1)
67+
rc=$?
68+
fi
4669

4770
if [[ $rc -eq 0 ]]; then
4871
pass+=("$name")
49-
elif [[ $rc -eq 124 ]]; then
72+
elif [[ -n "$TIMEOUT_BIN" && $rc -eq 124 ]]; then
5073
tout+=("$name")
5174
elif echo "$output" | grep -q "Unimplemented"; then
5275
skip+=("$name")

0 commit comments

Comments
 (0)