diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 0b217d738..fd99bf274 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -121,6 +121,46 @@ jobs: run: sh ./_test/check-exercise-crate.sh continue-on-error: ${{ matrix.rust == 'beta' && matrix.deny_warnings == '1' }} + clippy: + name: Clippy + runs-on: ubuntu-latest + + strategy: + matrix: + rust: ["stable", "beta"] + + steps: + - name: Checkout master + uses: actions/checkout@v2 + with: + ref: master + + - name: Checkout code + uses: actions/checkout@v2 + + # We actually think explicitly installing Clippy isn't necessary, + # as it is currently installed by default. + # But we'll include this step anyway just in case that changes. + - name: Install Clippy + run: rustup component add clippy + + - name: Setup toolchain + uses: actions-rs/toolchain@v1 + with: + toolchain: ${{ matrix.rust }} + default: true + + - name: Clippy tests + env: + CLIPPY: tests/ + run: ./_test/check-exercises.sh + + # Our examples currently have too much Clippy output to consider this. + # But maybe in the future. + #- name: Clippy examples + # env: + # CLIPPY: src/lib.rs + # run: ./_test/check-exercises.sh nightly-compilation: name: Check exercises on nightly (benchmark enabled) runs-on: ubuntu-latest diff --git a/_test/check-exercises.sh b/_test/check-exercises.sh index 0ea61e2b7..6aa45da79 100755 --- a/_test/check-exercises.sh +++ b/_test/check-exercises.sh @@ -11,9 +11,10 @@ if [ ! -x "./bin/test-exercise" ]; then exit 1 fi -# In DENYWARNINGS mode, do not set -e so that we run all tests. +# In DENYWARNINGS or CLIPPY mode, do not set -e so that we run all tests. # This allows us to see all warnings. -if [ -z "$DENYWARNINGS" ]; then +# If we are in neither DENYWARNINGS nor CLIPPY mode, do set -e. +if [ -z "$DENYWARNINGS" ] && [ -z "$CLIPPY" ]; then set -e fi diff --git a/bin/test-exercise b/bin/test-exercise index cb42f67a3..d54470066 100755 --- a/bin/test-exercise +++ b/bin/test-exercise @@ -82,6 +82,19 @@ done # (use subshell so we auto-reset to current pwd after) ( cd $exercise - # this is the last command; its exit code is what's passed on - time cargo $command "$@" + if [ -n "$CLIPPY" ]; then + cargo clippy --all-targets --color always "$@" 2>clippy.log + # Only consider it a failure if output contains the string in CLIPPY. + # For example, if we're only looking in tests, CLIPPY contains tests/ + if grep -q $CLIPPY clippy.log; then + cat clippy.log + exit 1 + else + # Just to show progress + echo "clippy $exercise OK" + fi + else + # this is the last command; its exit code is what's passed on + time cargo $command "$@" + fi )