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

fix/silence clippy lints in test modules

parent 9cf1fa36
...@@ -284,6 +284,7 @@ mod u8_array_impls { ...@@ -284,6 +284,7 @@ mod u8_array_impls {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
#![allow(clippy::unwrap_used)]
use crate::{Reader, Writer}; use crate::{Reader, Writer};
use hex_literal::hex; use hex_literal::hex;
macro_rules! check_encode { macro_rules! check_encode {
...@@ -333,7 +334,7 @@ mod tests { ...@@ -333,7 +334,7 @@ mod tests {
#[test] #[test]
fn roundtrip_u64() { fn roundtrip_u64() {
check_roundtrip!(u64, 0x4040111u64, [0, 0, 0, 0, 4, 4, 1, 17]); check_roundtrip!(u64, 0x4040111_u64, [0, 0, 0, 0, 4, 4, 1, 17]);
} }
#[test] #[test]
......
...@@ -269,6 +269,7 @@ impl<'a> Reader<'a> { ...@@ -269,6 +269,7 @@ impl<'a> Reader<'a> {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
#![allow(clippy::unwrap_used)]
use super::*; use super::*;
#[test] #[test]
fn bytecursor_read_ok() { fn bytecursor_read_ok() {
......
...@@ -352,7 +352,7 @@ fn test_relay() { ...@@ -352,7 +352,7 @@ fn test_relay() {
// Try converting to/from raw bodies. // Try converting to/from raw bodies.
let body = [3_u8; 509]; let body = [3_u8; 509];
let cell = msg::Relay::from_raw(body.clone()); let cell = msg::Relay::from_raw(body);
let body2 = cell.into_relay_body(); let body2 = cell.into_relay_body();
assert_eq!(&body2[..], &body[..]); assert_eq!(&body2[..], &body[..]);
} }
......
...@@ -21,7 +21,7 @@ fn unhex(s: &str) -> Vec<u8> { ...@@ -21,7 +21,7 @@ fn unhex(s: &str) -> Vec<u8> {
} }
fn decode(cmd: RelayCmd, body: &[u8]) -> Result<msg::RelayMsg, BytesError> { fn decode(cmd: RelayCmd, body: &[u8]) -> Result<msg::RelayMsg, BytesError> {
let mut r = tor_bytes::Reader::from_slice(&body[..]); let mut r = tor_bytes::Reader::from_slice(body);
msg::RelayMsg::decode_from_reader(cmd, &mut r) msg::RelayMsg::decode_from_reader(cmd, &mut r)
} }
......
...@@ -618,6 +618,7 @@ impl tor_checkable::Timebound<Ed25519Cert> for SigCheckedCert { ...@@ -618,6 +618,7 @@ impl tor_checkable::Timebound<Ed25519Cert> for SigCheckedCert {
#[cfg(test)] #[cfg(test)]
mod test { mod test {
#![allow(clippy::unwrap_used)]
use super::*; use super::*;
use hex_literal::hex; use hex_literal::hex;
......
...@@ -108,6 +108,7 @@ impl crate::mgr::AbstractChannel for tor_proto::channel::Channel { ...@@ -108,6 +108,7 @@ impl crate::mgr::AbstractChannel for tor_proto::channel::Channel {
#[cfg(test)] #[cfg(test)]
mod test { mod test {
#![allow(clippy::unwrap_used)]
use super::*; use super::*;
use crate::{ use crate::{
mgr::{AbstractChannel, ChannelFactory}, mgr::{AbstractChannel, ChannelFactory},
......
...@@ -232,6 +232,7 @@ impl<CF: ChannelFactory> AbstractChanMgr<CF> { ...@@ -232,6 +232,7 @@ impl<CF: ChannelFactory> AbstractChanMgr<CF> {
#[cfg(test)] #[cfg(test)]
mod test { mod test {
#![allow(clippy::unwrap_used)]
use super::*; use super::*;
use crate::Error; use crate::Error;
......
...@@ -180,6 +180,7 @@ impl<C: AbstractChannel> ChannelMap<C> { ...@@ -180,6 +180,7 @@ impl<C: AbstractChannel> ChannelMap<C> {
#[cfg(test)] #[cfg(test)]
mod test { mod test {
#![allow(clippy::unwrap_used)]
use super::*; use super::*;
#[derive(Eq, PartialEq, Debug)] #[derive(Eq, PartialEq, Debug)]
struct FakeChannel { struct FakeChannel {
......
...@@ -37,6 +37,7 @@ impl<T> super::SelfSigned<T> for SignatureGated<T> { ...@@ -37,6 +37,7 @@ impl<T> super::SelfSigned<T> for SignatureGated<T> {
#[cfg(test)] #[cfg(test)]
mod test { mod test {
#![allow(clippy::unwrap_used)]
use super::*; use super::*;
use crate::SelfSigned; use crate::SelfSigned;
use tor_llcrypto::pk::ValidatableSignature; use tor_llcrypto::pk::ValidatableSignature;
......
...@@ -382,6 +382,7 @@ where ...@@ -382,6 +382,7 @@ where
#[cfg(test)] #[cfg(test)]
mod test { mod test {
#![allow(clippy::unwrap_used)]
use super::*; use super::*;
use futures::channel::oneshot; use futures::channel::oneshot;
use std::sync::atomic::{AtomicU64, Ordering::SeqCst}; use std::sync::atomic::{AtomicU64, Ordering::SeqCst};
...@@ -616,8 +617,8 @@ mod test { ...@@ -616,8 +617,8 @@ mod test {
let outcome = rt.wait_for(builder.build_owned(p1, &params, rng)).await; let outcome = rt.wait_for(builder.build_owned(p1, &params, rng)).await;
let circ = outcome.unwrap().into_inner().unwrap(); let circ = outcome.unwrap().into_inner().unwrap();
assert_eq!(circ.onehop, true); assert!(circ.onehop);
assert_eq!(circ.hops[..], [[0x11; 32].into()]); assert_eq!(circ.hops, [[0x11; 32].into()]);
let rng = let rng =
StdRng::from_rng(rand::thread_rng()).expect("couldn't construct temporary rng"); StdRng::from_rng(rand::thread_rng()).expect("couldn't construct temporary rng");
...@@ -625,7 +626,7 @@ mod test { ...@@ -625,7 +626,7 @@ mod test {
.wait_for(builder.build_owned(p2.clone(), &params, rng)) .wait_for(builder.build_owned(p2.clone(), &params, rng))
.await; .await;
let circ = outcome.unwrap().into_inner().unwrap(); let circ = outcome.unwrap().into_inner().unwrap();
assert_eq!(circ.onehop, false); assert!(!circ.onehop);
assert_eq!( assert_eq!(
circ.hops[..], circ.hops[..],
[[0x11; 32].into(), [0x22; 32].into(), [0x33; 32].into()] [[0x11; 32].into(), [0x22; 32].into(), [0x33; 32].into()]
...@@ -634,10 +635,10 @@ mod test { ...@@ -634,10 +635,10 @@ mod test {
{ {
let mut h = timeouts.lock().unwrap(); let mut h = timeouts.lock().unwrap();
assert_eq!(h.hist.len(), 2); assert_eq!(h.hist.len(), 2);
assert_eq!(h.hist[0].0, true); // completed assert!(h.hist[0].0); // completed
assert_eq!(h.hist[0].1, 0); // last hop completed assert_eq!(h.hist[0].1, 0); // last hop completed
// TODO: test time elapsed, once wait_for is more reliable. // TODO: test time elapsed, once wait_for is more reliable.
assert_eq!(h.hist[1].0, true); // completed assert!(h.hist[1].0); // completed
assert_eq!(h.hist[1].1, 2); // last hop completed assert_eq!(h.hist[1].1, 2); // last hop completed
// TODO: test time elapsed, once wait_for is more reliable. // TODO: test time elapsed, once wait_for is more reliable.
h.hist.clear(); h.hist.clear();
...@@ -657,7 +658,7 @@ mod test { ...@@ -657,7 +658,7 @@ mod test {
{ {
let mut h = timeouts.lock().unwrap(); let mut h = timeouts.lock().unwrap();
assert_eq!(h.hist.len(), 1); assert_eq!(h.hist.len(), 1);
assert_eq!(h.hist[0].0, false); assert!(!h.hist[0].0);
assert_eq!(h.hist[0].1, 2); assert_eq!(h.hist[0].1, 2);
h.hist.clear(); h.hist.clear();
} }
...@@ -672,14 +673,14 @@ mod test { ...@@ -672,14 +673,14 @@ mod test {
assert!(outcome.is_err()); assert!(outcome.is_err());
// "wait" a while longer to make sure that we eventually // "wait" a while longer to make sure that we eventually
// notice the circuit completing. // notice the circuit completing.
for _ in 0..1000u16 { for _ in 0..1000_u16 {
rt.advance(Duration::from_millis(100)).await; rt.advance(Duration::from_millis(100)).await;
} }
{ {
let h = timeouts.lock().unwrap(); let h = timeouts.lock().unwrap();
dbg!(&h.hist); dbg!(&h.hist);
// First we notice a circuit timeout after 2 hops // First we notice a circuit timeout after 2 hops
assert_eq!(h.hist[0].0, false); assert!(!h.hist[0].0);
assert_eq!(h.hist[0].1, 2); assert_eq!(h.hist[0].1, 2);
// TODO: check timeout more closely. // TODO: check timeout more closely.
assert!(h.hist[0].2 < Duration::from_secs(100)); assert!(h.hist[0].2 < Duration::from_secs(100));
...@@ -690,7 +691,7 @@ mod test { ...@@ -690,7 +691,7 @@ mod test {
{ {
assert_eq!(h.hist.len(), 2); assert_eq!(h.hist.len(), 2);
// Then we notice a circuit completing at its third hop. // Then we notice a circuit completing at its third hop.
assert_eq!(h.hist[1].0, true); assert!(h.hist[1].0);
assert_eq!(h.hist[1].1, 2); assert_eq!(h.hist[1].1, 2);
// TODO: check timeout more closely. // TODO: check timeout more closely.
assert!(h.hist[1].2 < Duration::from_secs(100)); assert!(h.hist[1].2 < Duration::from_secs(100));
......
...@@ -316,6 +316,7 @@ async fn continually_expire_circuits<R: Runtime>(runtime: R, circmgr: Weak<CircM ...@@ -316,6 +316,7 @@ async fn continually_expire_circuits<R: Runtime>(runtime: R, circmgr: Weak<CircM
#[cfg(test)] #[cfg(test)]
mod test { mod test {
#![allow(clippy::unwrap_used)]
use super::*; use super::*;
#[test] #[test]
...@@ -326,7 +327,7 @@ mod test { ...@@ -326,7 +327,7 @@ mod test {
let di: DirInfo<'_> = (&[][..]).into(); let di: DirInfo<'_> = (&[][..]).into();
let p1 = di.circ_params(); let p1 = di.circ_params();
assert_eq!(p1.extend_by_ed25519_id(), false); assert!(!p1.extend_by_ed25519_id());
assert_eq!(p1.initial_send_window(), 1000); assert_eq!(p1.initial_send_window(), 1000);
// Now try with a directory and configured parameters. // Now try with a directory and configured parameters.
...@@ -342,7 +343,7 @@ mod test { ...@@ -342,7 +343,7 @@ mod test {
let di: DirInfo<'_> = (&netdir).into(); let di: DirInfo<'_> = (&netdir).into();
let p2 = di.circ_params(); let p2 = di.circ_params();
assert_eq!(p2.initial_send_window(), 100); assert_eq!(p2.initial_send_window(), 100);
assert_eq!(p2.extend_by_ed25519_id(), true); assert!(p2.extend_by_ed25519_id());
// Now try with a bogus circwindow value. // Now try with a bogus circwindow value.
let (consensus, microdescs) = tor_netdir::testnet::construct_network().unwrap(); let (consensus, microdescs) = tor_netdir::testnet::construct_network().unwrap();
...@@ -357,6 +358,6 @@ mod test { ...@@ -357,6 +358,6 @@ mod test {
let di: DirInfo<'_> = (&netdir).into(); let di: DirInfo<'_> = (&netdir).into();
let p2 = di.circ_params(); let p2 = di.circ_params();
assert_eq!(p2.initial_send_window(), 1000); // Not 100_000 assert_eq!(p2.initial_send_window(), 1000); // Not 100_000
assert_eq!(p2.extend_by_ed25519_id(), true); assert!(p2.extend_by_ed25519_id());
} }
} }
...@@ -1104,6 +1104,7 @@ impl<B: AbstractCircBuilder + 'static, R: Runtime> AbstractCircMgr<B, R> { ...@@ -1104,6 +1104,7 @@ impl<B: AbstractCircBuilder + 'static, R: Runtime> AbstractCircMgr<B, R> {
#[cfg(test)] #[cfg(test)]
mod test { mod test {
#![allow(clippy::unwrap_used)]
use super::*; use super::*;
use crate::Error; use crate::Error;
use std::collections::BTreeSet; use std::collections::BTreeSet;
......
...@@ -115,6 +115,7 @@ where ...@@ -115,6 +115,7 @@ where
#[cfg(test)] #[cfg(test)]
mod test { mod test {
#![allow(clippy::unwrap_used)]
use super::*; use super::*;
use futures_await_test::async_test; use futures_await_test::async_test;
......
...@@ -127,6 +127,7 @@ impl OwnedPath { ...@@ -127,6 +127,7 @@ impl OwnedPath {
/// path. /// path.
#[cfg(test)] #[cfg(test)]
fn assert_same_path_when_owned(path: &TorPath<'_>) { fn assert_same_path_when_owned(path: &TorPath<'_>) {
#![allow(clippy::unwrap_used)]
use std::convert::TryInto; use std::convert::TryInto;
use tor_linkspec::ChanTarget; use tor_linkspec::ChanTarget;
let owned: OwnedPath = path.try_into().unwrap(); let owned: OwnedPath = path.try_into().unwrap();
......
...@@ -47,6 +47,7 @@ impl DirPathBuilder { ...@@ -47,6 +47,7 @@ impl DirPathBuilder {
#[cfg(test)] #[cfg(test)]
mod test { mod test {
#![allow(clippy::unwrap_used)]
use super::*; use super::*;
use crate::path::assert_same_path_when_owned; use crate::path::assert_same_path_when_owned;
use tor_netdir::fallback::FallbackDir; use tor_netdir::fallback::FallbackDir;
......
...@@ -139,6 +139,7 @@ fn relays_can_share_circuit(a: &Relay<'_>, b: &Relay<'_>, subnet_config: &Subnet ...@@ -139,6 +139,7 @@ fn relays_can_share_circuit(a: &Relay<'_>, b: &Relay<'_>, subnet_config: &Subnet
#[cfg(test)] #[cfg(test)]
mod test { mod test {
#![allow(clippy::unwrap_used)]
use super::*; use super::*;
use crate::path::{assert_same_path_when_owned, OwnedPath, TorPathInner}; use crate::path::{assert_same_path_when_owned, OwnedPath, TorPathInner};
use std::convert::TryInto; use std::convert::TryInto;
......
...@@ -655,6 +655,7 @@ impl ParetoEstimatorInner { ...@@ -655,6 +655,7 @@ impl ParetoEstimatorInner {
#[cfg(test)] #[cfg(test)]
mod test { mod test {
#![allow(clippy::unwrap_used)]
use super::*; use super::*;
use crate::timeouts::TimeoutEstimator; use crate::timeouts::TimeoutEstimator;
...@@ -671,6 +672,7 @@ mod test { ...@@ -671,6 +672,7 @@ mod test {
#[test] #[test]
fn ms_partial_cmp() { fn ms_partial_cmp() {
#![allow(clippy::eq_op)]
let myriad: MsecDuration = 10_000.into(); let myriad: MsecDuration = 10_000.into();
let lakh: MsecDuration = 100_000.into(); let lakh: MsecDuration = 100_000.into();
let crore: MsecDuration = 10_000_000.into(); let crore: MsecDuration = 10_000_000.into();
......
...@@ -262,6 +262,7 @@ impl crate::mgr::AbstractSpec for SupportedCircUsage { ...@@ -262,6 +262,7 @@ impl crate::mgr::AbstractSpec for SupportedCircUsage {
#[cfg(test)] #[cfg(test)]
mod test { mod test {
#![allow(clippy::unwrap_used)]
use super::*; use super::*;
use tor_netdir::testnet; use tor_netdir::testnet;
......
#![allow(clippy::unwrap_used)]
//! Implement a configuration source based on command-line arguments. //! Implement a configuration source based on command-line arguments.
use config::{ConfigError, Source, Value}; use config::{ConfigError, Source, Value};
...@@ -127,6 +128,7 @@ fn tweak_toml_bareword(s: &str) -> Option<String> { ...@@ -127,6 +128,7 @@ fn tweak_toml_bareword(s: &str) -> Option<String> {
#[cfg(test)] #[cfg(test)]
mod test { mod test {
#![allow(clippy::unwrap_used)]
use super::*; use super::*;
#[test] #[test]
fn bareword_expansion() { fn bareword_expansion() {
......
...@@ -104,6 +104,7 @@ pub fn default_config_file() -> Option<PathBuf> { ...@@ -104,6 +104,7 @@ pub fn default_config_file() -> Option<PathBuf> {
#[cfg(test)] #[cfg(test)]
mod test { mod test {
#![allow(clippy::unwrap_used)]
use super::*; use super::*;
use tempfile::tempdir; use tempfile::tempdir;
......
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