Skip to content

Commit 9dc9006

Browse files
committed
fix(rust): reflect changes on module
1 parent 528abe6 commit 9dc9006

File tree

3 files changed

+70
-35
lines changed

3 files changed

+70
-35
lines changed

Dockerfile

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,45 @@
11
### Test Image specific config
2+
FROM rustlang/rust:nightly-alpine
23

3-
FROM rust:1.90-slim-trixie
4-
5-
RUN apt-get update
6-
RUN apt-get -y install pkg-config libssl-dev moreutils
4+
# Install required packages
5+
RUN apk add --no-cache \
6+
bash \
7+
coreutils \
8+
findutils \
9+
gawk \
10+
grep \
11+
sed \
12+
parallel \
13+
pkgconfig \
14+
openssl-dev \
15+
build-base \
16+
moreutils
717

818
WORKDIR /app
19+
20+
# Copy project structure
921
COPY tests tests
1022
COPY tests_utility tests_utility
1123
COPY solutions solutions
24+
25+
# Use sparse index for Cargo (faster network)
1226
ENV CARGO_REGISTRIES_CRATES_IO_PROTOCOL=sparse
13-
RUN parallel cargo fetch --manifest-path -- $(find tests -name Cargo.toml)
27+
28+
# Pre-fetch all dependencies
29+
RUN find tests -name Cargo.toml | parallel cargo fetch --manifest-path {}
30+
31+
# Fix permissions for Rust crates (avoid “permission denied”)
1432
RUN find /usr/local/cargo/registry/src -type f -name '*.rs' -exec chmod 644 {} \;
33+
34+
# Remove solutions (only student code will be mounted)
1535
RUN rm -rf solutions
1636

17-
### Default configs
18-
# ℹ️ URL of the Repository
19-
LABEL org.opencontainers.image.source=https://github.com/01-edu/rust-tests
20-
# ℹ️ Description of the Test Image
21-
LABEL org.opencontainers.image.description="01 Edu - Rust Test Image"
22-
# ℹ️ Licence type – MIT by default
23-
LABEL org.opencontainers.image.licenses=MIT
37+
### Metadata labels
38+
LABEL org.opencontainers.image.source="https://github.com/01-edu/rust-tests"
39+
LABEL org.opencontainers.image.description="01 Edu - Rust Test Image (Alpine)"
40+
LABEL org.opencontainers.image.licenses="MIT"
2441

42+
# Copy entrypoint and isolate script
2543
COPY entrypoint.sh ./
2644
COPY isolate.sh ./
2745

entrypoint.sh

Lines changed: 34 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
#!/usr/bin/env bash
2-
32
set -eo pipefail
4-
IFS='
5-
'
3+
IFS=$'\n'
64

75
# support both variables CODE_EDITOR_RUN_ONLY and EXAM_RUN_ONLY
86
CODE_EDITOR_RUN_ONLY="${CODE_EDITOR_RUN_ONLY:-$EXAM_RUN_ONLY}"
@@ -13,26 +11,42 @@ cp -a /app/tests .
1311
cp -a /app/isolate.sh .
1412
cp -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 -
2724
fi
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
3229
fi
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" -- "$@"
3638
else
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"
3852
fi

isolate.sh

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env bash
22
# Use:
3-
# EXERCISE="" bash -c 'cargo --config '\''target."cfg(all())".runner="./isolate.sh"'\'' test --manifest-path "tests/${EXERCISE}_test/Cargo.toml"'
3+
# cargo --config 'target."cfg(all())".runner="./isolate.sh"' test --manifest-path "tests/${EXERCISE}_test/Cargo.toml"
44

55
set -u
66

@@ -36,8 +36,11 @@ fi
3636
awk -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-
"$bin" "${filtered[@]}" 2>&1 | tee "$logfile"
40-
rc="${PIPESTATUS[0]}"
39+
(
40+
"$bin" "${filtered[@]}" 2>&1
41+
echo "__RC__$?"
42+
) | tee "$logfile"
43+
rc="$(awk -F'__RC__' '/__RC__/ {v=$2} END{print v+0}' "$logfile")"
4144

4245
# 3) Collect tests that actually produced a result line:
4346
# Matches lines like: `test foo::bar ... ok|ignored|FAILED`

0 commit comments

Comments
 (0)