Skip to content

Commit 465ac7e

Browse files
authored
GitHub Actions: Run Clippy on stubs (#1011)
Fails the build if any stubs have Clippy errors. Does not fail the build if stubs have Clippy warnings, but does display them (and there are a number of them). The author of this PR is not sure we will ever get around to fixing all the Clippy warnings, but supposes that it is at least beneficial to make sure we add no new Clippy errors. 1/3 of #659 (By the way, ensure-stubs-compile already had a bad mix of spaces and tabs and this commit did not help any in making it better. The author's text editor cannot easily put tabs in shell scripts)
1 parent c9048a4 commit 465ac7e

File tree

2 files changed

+34
-10
lines changed

2 files changed

+34
-10
lines changed

.github/workflows/tests.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,11 +137,16 @@ jobs:
137137
- name: Install Clippy
138138
run: rustup component add clippy
139139

140-
- name: Clippy
140+
- name: Clippy tests
141141
env:
142142
CLIPPY: true
143143
run: ./_test/check-exercises.sh
144144

145+
- name: Clippy stubs
146+
env:
147+
CLIPPY: true
148+
run: sh ./_test/ensure-stubs-compile.sh
149+
145150
nightly-compilation:
146151
name: Check exercises on nightly (benchmark enabled)
147152
runs-on: ubuntu-latest

_test/ensure-stubs-compile.sh

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,21 +30,40 @@ for dir in $changed_exercises; do
3030
cp -r $dir/tests $dir/tests.orig
3131
cp $dir/src/lib.rs $dir/lib.rs.orig
3232

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

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

44-
if ! (cd $dir && cargo test --quiet --no-run); then
45-
echo "$exercise's stub does not compile; please make it compile"
46-
broken="$broken\n$exercise"
47-
fi
51+
if [ -n "$CLIPPY" ]; then
52+
if ! (cd $dir && cargo clippy --lib --tests --color always 2>clippy.log); then
53+
cat $dir/clippy.log
54+
broken="$broken\n$exercise"
55+
elif grep -q warning $dir/clippy.log; then
56+
# Warnings will be outputted, but do not fail the build.
57+
echo "clippy $exercise WARN"
58+
cat $dir/clippy.log
59+
else
60+
# Just to show progress
61+
echo "clippy $exercise OK"
62+
fi
63+
elif ! (cd $dir && cargo test --quiet --no-run); then
64+
echo "$exercise's stub does not compile; please make it compile"
65+
broken="$broken\n$exercise"
66+
fi
4867

4968
# Restore tests and stub.
5069
mv $dir/lib.rs.orig $dir/src/lib.rs

0 commit comments

Comments
 (0)