-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathisolate.sh
More file actions
executable file
·73 lines (62 loc) · 2.42 KB
/
isolate.sh
File metadata and controls
executable file
·73 lines (62 loc) · 2.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/usr/bin/env bash
# Use:
# cargo --config 'target."cfg(all())".runner="./isolate.sh"' test --manifest-path "tests/${EXERCISE}_test/Cargo.toml"
set -u
bin="${1:-}"; shift || true
[[ -n "${bin:-}" ]] || { echo "[wrapper] missing test binary" >&2; exit 2; }
# Strip Cargo-only flags that confuse the test binary (e.g., --message-format)
filter_args() {
local -a out=(); local skip=0
for a in "$@"; do
if [[ $skip -eq 1 ]]; then skip=0; continue; fi
case "$a" in
--message-format|--format) skip=1 ;; # drop the next token
--message-format=*|--format=*) ;; # drop inline forms
*) out+=("$a") ;;
esac
done
printf '%s\n' "${out[@]}"
}
mapfile -t filtered < <(filter_args "$@")
tmpdir="$(mktemp -d -t strictwrap.XXXXXX)"; trap 'rm -rf "$tmpdir"' EXIT
expected="$tmpdir/expected.txt"
actual="$tmpdir/actual.txt"
logfile="$tmpdir/run.out"
# 1) Ask the harness which tests it *will* run (respects filters in "$@")
if ! "$bin" --list "${filtered[@]}" >"$tmpdir/list.txt" 2>/dev/null; then
echo "[wrapper] unable to list tests; cannot verify harness" >&2
exit 1
fi
# Lines look like: `path::to::name: test` (sometimes with " (ignored)")
awk -F': test' '/: test/{print $1}' "$tmpdir/list.txt" | sed 's/[[:space:]]*$//' > "$expected"
# 2) Run the suite normally and capture output + real exit code
(
"$bin" "${filtered[@]}" 2>&1
echo "__RC__$?"
) | tee "$logfile"
rc="$(awk -F'__RC__' '/__RC__/ {v=$2} END{print v+0}' "$logfile")"
# 3) Collect tests that actually produced a result line:
# Matches lines like: `test foo::bar ... ok|ignored|FAILED`
# Normalize names by stripping the " - should panic[ with `...`]" suffix.
awk '
/^test[[:space:]][^ ]/ {
line=$0
sub(/^test[[:space:]]+/, "", line) # drop leading "test "
sub(/[[:space:]]+\.\.\..*$/, "", line) # drop " ... ok/FAILED/ignored"
# Remove should_panic annotation added to pretty output:
sub(/[[:space:]]+- should panic( with `[^`]*`)?$/, "", line)
print line
}
' "$logfile" | sed 's/[[:space:]]*$//' > "$actual"
# 4) Decide overall success/failure
sort -u "$expected" -o "$expected"
sort -u "$actual" -o "$actual"
missing=0
if comm -23 "$expected" "$actual" | read -r _; then
echo "Some tests weren't ran for the exercise \`$EXERCISE\`. Perhaps the solution forcefully exits?"
missing=1
fi
if [[ "$rc" -eq 0 ]] && grep -Eq '^test result: ok\.' "$logfile" && [[ $missing -eq 0 ]]; then
exit 0
fi
exit 1