Skip to content

Commit fe13133

Browse files
authored
GitHub Actions: Run Clippy on tests (#1006)
1/3 of #659
1 parent c8e17a9 commit fe13133

File tree

3 files changed

+58
-4
lines changed

3 files changed

+58
-4
lines changed

.github/workflows/tests.yml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,46 @@ jobs:
121121
run: sh ./_test/check-exercise-crate.sh
122122
continue-on-error: ${{ matrix.rust == 'beta' && matrix.deny_warnings == '1' }}
123123

124+
clippy:
125+
name: Clippy
126+
runs-on: ubuntu-latest
127+
128+
strategy:
129+
matrix:
130+
rust: ["stable", "beta"]
131+
132+
steps:
133+
- name: Checkout master
134+
uses: actions/checkout@v2
135+
with:
136+
ref: master
137+
138+
- name: Checkout code
139+
uses: actions/checkout@v2
140+
141+
# We actually think explicitly installing Clippy isn't necessary,
142+
# as it is currently installed by default.
143+
# But we'll include this step anyway just in case that changes.
144+
- name: Install Clippy
145+
run: rustup component add clippy
146+
147+
- name: Setup toolchain
148+
uses: actions-rs/toolchain@v1
149+
with:
150+
toolchain: ${{ matrix.rust }}
151+
default: true
152+
153+
- name: Clippy tests
154+
env:
155+
CLIPPY: tests/
156+
run: ./_test/check-exercises.sh
157+
158+
# Our examples currently have too much Clippy output to consider this.
159+
# But maybe in the future.
160+
#- name: Clippy examples
161+
# env:
162+
# CLIPPY: src/lib.rs
163+
# run: ./_test/check-exercises.sh
124164
nightly-compilation:
125165
name: Check exercises on nightly (benchmark enabled)
126166
runs-on: ubuntu-latest

_test/check-exercises.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@ if [ ! -x "./bin/test-exercise" ]; then
1111
exit 1
1212
fi
1313

14-
# In DENYWARNINGS mode, do not set -e so that we run all tests.
14+
# In DENYWARNINGS or CLIPPY mode, do not set -e so that we run all tests.
1515
# This allows us to see all warnings.
16-
if [ -z "$DENYWARNINGS" ]; then
16+
# If we are in neither DENYWARNINGS nor CLIPPY mode, do set -e.
17+
if [ -z "$DENYWARNINGS" ] && [ -z "$CLIPPY" ]; then
1718
set -e
1819
fi
1920

bin/test-exercise

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,19 @@ done
8282
# (use subshell so we auto-reset to current pwd after)
8383
(
8484
cd $exercise
85-
# this is the last command; its exit code is what's passed on
86-
time cargo $command "$@"
85+
if [ -n "$CLIPPY" ]; then
86+
cargo clippy --all-targets --color always "$@" 2>clippy.log
87+
# Only consider it a failure if output contains the string in CLIPPY.
88+
# For example, if we're only looking in tests, CLIPPY contains tests/
89+
if grep -q $CLIPPY clippy.log; then
90+
cat clippy.log
91+
exit 1
92+
else
93+
# Just to show progress
94+
echo "clippy $exercise OK"
95+
fi
96+
else
97+
# this is the last command; its exit code is what's passed on
98+
time cargo $command "$@"
99+
fi
87100
)

0 commit comments

Comments
 (0)