From d81e2b2b00259de695bc7302f3187531d07a99e9 Mon Sep 17 00:00:00 2001 From: Peter Tseng Date: Wed, 18 Nov 2020 09:05:30 +0000 Subject: [PATCH 1/7] GitHub Actions: Run Clippy on stubs 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 https://github.com/exercism/rust/issues/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) --- .github/workflows/tests.yml | 7 ++++++- _test/ensure-stubs-compile.sh | 37 ++++++++++++++++++++++++++--------- 2 files changed, 34 insertions(+), 10 deletions(-) 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 From f27d7e2d95ef77eb5440ce3d60bcd24a38836263 Mon Sep 17 00:00:00 2001 From: Peter Tseng Date: Wed, 18 Nov 2020 08:56:07 +0000 Subject: [PATCH 2/7] proof: leap: violate clippy --- exercises/leap/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/exercises/leap/src/lib.rs b/exercises/leap/src/lib.rs index fb1ecbc70..f3ade9f7c 100644 --- a/exercises/leap/src/lib.rs +++ b/exercises/leap/src/lib.rs @@ -1,3 +1,3 @@ -pub fn is_leap_year(year: u64) -> bool { - unimplemented!("true if {} is a leap year", year) +pub fn is_leap_year(_year: u64) -> bool { + return true; } From 7d41c0a24c41986cced3c67cecc12afaa7364418 Mon Sep 17 00:00:00 2001 From: Peter Tseng Date: Wed, 18 Nov 2020 08:59:15 +0000 Subject: [PATCH 3/7] proof: acronym: fail to compile --- exercises/acronym/src/lib.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/exercises/acronym/src/lib.rs b/exercises/acronym/src/lib.rs index adae79fa4..f10acb0b3 100644 --- a/exercises/acronym/src/lib.rs +++ b/exercises/acronym/src/lib.rs @@ -1,3 +1,4 @@ pub fn abbreviate(phrase: &str) -> String { + haha, this doesn't compile!!! unimplemented!("Given the phrase '{}', return its acronym", phrase); } From d31bed750f1d2a8b9c4ad42cff4c7fd30d8720c7 Mon Sep 17 00:00:00 2001 From: Peter Tseng Date: Wed, 18 Nov 2020 09:19:34 +0000 Subject: [PATCH 4/7] Revert "proof: acronym: fail to compile" This reverts commit 7d41c0a24c41986cced3c67cecc12afaa7364418. --- exercises/acronym/src/lib.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/exercises/acronym/src/lib.rs b/exercises/acronym/src/lib.rs index f10acb0b3..adae79fa4 100644 --- a/exercises/acronym/src/lib.rs +++ b/exercises/acronym/src/lib.rs @@ -1,4 +1,3 @@ pub fn abbreviate(phrase: &str) -> String { - haha, this doesn't compile!!! unimplemented!("Given the phrase '{}', return its acronym", phrase); } From 7ccf795f4a83d1723ca436fbff3e040a0c81c383 Mon Sep 17 00:00:00 2001 From: Peter Tseng Date: Wed, 18 Nov 2020 09:23:30 +0000 Subject: [PATCH 5/7] Revert "proof: leap: violate clippy" This reverts commit f27d7e2d95ef77eb5440ce3d60bcd24a38836263. --- exercises/leap/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/exercises/leap/src/lib.rs b/exercises/leap/src/lib.rs index f3ade9f7c..fb1ecbc70 100644 --- a/exercises/leap/src/lib.rs +++ b/exercises/leap/src/lib.rs @@ -1,3 +1,3 @@ -pub fn is_leap_year(_year: u64) -> bool { - return true; +pub fn is_leap_year(year: u64) -> bool { + unimplemented!("true if {} is a leap year", year) } From b74f52bebafd75f2bb476c37e0f8c2b090945437 Mon Sep 17 00:00:00 2001 From: Peter Tseng Date: Wed, 18 Nov 2020 09:23:53 +0000 Subject: [PATCH 6/7] proof: leap: violate clippy with an error (should fail) --- exercises/leap/src/lib.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/exercises/leap/src/lib.rs b/exercises/leap/src/lib.rs index fb1ecbc70..685cd3f7f 100644 --- a/exercises/leap/src/lib.rs +++ b/exercises/leap/src/lib.rs @@ -1,3 +1,6 @@ pub fn is_leap_year(year: u64) -> bool { + loop { + break; + } unimplemented!("true if {} is a leap year", year) } From c7cb43246664b067c6e3c02df2aeb45394f8f626 Mon Sep 17 00:00:00 2001 From: Peter Tseng Date: Wed, 18 Nov 2020 09:25:27 +0000 Subject: [PATCH 7/7] Revert "proof: leap: violate clippy with an error (should fail)" This reverts commit b74f52bebafd75f2bb476c37e0f8c2b090945437. --- exercises/leap/src/lib.rs | 3 --- 1 file changed, 3 deletions(-) diff --git a/exercises/leap/src/lib.rs b/exercises/leap/src/lib.rs index 685cd3f7f..fb1ecbc70 100644 --- a/exercises/leap/src/lib.rs +++ b/exercises/leap/src/lib.rs @@ -1,6 +1,3 @@ pub fn is_leap_year(year: u64) -> bool { - loop { - break; - } unimplemented!("true if {} is a leap year", year) }