Skip to content

Commit 42ff19a

Browse files
authored
Merge pull request #1009 from petertseng/clippyexit
test-exercise: Detect Clippy failure by exit code, not by grep
2 parents 2d8ec8f + 63a6046 commit 42ff19a

File tree

5 files changed

+26
-22
lines changed

5 files changed

+26
-22
lines changed

.github/workflows/tests.yml

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -126,29 +126,22 @@ jobs:
126126
- name: Checkout code
127127
uses: actions/checkout@v2
128128

129-
# We actually think explicitly installing Clippy isn't necessary,
130-
# as it is currently installed by default.
131-
# But we'll include this step anyway just in case that changes.
132-
- name: Install Clippy
133-
run: rustup component add clippy
134-
135129
- name: Setup toolchain
136130
uses: actions-rs/toolchain@v1
137131
with:
138132
toolchain: ${{ matrix.rust }}
139133
default: true
140134

141-
- name: Clippy tests
135+
# Clippy already installed on Stable, but not Beta.
136+
# So, we must install here.
137+
- name: Install Clippy
138+
run: rustup component add clippy
139+
140+
- name: Clippy
142141
env:
143-
CLIPPY: tests/
142+
CLIPPY: true
144143
run: ./_test/check-exercises.sh
145144

146-
# Our examples currently have too much Clippy output to consider this.
147-
# But maybe in the future.
148-
#- name: Clippy examples
149-
# env:
150-
# CLIPPY: src/lib.rs
151-
# run: ./_test/check-exercises.sh
152145
nightly-compilation:
153146
name: Check exercises on nightly (benchmark enabled)
154147
runs-on: ubuntu-latest

bin/test-exercise

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,12 @@ done
8383
(
8484
cd $exercise
8585
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
86+
# Consider any Clippy to be an error in tests only.
87+
# For now, not the example solutions since they have many Clippy warnings,
88+
# and are not shown to students anyway.
89+
sed -i -e '1i #![deny(clippy::all)]' tests/*.rs
90+
cargo clippy --tests --color always "$@" 2>clippy.log
91+
if [ $? -ne 0 ]; then
9092
cat clippy.log
9193
exit 1
9294
else

exercises/book-store/example.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ type GroupedBasket = Vec<Group>;
1010
type Price = u32;
1111
const BOOK_PRICE: Price = 800;
1212

13-
#[derive(Debug, Clone, PartialEq, Eq)]
13+
#[derive(Debug, Clone)]
1414
struct Group(RefCell<BTreeSet<Book>>);
1515

1616
impl Group {
@@ -65,6 +65,14 @@ impl PartialOrd for Group {
6565
}
6666
}
6767

68+
impl PartialEq for Group {
69+
fn eq(&self, other: &Group) -> bool {
70+
self.0.borrow().eq(&other.0.borrow())
71+
}
72+
}
73+
74+
impl Eq for Group {}
75+
6876
impl Hash for Group {
6977
fn hash<H: Hasher>(&self, hasher: &mut H) {
7078
self.0.borrow().hash(hasher);

exercises/decimal/example.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,10 @@ impl Decimal {
101101
}
102102

103103
macro_rules! auto_impl_decimal_ops {
104-
($trait:ident, $func_name:ident, $digits_operation:expr, $index_operation:expr) => {
104+
($(#[$attr:meta])* $trait:ident, $func_name:ident, $digits_operation:expr, $index_operation:expr) => {
105105
impl $trait for Decimal {
106106
type Output = Self;
107+
$(#[$attr])*
107108
fn $func_name(mut self, mut rhs: Self) -> Self {
108109
Decimal::equalize_precision(&mut self, &mut rhs);
109110
Decimal::new(
@@ -117,7 +118,7 @@ macro_rules! auto_impl_decimal_ops {
117118

118119
auto_impl_decimal_ops!(Add, add, |s, o| s + o, |s, _| s);
119120
auto_impl_decimal_ops!(Sub, sub, |s, o| s - o, |s, _| s);
120-
auto_impl_decimal_ops!(Mul, mul, |s, o| s * o, |s, o| s + o);
121+
auto_impl_decimal_ops!(#[allow(clippy::suspicious_arithmetic_impl)] Mul, mul, |s, o| s * o, |s, o| s + o);
121122

122123
macro_rules! auto_impl_decimal_cow {
123124
($trait:ident, $func_name:ident, $digits_operation:expr, $return_type:ty) => {

exercises/decimal/tests/decimal.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ fn decimal(input: &str) -> Decimal {
88
}
99

1010
/// Some big and precise values we can use for testing. [0] + [1] == [2]
11-
const BIGS: [&'static str; 3] = [
11+
const BIGS: [&str; 3] = [
1212
"100000000000000000000000000000000000000000000.00000000000000000000000000000000000000001",
1313
"100000000000000000000000000000000000000000000.00000000000000000000000000000000000000002",
1414
"200000000000000000000000000000000000000000000.00000000000000000000000000000000000000003",

0 commit comments

Comments
 (0)