Commit fb3b8b84 authored by daniel.eades's avatar daniel.eades
Browse files

fix/silence clippy lints in test modules

parent 9cf1fa36
......@@ -416,6 +416,7 @@ impl<T: AsyncRead + AsyncWrite + Send + Unpin + 'static> VerifiedChannel<T> {
#[cfg(test)]
pub(super) mod test {
#![allow(clippy::unwrap_used)]
use futures_await_test::async_test;
use hex_literal::hex;
use std::time::{Duration, SystemTime};
......@@ -733,7 +734,7 @@ pub(super) mod test {
);
let err = certs_test(
certs.clone(),
certs,
Some(cert_timestamp()),
certs::PEER_ED,
certs::PEER_RSA,
......
......@@ -358,6 +358,7 @@ where
#[cfg(test)]
pub(crate) mod test {
#![allow(clippy::unwrap_used)]
use super::*;
use futures::sink::SinkExt;
use futures::stream::StreamExt;
......@@ -427,7 +428,7 @@ pub(crate) mod test {
let (rr_s, _) = join!(run_reactor, exit_then_check);
// Now let's see. The reactor should not _still_ be running.
assert_eq!(rr_s, true);
assert!(rr_s);
}
#[async_test]
......
......@@ -68,7 +68,7 @@ mod test {
// Make sure we got distinct numbers
let mut all_nums: Vec<_> = ids.iter().map(|x| x.0).collect();
all_nums.sort();
all_nums.sort_unstable();
all_nums.dedup();
assert_eq!(all_nums.len(), ids.len());
......
......@@ -1172,6 +1172,7 @@ fn resolvedval_to_result(val: ResolvedVal) -> Result<ResolvedVal> {
#[cfg(test)]
mod test {
#![allow(clippy::unwrap_used)]
use super::*;
use crate::channel::test::fake_channel;
use chanmsg::{ChanMsg, Created2, CreatedFast};
......@@ -1328,6 +1329,7 @@ mod test {
}
impl DummyCrypto {
fn next_tag(&mut self) -> &[u8; 20] {
#![allow(clippy::identity_op)]
self.counter_tag[0] = ((self.counter >> 0) & 255) as u8;
self.counter_tag[1] = ((self.counter >> 8) & 255) as u8;
self.counter_tag[2] = ((self.counter >> 16) & 255) as u8;
......
......@@ -66,6 +66,7 @@ impl TryFrom<ChanMsg> for ClientCircChanMsg {
#[cfg(test)]
mod test {
#![allow(clippy::unwrap_used)]
use super::*;
use std::convert::TryFrom;
......
......@@ -81,6 +81,7 @@ impl HalfStream {
#[cfg(test)]
mod test {
#![allow(clippy::unwrap_used)]
use super::*;
use crate::circuit::sendme::{StreamRecvWindow, StreamSendWindow};
use futures_await_test::async_test;
......
......@@ -284,6 +284,7 @@ pub(crate) fn cell_counts_towards_windows(cell: &RelayCell) -> bool {
#[cfg(test)]
mod test {
#![allow(clippy::unwrap_used)]
use super::*;
use futures::FutureExt;
use futures_await_test::async_test;
......@@ -307,9 +308,9 @@ mod test {
let mut w: RecvWindow<StreamParams> = RecvWindow::new(500);
for _ in 0..49 {
assert_eq!(w.take().unwrap(), false);
assert!(!w.take().unwrap());
}
assert_eq!(w.take().unwrap(), true);
assert!(w.take().unwrap());
assert_eq!(w.window, 450);
assert!(w.decrement_n(123).is_ok());
......
......@@ -188,6 +188,7 @@ impl StreamMap {
#[cfg(test)]
mod test {
#![allow(clippy::unwrap_used)]
use super::*;
use crate::circuit::sendme::{StreamRecvWindow, StreamSendWindow};
......
......@@ -389,7 +389,7 @@ pub(crate) mod tor1 {
#[cfg(test)]
mod test {
#![allow(clippy::unwrap_used)]
use super::*;
use crate::SecretBytes;
use rand::RngCore;
......@@ -444,9 +444,9 @@ mod test {
let mut cell = cell.into();
let _tag = cc_out.encrypt(&mut cell, 2.into()).unwrap();
assert_ne!(&cell.as_ref()[9..], &cell_orig.as_ref()[9..]);
assert_eq!(false, r1.decrypt_outbound(&mut cell));
assert_eq!(false, r2.decrypt_outbound(&mut cell));
assert_eq!(true, r3.decrypt_outbound(&mut cell));
assert!(!r1.decrypt_outbound(&mut cell));
assert!(!r2.decrypt_outbound(&mut cell));
assert!(r3.decrypt_outbound(&mut cell));
assert_eq!(&cell.as_ref()[9..], &cell_orig.as_ref()[9..]);
......
......@@ -86,6 +86,7 @@ impl super::ServerHandshake for CreateFastServer {
#[cfg(test)]
mod test {
#![allow(clippy::unwrap_used)]
use super::*;
use crate::crypto::handshake::{ClientHandshake, KeyGenerator, ServerHandshake};
use hex_literal::hex;
......
......@@ -303,6 +303,7 @@ where
#[cfg(test)]
mod tests {
#![allow(clippy::unwrap_used)]
use super::*;
use crate::crypto::testing::FakePRNG;
......@@ -320,7 +321,7 @@ mod tests {
let (state, cmsg) = NtorClient::client1(&mut rng, &relay_ntpk)?;
let relay_ntsk = NtorSecretKey {
pk: relay_ntpk.clone(),
pk: relay_ntpk,
sk: relay_secret,
};
let relay_ntsks = [relay_ntsk];
......
......@@ -118,6 +118,7 @@ impl Kdf for ShakeKdf {
#[cfg(test)]
mod test {
#![allow(clippy::unwrap_used)]
use super::*;
use hex_literal::hex;
......
......@@ -46,6 +46,7 @@ pub(crate) fn bytes_eq(a: &[u8], b: &[u8]) -> bool {
#[cfg(test)]
mod test {
#![allow(clippy::unwrap_used)]
#[test]
fn test_bytes_eq() {
use super::bytes_eq;
......
......@@ -493,6 +493,7 @@ impl std::fmt::Display for Protocols {
#[cfg(test)]
mod test {
#![allow(clippy::unwrap_used)]
use super::*;
#[test]
......@@ -566,19 +567,19 @@ mod test {
fn test_supports() -> Result<(), ParseError> {
let p: Protocols = "Link=4,5-7 Padding=2 Lonk=1-3,5".parse()?;
assert_eq!(p.supports_known_subver(ProtoKind::Padding, 2), true);
assert_eq!(p.supports_known_subver(ProtoKind::Padding, 1), false);
assert_eq!(p.supports_known_subver(ProtoKind::Link, 6), true);
assert_eq!(p.supports_known_subver(ProtoKind::Link, 255), false);
assert_eq!(p.supports_known_subver(ProtoKind::Cons, 1), false);
assert_eq!(p.supports_known_subver(ProtoKind::Cons, 0), false);
assert_eq!(p.supports_subver("Link", 6), true);
assert_eq!(p.supports_subver("link", 6), false);
assert_eq!(p.supports_subver("Cons", 0), false);
assert_eq!(p.supports_subver("Lonk", 3), true);
assert_eq!(p.supports_subver("Lonk", 4), false);
assert_eq!(p.supports_subver("lonk", 3), false);
assert_eq!(p.supports_subver("Lonk", 64), false);
assert!(p.supports_known_subver(ProtoKind::Padding, 2));
assert!(!p.supports_known_subver(ProtoKind::Padding, 1));
assert!(p.supports_known_subver(ProtoKind::Link, 6));
assert!(!p.supports_known_subver(ProtoKind::Link, 255));
assert!(!p.supports_known_subver(ProtoKind::Cons, 1));
assert!(!p.supports_known_subver(ProtoKind::Cons, 0));
assert!(p.supports_subver("Link", 6));
assert!(!p.supports_subver("link", 6));
assert!(!p.supports_subver("Cons", 0));
assert!(p.supports_subver("Lonk", 3));
assert!(!p.supports_subver("Lonk", 4));
assert!(!p.supports_subver("lonk", 3));
assert!(!p.supports_subver("Lonk", 64));
Ok(())
}
......
#![allow(clippy::unwrap_used, clippy::unnecessary_wraps)]
use crate::Runtime;
use crate::SleepProviderExt;
......
......@@ -193,6 +193,7 @@ fn calc_next_delay(now: SystemTime, when: SystemTime) -> (bool, Duration) {
#[cfg(test)]
mod test {
#![allow(clippy::erasing_op)]
use super::*;
#[test]
......
......@@ -158,6 +158,7 @@ impl LocalStream {
#[cfg(test)]
mod test {
#![allow(clippy::unwrap_used)]
use super::*;
use futures::io::{AsyncReadExt, AsyncWriteExt};
......
......@@ -493,6 +493,7 @@ fn err(k: ErrorKind) -> IoError {
#[cfg(test)]
mod test {
#![allow(clippy::unwrap_used)]
use super::*;
use futures::io::{AsyncReadExt, AsyncWriteExt};
use tor_rtcompat::test_with_all_runtimes;
......
......@@ -227,6 +227,7 @@ impl Future for Sleeping {
#[cfg(test)]
mod test {
#![allow(clippy::unwrap_used)]
use super::*;
use tor_rtcompat::test_with_all_runtimes;
......@@ -286,21 +287,21 @@ mod test {
async {
sp.advance(one_hour * 2).await;
r1.await.unwrap();
assert_eq!(true, b1.load(Ordering::SeqCst));
assert_eq!(false, b2.load(Ordering::SeqCst));
assert_eq!(false, b3.load(Ordering::SeqCst));
assert!(b1.load(Ordering::SeqCst));
assert!(!b2.load(Ordering::SeqCst));
assert!(!b3.load(Ordering::SeqCst));
sp.advance(one_hour * 2).await;
r2.await.unwrap();
assert_eq!(true, b1.load(Ordering::SeqCst));
assert_eq!(true, b2.load(Ordering::SeqCst));
assert_eq!(false, b3.load(Ordering::SeqCst));
assert!(b1.load(Ordering::SeqCst));
assert!(b2.load(Ordering::SeqCst));
assert!(!b3.load(Ordering::SeqCst));
sp.advance(one_hour * 2).await;
r3.await.unwrap();
assert_eq!(true, b1.load(Ordering::SeqCst));
assert_eq!(true, b2.load(Ordering::SeqCst));
assert_eq!(true, b3.load(Ordering::SeqCst));
assert!(b1.load(Ordering::SeqCst));
assert!(b2.load(Ordering::SeqCst));
assert!(b3.load(Ordering::SeqCst));
let real_end = Instant::now();
assert!(real_end - real_start < one_hour);
......
......@@ -78,12 +78,12 @@ fn wallclock_simple() {
},
async {
while mock_sp.wallclock() < start() + ONE_DAY {
assert_eq!(false, b.load(Ordering::SeqCst));
assert!(!b.load(Ordering::SeqCst));
mock_sp.advance(Duration::new(413, 0)).await;
}
}
);
assert_eq!(true, b.load(Ordering::SeqCst));
assert!(b.load(Ordering::SeqCst));
});
}
......@@ -104,13 +104,13 @@ fn wallclock_early() {
},
async {
while mock_sp.wallclock() < start() + (ONE_DAY / 2) {
assert_eq!(false, b.load(Ordering::SeqCst));
assert!(!b.load(Ordering::SeqCst));
mock_sp.advance(Duration::new(413, 0)).await;
}
send.send(()).unwrap();
}
);
assert_eq!(false, b.load(Ordering::SeqCst));
assert!(!b.load(Ordering::SeqCst));
});
}
......@@ -131,7 +131,7 @@ fn wallclock_jump_forward() {
mock_sp.advance(Duration::new(1000, 0)).await; // have to rest some.
}
);
assert_eq!(true, b.load(Ordering::SeqCst));
assert!(b.load(Ordering::SeqCst));
let i2 = mock_sp.now();
assert!(i2 - i1 < ONE_DAY);
});
......@@ -157,14 +157,14 @@ fn wallclock_jump_backwards() {
mock_sp.jump_to(start() - ONE_DAY);
let mut elapsed = Duration::new(0, 0);
while elapsed < (3 * ONE_DAY) / 2 {
assert_eq!(false, b.load(Ordering::SeqCst));
assert!(!b.load(Ordering::SeqCst));
mock_sp.advance(Duration::new(413, 0)).await;
elapsed += Duration::new(413, 0);
}
send.send(()).unwrap();
}
);
assert_eq!(false, b.load(Ordering::SeqCst));
assert!(!b.load(Ordering::SeqCst));
let i2 = mock_sp.now();
assert!(i2 - i1 > ONE_DAY);
assert!(mock_sp.wallclock() < start() + ONE_DAY);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment