11#! /usr/bin/env bash
22# Use:
3- # cargo --config 'target."cfg(all())".runner="./isolate.sh"' test [args]
3+ # EXERCISE="" bash -c ' cargo --config '\'' target."cfg(all())".runner="./isolate.sh"'\'' test --manifest-path "tests/${EXERCISE}_test/Cargo.toml"'
44
55set -u
66
3636awk -F' : test' ' /: test/{print $1}' " $tmpdir /list.txt" | sed ' s/[[:space:]]*$//' > " $expected "
3737
3838# 2) Run the suite normally and capture output + real exit code
39- (
40- " $bin " " ${filtered[@]} " 2>&1
41- echo " __RC__$? "
42- ) | tee " $logfile " > /dev/null
43- rc=" $( awk -F' __RC__' ' /__RC__/ {v=$2} END{print v+0}' " $logfile " ) "
39+ " $bin " " ${filtered[@]} " 2>&1 | tee " $logfile "
40+ rc=" ${PIPESTATUS[0]} "
4441
4542# 3) Collect tests that actually produced a result line:
4643# Matches lines like: `test foo::bar ... ok|ignored|FAILED`
@@ -56,18 +53,18 @@ awk '
5653 }
5754' " $logfile " | sed ' s/[[:space:]]*$//' > " $actual "
5855
59- # 4) Decide: require (a) rc==0, (b) final summary ok, (c) every expected test appeared
60- if [[ " $rc " -eq 0 ]] && grep -Eq ' ^test result: ok\. ' " $logfile " ; then
61- sort -u " $expected " -o " $expected "
62- sort -u " $actual " -o " $actual "
63- # If no tests were expected (filters matched none), that's fine too.
64- if comm -23 " $expected " " $actual " | read -r _; then
65- # there were missing tests → failure
66- echo " Some tests weren't ran for the exercise \` $EXERCISE \` . Perhaps the solution forcefully exits? "
67- exit 1
68- else
69- exit 0
70- fi
56+ # 4) Decide overall success/failure
57+ sort -u " $expected " -o " $expected "
58+ sort -u " $actual " -o " $actual "
59+
60+ missing=0
61+ if comm -23 " $expected " " $actual " | read -r _; then
62+ echo " Some tests weren't ran for the exercise \` $EXERCISE \` . Perhaps the solution forcefully exits? "
63+ missing=1
64+ fi
65+
66+ if [[ " $rc " -eq 0 ]] && grep -Eq ' ^test result: ok\. ' " $logfile " && [[ $missing -eq 0 ]] ; then
67+ exit 0
7168fi
7269
7370exit 1
0 commit comments