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

fix/silence clippy lints in test modules

parent 9cf1fa36
......@@ -418,6 +418,7 @@ impl<'a> Iterator for AuthCertIterator<'a> {
#[cfg(test)]
mod test {
#![allow(clippy::unwrap_used)]
use super::*;
use crate::{Error, Pos};
const TESTDATA: &str = include_str!("../../testdata/authcert1.txt");
......@@ -446,29 +447,29 @@ mod test {
#[test]
fn parse_bad() {
fn check(fname: &str, err: Error) {
fn check(fname: &str, err: &Error) {
let contents = bad_data(fname);
let cert = AuthCert::parse(&contents);
assert!(cert.is_err());
assert_eq!(cert.err().unwrap(), err);
assert_eq!(&cert.err().unwrap(), err);
}
check("bad-cc-tag", Error::WrongObject(Pos::from_line(27, 12)));
check("bad-cc-tag", &Error::WrongObject(Pos::from_line(27, 12)));
check(
"bad-fingerprint",
Error::BadArgument(
&Error::BadArgument(
Pos::from_line(2, 1),
"fingerprint does not match RSA identity".into(),
),
);
check("bad-version", Error::BadDocumentVersion(4));
check("bad-version", &Error::BadDocumentVersion(4));
check(
"wrong-end",
Error::WrongEndingToken("dir-key-crosscert".into(), Pos::from_line(37, 1)),
&Error::WrongEndingToken("dir-key-crosscert".into(), Pos::from_line(37, 1)),
);
check(
"wrong-start",
Error::WrongStartingToken("fingerprint".into(), Pos::from_line(1, 1)),
&Error::WrongStartingToken("fingerprint".into(), Pos::from_line(1, 1)),
);
}
......
......@@ -129,6 +129,7 @@ impl AuthCertBuilder {
#[cfg(test)]
mod test {
#![allow(clippy::unwrap_used)]
use super::*;
use hex_literal::hex;
use std::time::Duration;
......
......@@ -444,6 +444,7 @@ impl<'a> Iterator for MicrodescReader<'a> {
#[cfg(test)]
mod test {
#![allow(clippy::unwrap_used)]
use super::*;
use hex_literal::hex;
const TESTDATA: &str = include_str!("../../testdata/microdesc1.txt");
......@@ -502,20 +503,20 @@ mod test {
fn test_bad() {
use crate::types::policy::PolicyError;
use crate::Pos;
fn check(fname: &str, e: Error) {
fn check(fname: &str, e: &Error) {
let content = read_bad(fname);
let res = Microdesc::parse(&content);
assert!(res.is_err());
assert_eq!(res.err().unwrap(), e);
assert_eq!(&res.err().unwrap(), e);
}
check(
"wrong-start",
Error::WrongStartingToken("family".into(), Pos::from_line(1, 1)),
&Error::WrongStartingToken("family".into(), Pos::from_line(1, 1)),
);
check(
"bogus-policy",
Error::BadPolicy(Pos::from_line(9, 1), PolicyError::InvalidPort),
&Error::BadPolicy(Pos::from_line(9, 1), PolicyError::InvalidPort),
);
}
......
......@@ -165,6 +165,7 @@ impl MicrodescBuilder {
#[cfg(test)]
mod test {
#![allow(clippy::unwrap_used)]
use super::*;
use hex_literal::hex;
......
......@@ -1538,6 +1538,7 @@ impl SignatureGroup {
#[cfg(test)]
mod test {
#![allow(clippy::unwrap_used)]
use super::*;
use hex_literal::hex;
......@@ -1611,8 +1612,8 @@ mod test {
r0.rsa_identity().as_bytes(),
&hex!("0a3057af2910415794d8ea430309d9ac5f5d524b")
);
assert_eq!(r0.weight().is_measured(), false);
assert_eq!(r0.weight().is_nonzero(), false);
assert!(!r0.weight().is_measured());
assert!(!r0.weight().is_nonzero());
let pv = &r0.protovers();
assert!(pv.supports_subver("HSDir", 2));
assert!(!pv.supports_subver("HSDir", 3));
......@@ -1652,41 +1653,41 @@ mod test {
#[test]
fn test_bad() {
use crate::Pos;
fn check(fname: &str, e: Error) {
fn check(fname: &str, e: &Error) {
let content = read_bad(fname);
let res = MdConsensus::parse(&content);
assert!(res.is_err());
assert_eq!(res.err().unwrap(), e);
assert_eq!(&res.err().unwrap(), e);
}
check(
"bad-flags",
Error::BadArgument(Pos::from_line(27, 1), "Flags out of order".into()),
&Error::BadArgument(Pos::from_line(27, 1), "Flags out of order".into()),
);
check(
"bad-md-digest",
Error::BadArgument(Pos::from_line(40, 3), "Invalid base64".into()),
&Error::BadArgument(Pos::from_line(40, 3), "Invalid base64".into()),
);
check(
"bad-weight",
Error::BadArgument(
&Error::BadArgument(
Pos::from_line(67, 141),
"invalid digit found in string".into(),
),
);
check(
"bad-weights",
Error::BadArgument(
&Error::BadArgument(
Pos::from_line(51, 13),
"invalid digit found in string".into(),
),
);
check("wrong-order", Error::WrongSortOrder(Pos::from_line(52, 1)));
check("wrong-order", &Error::WrongSortOrder(Pos::from_line(52, 1)));
check(
"wrong-start",
Error::UnexpectedToken("vote-status", Pos::from_line(1, 1)),
&Error::UnexpectedToken("vote-status", Pos::from_line(1, 1)),
);
check("wrong-version", Error::BadDocumentVersion(10));
check("wrong-version", &Error::BadDocumentVersion(10));
}
fn gettok(s: &str) -> Result<Item<'_, NetstatusKwd>> {
......
......@@ -385,6 +385,7 @@ impl VoterInfoBuilder {
#[cfg(test)]
mod test {
#![allow(clippy::unwrap_used)]
use super::*;
use crate::doc::netstatus::RelayFlags;
......
......@@ -765,6 +765,7 @@ impl<'a> Iterator for RouterReader<'a> {
#[cfg(test)]
mod test {
#![allow(clippy::unwrap_used)]
use super::*;
const TESTDATA: &str = include_str!("../../testdata/routerdesc1.txt");
......@@ -800,38 +801,38 @@ mod test {
fn test_bad() {
use crate::types::policy::PolicyError;
use crate::Pos;
fn check(fname: &str, e: Error) {
fn check(fname: &str, e: &Error) {
let text = read_bad(fname);
let rd = RouterDesc::parse(&text);
assert!(rd.is_err());
assert_eq!(rd.err().unwrap(), e);
assert_eq!(&rd.err().unwrap(), e);
}
check(
"bad-sig-order",
Error::UnexpectedToken("router-sig-ed25519", Pos::from_line(50, 1)),
&Error::UnexpectedToken("router-sig-ed25519", Pos::from_line(50, 1)),
);
check(
"bad-start1",
Error::MisplacedToken("identity-ed25519", Pos::from_line(1, 1)),
&Error::MisplacedToken("identity-ed25519", Pos::from_line(1, 1)),
);
check("bad-start2", Error::MissingToken("identity-ed25519"));
check("bad-start2", &Error::MissingToken("identity-ed25519"));
check(
"mismatched-fp",
Error::BadArgument(
&Error::BadArgument(
Pos::from_line(12, 1),
"fingerprint does not match RSA identity".into(),
),
);
check("no-ed-sk", Error::MissingToken("identity-ed25519"));
check("no-ed-sk", &Error::MissingToken("identity-ed25519"));
check(
"bad-cc-sign",
Error::BadArgument(Pos::from_line(34, 26), "not 0 or 1".into()),
&Error::BadArgument(Pos::from_line(34, 26), "not 0 or 1".into()),
);
check(
"bad-ipv6policy",
Error::BadPolicy(Pos::from_line(43, 1), PolicyError::InvalidPolicy),
&Error::BadPolicy(Pos::from_line(43, 1), PolicyError::InvalidPolicy),
);
}
......
......@@ -295,6 +295,7 @@ impl<T: Keyword> SectionRules<T> {
#[cfg(test)]
mod test {
#![allow(clippy::unwrap_used)]
use super::SectionRules;
use crate::parse::keyword::Keyword;
use crate::parse::macros::test::Fruit;
......@@ -370,43 +371,43 @@ lemon
#[test]
fn rejected() {
use crate::Pos;
fn check(s: &str, e: Error) {
fn check(s: &str, e: &Error) {
let mut r: NetDocReader<'_, Fruit> = NetDocReader::new(s);
let res = FRUIT_SALAD.parse(&mut r.iter());
assert!(res.is_err());
assert_eq!(res.err().unwrap().within(s), e);
assert_eq!(&res.err().unwrap().within(s), e);
}
// unrecognized tokens aren't allowed here
check(
"orange foo\nfoobar x\n@tasty yes\n",
Error::UnexpectedToken("<unrecognized>", Pos::from_line(2, 1)),
&Error::UnexpectedToken("<unrecognized>", Pos::from_line(2, 1)),
);
// Only one orange per customer.
check(
"@tasty yes\norange foo\norange bar\n",
Error::DuplicateToken("orange", Pos::from_line(3, 1)),
&Error::DuplicateToken("orange", Pos::from_line(3, 1)),
);
// There needs to be a declaration of tastiness.
check("orange foo\n", Error::MissingToken("@tasty"));
check("orange foo\n", &Error::MissingToken("@tasty"));
// You can't have an orange without an argument.
check(
"@tasty nope\norange\n",
Error::TooFewArguments("orange", Pos::from_line(2, 1)),
&Error::TooFewArguments("orange", Pos::from_line(2, 1)),
);
// You can't have an more than one argument on "tasty".
check(
"@tasty yup indeed\norange normal\n",
Error::TooManyArguments("@tasty", Pos::from_line(1, 1)),
&Error::TooManyArguments("@tasty", Pos::from_line(1, 1)),
);
// Every lemon needs an object
check(
"@tasty yes\nlemon\norange no\n",
Error::MissingObject("lemon", Pos::from_line(2, 1)),
&Error::MissingObject("lemon", Pos::from_line(2, 1)),
);
}
}
......@@ -652,6 +652,7 @@ impl<'a, K: Keyword> NetDocReader<'a, K> {
#[cfg(test)]
mod test {
#![allow(clippy::unwrap_used)]
use super::*;
use crate::parse::macros::test::Fruit;
use crate::{Error, Pos, Result};
......
......@@ -60,6 +60,7 @@ impl std::str::FromStr for RelayFamily {
#[cfg(test)]
mod test {
#![allow(clippy::unwrap_used)]
use super::*;
use crate::Result;
#[test]
......
......@@ -373,6 +373,7 @@ mod fingerprint {
#[cfg(test)]
mod test {
#![allow(clippy::unwrap_used)]
use super::*;
use crate::Result;
......
......@@ -162,6 +162,7 @@ impl FromStr for PortRange {
#[cfg(test)]
mod test {
#![allow(clippy::unwrap_used)]
use super::*;
use crate::Result;
#[test]
......
......@@ -283,6 +283,7 @@ impl FromStr for IpPattern {
#[cfg(test)]
mod test {
#![allow(clippy::unwrap_used)]
use super::*;
#[test]
......
......@@ -159,6 +159,7 @@ static POLICY_CACHE: InternCache<PortPolicy> = InternCache::new();
#[cfg(test)]
mod test {
#![allow(clippy::unwrap_used)]
use super::*;
#[test]
......
......@@ -179,6 +179,7 @@ impl FromStr for TorVersion {
#[cfg(test)]
mod test {
#![allow(clippy::unwrap_used)]
use super::*;
#[test]
......
......@@ -91,6 +91,8 @@ impl Extent {
#[cfg(test)]
mod test {
#![allow(clippy::unwrap_used)]
#[test]
fn test_str_offset() {
use super::str_offset;
......
......@@ -250,6 +250,7 @@ impl From<std::io::Error> for Error {
#[cfg(test)]
mod test {
#![allow(clippy::unwrap_used)]
use super::*;
use std::collections::HashMap;
......
......@@ -449,6 +449,7 @@ impl Drop for CircDestroyHandle {
pub(crate) mod test {
// Most of this module is tested via tests that also check on the
// reactor code; there are just a few more cases to examine here.
#![allow(clippy::unwrap_used)]
use super::*;
use crate::channel::codec::test::MsgBuf;
use crate::channel::reactor::test::new_reactor;
......
......@@ -174,6 +174,7 @@ impl CircMap {
#[cfg(test)]
mod test {
#![allow(clippy::unwrap_used)]
use super::*;
use futures::channel::{mpsc, oneshot};
......
......@@ -40,6 +40,7 @@ impl futures_codec::Decoder for ChannelCodec {
#[cfg(test)]
pub(crate) mod test {
#![allow(clippy::unwrap_used)]
use futures::io::{AsyncRead, AsyncWrite, Cursor, Result};
use futures::sink::SinkExt;
use futures::stream::StreamExt;
......
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