Skip to content

Commit

Permalink
Merge pull request #415 from newAM/clippy-tests
Browse files Browse the repository at this point in the history
Run clippy on tests
  • Loading branch information
Dirbaio authored Nov 17, 2023
2 parents c58881e + 168c198 commit 11bda49
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 47 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@ jobs:
uses: dtolnay/rust-toolchain@stable
with:
components: clippy
targets: i686-unknown-linux-gnu
- run: cargo clippy --all --target i686-unknown-linux-gnu -- --deny warnings
targets: i686-unknown-linux-musl
- run: cargo clippy --all --target i686-unknown-linux-musl --all-targets -- --deny warnings

# Compilation check
check:
Expand Down
3 changes: 0 additions & 3 deletions src/pool/boxed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,6 @@ mod tests {
assert_eq!(0, raw as usize % 4096);
}

#[allow(clippy::redundant_clone)]
#[test]
fn can_clone_if_pool_is_not_exhausted() {
static STRUCT_CLONE_WAS_CALLED: AtomicBool = AtomicBool::new(false);
Expand Down Expand Up @@ -480,7 +479,6 @@ mod tests {
assert!(is_oom);
}

#[allow(clippy::redundant_clone)]
#[test]
fn clone_panics_if_pool_exhausted() {
static STRUCT_CLONE_WAS_CALLED: AtomicBool = AtomicBool::new(false);
Expand Down Expand Up @@ -515,7 +513,6 @@ mod tests {
// assert!(!STRUCT_CLONE_WAS_CALLED.load(Ordering::Relaxed));
}

#[allow(clippy::redundant_clone)]
#[test]
fn panicking_clone_does_not_leak_memory() {
static STRUCT_CLONE_WAS_CALLED: AtomicBool = AtomicBool::new(false);
Expand Down
36 changes: 18 additions & 18 deletions src/spsc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -638,26 +638,26 @@ mod tests {
fn full() {
let mut rb: Queue<i32, 3> = Queue::new();

assert_eq!(rb.is_full(), false);
assert!(!rb.is_full());

rb.enqueue(1).unwrap();
assert_eq!(rb.is_full(), false);
assert!(!rb.is_full());

rb.enqueue(2).unwrap();
assert_eq!(rb.is_full(), true);
assert!(rb.is_full());
}

#[test]
fn empty() {
let mut rb: Queue<i32, 3> = Queue::new();

assert_eq!(rb.is_empty(), true);
assert!(rb.is_empty());

rb.enqueue(1).unwrap();
assert_eq!(rb.is_empty(), false);
assert!(!rb.is_empty());

rb.enqueue(2).unwrap();
assert_eq!(rb.is_empty(), false);
assert!(!rb.is_empty());
}

#[test]
Expand Down Expand Up @@ -706,9 +706,9 @@ mod tests {

let (mut p, mut c) = rb.split();

assert_eq!(p.ready(), true);
assert!(p.ready());

assert_eq!(c.ready(), false);
assert!(!c.ready());

assert_eq!(c.dequeue(), None);

Expand Down Expand Up @@ -851,28 +851,28 @@ mod tests {
fn ready_flag() {
let mut rb: Queue<i32, 3> = Queue::new();
let (mut p, mut c) = rb.split();
assert_eq!(c.ready(), false);
assert_eq!(p.ready(), true);
assert!(!c.ready());
assert!(p.ready());

p.enqueue(0).unwrap();

assert_eq!(c.ready(), true);
assert_eq!(p.ready(), true);
assert!(c.ready());
assert!(p.ready());

p.enqueue(1).unwrap();

assert_eq!(c.ready(), true);
assert_eq!(p.ready(), false);
assert!(c.ready());
assert!(!p.ready());

c.dequeue().unwrap();

assert_eq!(c.ready(), true);
assert_eq!(p.ready(), true);
assert!(c.ready());
assert!(p.ready());

c.dequeue().unwrap();

assert_eq!(c.ready(), false);
assert_eq!(p.ready(), true);
assert!(!c.ready());
assert!(p.ready());
}

#[test]
Expand Down
16 changes: 6 additions & 10 deletions src/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -664,8 +664,7 @@ mod tests {
assert!(s.len() == 3);
assert_eq!(s, "123");

let e: () = String::<2>::try_from("123").unwrap_err();
assert_eq!(e, ());
let _: () = String::<2>::try_from("123").unwrap_err();
}

#[test]
Expand All @@ -676,8 +675,7 @@ mod tests {
assert!(s.len() == 3);
assert_eq!(s, "123");

let e: () = String::<2>::from_str("123").unwrap_err();
assert_eq!(e, ());
let _: () = String::<2>::from_str("123").unwrap_err();
}

#[test]
Expand All @@ -702,19 +700,18 @@ mod tests {

#[test]
fn try_from_num() {
let v: String<20> = String::try_from(18446744073709551615 as u64).unwrap();
let v: String<20> = String::try_from(18446744073709551615_u64).unwrap();
assert_eq!(v, "18446744073709551615");

let e: () = String::<2>::try_from(18446744073709551615 as u64).unwrap_err();
assert_eq!(e, ());
let _: () = String::<2>::try_from(18446744073709551615_u64).unwrap_err();
}

#[test]
fn into_bytes() {
let s: String<4> = String::try_from("ab").unwrap();
let b: Vec<u8, 4> = s.into_bytes();
assert_eq!(b.len(), 2);
assert_eq!(&['a' as u8, 'b' as u8], &b[..]);
assert_eq!(&[b'a', b'b'], &b[..]);
}

#[test]
Expand Down Expand Up @@ -790,9 +787,8 @@ mod tests {
Some(c) => {
assert_eq!(s.len(), 1);
assert_eq!(c, '\u{0301}'); // accute accent of e
()
}
None => assert!(false),
None => panic!(),
};
}

Expand Down
2 changes: 1 addition & 1 deletion src/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1437,7 +1437,7 @@ mod tests {

v.resize(0, 0).unwrap();
v.resize(4, 0).unwrap();
v.resize(5, 0).err().expect("full");
v.resize(5, 0).expect_err("full");
}

#[test]
Expand Down
20 changes: 7 additions & 13 deletions tests/tsan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,9 @@ fn contention() {

for _ in 0..(2 * N) {
loop {
match c.dequeue() {
Some(v) => {
sum = sum.wrapping_add(v as u32);
break;
}
_ => {}
if let Some(v) = c.dequeue() {
sum = sum.wrapping_add(v as u32);
break;
}
}
}
Expand Down Expand Up @@ -149,13 +146,10 @@ fn mpmc_contention() {

for _ in 0..(16 * N) {
loop {
match Q.dequeue() {
Some(v) => {
sum = sum.wrapping_add(v);
println!("dequeue {}", v);
break;
}
_ => {}
if let Some(v) = Q.dequeue() {
sum = sum.wrapping_add(v);
println!("dequeue {}", v);
break;
}
}
}
Expand Down

0 comments on commit 11bda49

Please sign in to comment.