Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,16 @@ jobs:
- name: Install Clippy
run: rustup component add clippy

- name: Clippy
- name: Clippy tests
env:
CLIPPY: true
run: ./_test/check-exercises.sh

- name: Clippy stubs
env:
CLIPPY: true
run: sh ./_test/ensure-stubs-compile.sh

nightly-compilation:
name: Check exercises on nightly (benchmark enabled)
runs-on: ubuntu-latest
Expand Down
37 changes: 28 additions & 9 deletions _test/ensure-stubs-compile.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,40 @@ for dir in $changed_exercises; do
cp -r $dir/tests $dir/tests.orig
cp $dir/src/lib.rs $dir/lib.rs.orig

# This sed serves two purposes:
# First, in Travis CI, we may have already compiled using the example solution.
# Edit the src/lib.rs file so that we surely recompile using the stub.
# Second, ensures that the stub compiles without warnings.
sed -i -e '1i #![deny(warnings)]' "$dir/src/lib.rs"
# In CI, we may have already compiled using the example solution.
# So we want to touch the src/lib.rs in some way,
# so that we surely recompile using the stub.
if [ -n "$CLIPPY" ]; then
# We don't deny warnings in clippy mode,
# just because there are many we don't want to deal with right now.
# So in clippy mode it's just a touch.
touch "$dir/src/lib.rs"
else
# In non-clippy mode, we do want to compile without warnings.
sed -i -e '1i #![deny(warnings)]' "$dir/src/lib.rs"
fi

# Deny warnings in the tests that may result from compiling the stubs.
# This helps avoid, for example, an overflowing literal warning
# that could be caused by a stub with a type that is too small.
sed -i -e '1i #![deny(warnings)]' $dir/tests/*.rs

if ! (cd $dir && cargo test --quiet --no-run); then
echo "$exercise's stub does not compile; please make it compile"
broken="$broken\n$exercise"
fi
if [ -n "$CLIPPY" ]; then
if ! (cd $dir && cargo clippy --lib --tests --color always 2>clippy.log); then
cat $dir/clippy.log
broken="$broken\n$exercise"
elif grep -q warning $dir/clippy.log; then
# Warnings will be outputted, but do not fail the build.
echo "clippy $exercise WARN"
cat $dir/clippy.log
else
# Just to show progress
echo "clippy $exercise OK"
fi
elif ! (cd $dir && cargo test --quiet --no-run); then
echo "$exercise's stub does not compile; please make it compile"
broken="$broken\n$exercise"
fi

# Restore tests and stub.
mv $dir/lib.rs.orig $dir/src/lib.rs
Expand Down