diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 6438fcc2e..e34f02a60 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -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 diff --git a/_test/ensure-stubs-compile.sh b/_test/ensure-stubs-compile.sh index d14da907b..7968765eb 100755 --- a/_test/ensure-stubs-compile.sh +++ b/_test/ensure-stubs-compile.sh @@ -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