11#! /usr/bin/env bash
2-
32set -eo pipefail
4- IFS='
5- '
3+ IFS=$' \n '
64
75# support both variables CODE_EDITOR_RUN_ONLY and EXAM_RUN_ONLY
86CODE_EDITOR_RUN_ONLY=" ${CODE_EDITOR_RUN_ONLY:- $EXAM_RUN_ONLY } "
@@ -13,26 +11,42 @@ cp -a /app/tests .
1311cp -a /app/isolate.sh .
1412cp -a student solutions
1513
16- if test " $CODE_EDITOR_MODE " ; then
17- cd " solutions/$EXERCISE "
18- # ! to support both the old and the new version of the runner we
19- # ! need to check the files in the code editor
20- if ! echo " $EDITOR_FILES " | tr ' ,' ' \n' | grep -q ' src/main.rs' ; then
21- if test " $CODE_EDITOR_RUN_ONLY " ; then
22- mv src/lib.rs src/main.rs 2>&1 || :
23- fi
24- fi
25- cargo init
26- cd
14+ if [ " $CODE_EDITOR_MODE " ]; then
15+ cd " solutions/$EXERCISE "
16+ # Support both old/new code editor runners
17+ if ! echo " $EDITOR_FILES " | tr ' ,' ' \n' | grep -q ' src/main.rs' ; then
18+ if [ " $CODE_EDITOR_RUN_ONLY " ]; then
19+ mv src/lib.rs src/main.rs 2> /dev/null || true
20+ fi
21+ fi
22+ cargo init
23+ cd -
2724fi
2825
29- if ! test -f " tests/${EXERCISE} _test/Cargo.toml" ; then
30- echo " No test file found for the exercise : $EXERCISE "
31- exit 1
26+ if [ ! -f " tests/${EXERCISE} _test/Cargo.toml" ] ; then
27+ echo " No test file found for the exercise: $EXERCISE "
28+ exit 1
3229fi
3330
34- if test " $CODE_EDITOR_RUN_ONLY " ; then
35- cargo run --manifest-path " solutions/$EXERCISE /Cargo.toml" -- " $@ "
31+ # Ensure EXERCISE is inherited by isolate.sh
32+ export EXERCISE
33+ # Ensure current directory is in PATH for isolate.sh
34+ export PATH=" .:$PATH "
35+
36+ if [ " $CODE_EDITOR_RUN_ONLY " ]; then
37+ cargo run --manifest-path " solutions/$EXERCISE /Cargo.toml" -- " $@ "
3638else
37- cargo --config ' target."cfg(all())".runner="./isolate.sh"' test --manifest-path " tests/${EXERCISE} _test/Cargo.toml"
39+ # 1) Compile tests first, without running
40+ set +e
41+ cargo test --no-run --manifest-path " tests/${EXERCISE} _test/Cargo.toml"
42+ rc=$?
43+ set -e
44+ if [ " $rc " -ne 0 ]; then
45+ echo " Solution did not compile."
46+ exit 1
47+ fi
48+
49+ # 2) Run tests with isolate.sh as runner
50+ cargo --config ' target."cfg(all())".runner="./isolate.sh"' \
51+ test --manifest-path " tests/${EXERCISE} _test/Cargo.toml"
3852fi
0 commit comments