Run clippy on tests and examples

This commit is contained in:
Floris Bruynooghe
2020-09-05 17:39:53 +02:00
parent 11b9a933b0
commit ee27c7d9d4
15 changed files with 38 additions and 28 deletions

View File

@@ -38,7 +38,7 @@ jobs:
- uses: actions-rs/clippy-check@v1 - uses: actions-rs/clippy-check@v1
with: with:
token: ${{ secrets.GITHUB_TOKEN }} token: ${{ secrets.GITHUB_TOKEN }}
args: --all args: --workspace --tests --examples
build_and_test: build_and_test:

View File

@@ -685,7 +685,7 @@ mod tests {
let (stem, ext) = BlobObject::sanitise_name("foo?.bar"); let (stem, ext) = BlobObject::sanitise_name("foo?.bar");
assert!(stem.contains("foo")); assert!(stem.contains("foo"));
assert!(!stem.contains("?")); assert!(!stem.contains('?'));
assert_eq!(ext, ".bar"); assert_eq!(ext, ".bar");
let (stem, ext) = BlobObject::sanitise_name("no-extension"); let (stem, ext) = BlobObject::sanitise_name("no-extension");
@@ -698,10 +698,10 @@ mod tests {
assert!(!stem.contains("ignored")); assert!(!stem.contains("ignored"));
assert!(stem.contains("this")); assert!(stem.contains("this"));
assert!(stem.contains("forbidden")); assert!(stem.contains("forbidden"));
assert!(!stem.contains("/")); assert!(!stem.contains('/'));
assert!(!stem.contains("\\")); assert!(!stem.contains('\\'));
assert!(!stem.contains(":")); assert!(!stem.contains(':'));
assert!(!stem.contains("*")); assert!(!stem.contains('*'));
assert!(!stem.contains("?")); assert!(!stem.contains('?'));
} }
} }

View File

@@ -268,6 +268,8 @@ pub(crate) async fn moz_autoconfigure(
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
#![allow(clippy::indexing_slicing)]
use super::*; use super::*;
#[test] #[test]

View File

@@ -209,6 +209,8 @@ pub(crate) async fn outlk_autodiscover(
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
#![allow(clippy::indexing_slicing)]
use super::*; use super::*;
#[test] #[test]

View File

@@ -498,6 +498,7 @@ pub enum Error {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
#![allow(clippy::indexing_slicing)]
use super::*; use super::*;
use crate::config::*; use crate::config::*;

View File

@@ -573,7 +573,7 @@ mod tests {
let tmp = tempfile::tempdir().unwrap(); let tmp = tempfile::tempdir().unwrap();
let dbfile = tmp.path().join("db.sqlite"); let dbfile = tmp.path().join("db.sqlite");
let blobdir = PathBuf::new(); let blobdir = PathBuf::new();
let res = Context::with_blobdir("FakeOS".into(), dbfile.into(), blobdir.into(), 1).await; let res = Context::with_blobdir("FakeOS".into(), dbfile.into(), blobdir, 1).await;
assert!(res.is_err()); assert!(res.is_err());
} }

View File

@@ -2213,7 +2213,7 @@ mod tests {
} else { } else {
panic!("Wrong item type"); panic!("Wrong item type");
}; };
let msg = message::Message::load_from_db(&t.ctx, msg_id.clone()) let msg = message::Message::load_from_db(&t.ctx, *msg_id)
.await .await
.unwrap(); .unwrap();
assert_eq!(msg.is_dc_message, MessengerMessage::Yes); assert_eq!(msg.is_dc_message, MessengerMessage::Yes);
@@ -2264,7 +2264,7 @@ mod tests {
chat::get_chat_msgs(&t.ctx, group_id, 0, None).await.len(), chat::get_chat_msgs(&t.ctx, group_id, 0, None).await.len(),
1 1
); );
let msg = message::Message::load_from_db(&t.ctx, msg_id.clone()) let msg = message::Message::load_from_db(&t.ctx, *msg_id)
.await .await
.unwrap(); .unwrap();
assert_eq!(msg.state, MessageState::OutMdnRcvd); assert_eq!(msg.state, MessageState::OutMdnRcvd);
@@ -2352,7 +2352,7 @@ mod tests {
} else { } else {
panic!("Wrong item type"); panic!("Wrong item type");
}; };
let msg = message::Message::load_from_db(&t.ctx, msg_id.clone()) let msg = message::Message::load_from_db(&t.ctx, *msg_id)
.await .await
.unwrap(); .unwrap();
assert_eq!(msg.is_dc_message, MessengerMessage::Yes); assert_eq!(msg.is_dc_message, MessengerMessage::Yes);

View File

@@ -639,6 +639,8 @@ pub(crate) fn improve_single_line_input(input: impl AsRef<str>) -> String {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
#![allow(clippy::indexing_slicing)]
use super::*; use super::*;
use std::convert::TryInto; use std::convert::TryInto;

View File

@@ -529,11 +529,11 @@ i8pcjGO+IZffvyZJVRWfVooBJmWWbPB1pueo3tx8w3+fcuzpxz+RLFKaPyqXO+dD
#[test] #[test]
fn test_from_slice_bad_data() { fn test_from_slice_bad_data() {
let mut bad_data: [u8; 4096] = [0; 4096]; let mut bad_data: [u8; 4096] = [0; 4096];
for i in 0..4096 { for (i, v) in bad_data.iter_mut().enumerate() {
bad_data[i] = (i & 0xff) as u8; *v = (i & 0xff) as u8;
} }
for j in 0..(4096 / 40) { for j in 0..(4096 / 40) {
let slice = &bad_data[j..j + 4096 / 2 + j]; let slice = &bad_data.get(j..j + 4096 / 2 + j).unwrap();
assert!(SignedPublicKey::from_slice(slice).is_err()); assert!(SignedPublicKey::from_slice(slice).is_err());
assert!(SignedSecretKey::from_slice(slice).is_err()); assert!(SignedSecretKey::from_slice(slice).is_err());
} }
@@ -593,7 +593,7 @@ i8pcjGO+IZffvyZJVRWfVooBJmWWbPB1pueo3tx8w3+fcuzpxz+RLFKaPyqXO+dD
let ctx0 = ctx.clone(); let ctx0 = ctx.clone();
let thr0 = let thr0 =
thread::spawn(move || async_std::task::block_on(SignedPublicKey::load_self(&ctx0))); thread::spawn(move || async_std::task::block_on(SignedPublicKey::load_self(&ctx0)));
let ctx1 = ctx.clone(); let ctx1 = ctx;
let thr1 = let thr1 =
thread::spawn(move || async_std::task::block_on(SignedPublicKey::load_self(&ctx1))); thread::spawn(move || async_std::task::block_on(SignedPublicKey::load_self(&ctx1)));
let res0 = thr0.join().unwrap(); let res0 = thr0.join().unwrap();

View File

@@ -723,6 +723,8 @@ pub(crate) async fn job_maybe_send_locations_ended(
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
#![allow(clippy::indexing_slicing)]
use super::*; use super::*;
use crate::test_utils::TestContext; use crate::test_utils::TestContext;
@@ -772,7 +774,7 @@ mod tests {
assert!(locations_ref[0].latitude < 51.423724f64); assert!(locations_ref[0].latitude < 51.423724f64);
assert!(locations_ref[0].longitude >= 8.552556f64); assert!(locations_ref[0].longitude >= 8.552556f64);
assert!(locations_ref[0].longitude < 8.552557f64); assert!(locations_ref[0].longitude < 8.552557f64);
assert_eq!(locations_ref[0].accuracy, 0.0f64); assert!(locations_ref[0].accuracy.abs() < f64::EPSILON);
assert_eq!(locations_ref[0].timestamp, timestamp); assert_eq!(locations_ref[0].timestamp, timestamp);
} }
} }

View File

@@ -1893,8 +1893,7 @@ mod tests {
); );
assert_eq!( assert_eq!(
get_summarytext_by_raw(Viewtype::Voice, no_text.as_ref(), &mut some_file, 50, &ctx) get_summarytext_by_raw(Viewtype::Voice, no_text.as_ref(), &some_file, 50, &ctx).await,
.await,
"Voice message" // file names are not added for voice messages "Voice message" // file names are not added for voice messages
); );
@@ -1904,8 +1903,7 @@ mod tests {
); );
assert_eq!( assert_eq!(
get_summarytext_by_raw(Viewtype::Audio, no_text.as_ref(), &mut some_file, 50, &ctx) get_summarytext_by_raw(Viewtype::Audio, no_text.as_ref(), &some_file, 50, &ctx).await,
.await,
"Audio \u{2013} foo.bar" // file name is added for audio "Audio \u{2013} foo.bar" // file name is added for audio
); );
@@ -1921,8 +1919,7 @@ mod tests {
); );
assert_eq!( assert_eq!(
get_summarytext_by_raw(Viewtype::File, some_text.as_ref(), &mut some_file, 50, &ctx) get_summarytext_by_raw(Viewtype::File, some_text.as_ref(), &some_file, 50, &ctx).await,
.await,
"File \u{2013} foo.bar \u{2013} bla bla" // file name is added for files "File \u{2013} foo.bar \u{2013} bla bla" // file name is added for files
); );
@@ -1930,7 +1927,7 @@ mod tests {
asm_file.set(Param::File, "foo.bar"); asm_file.set(Param::File, "foo.bar");
asm_file.set_cmd(SystemMessage::AutocryptSetupMessage); asm_file.set_cmd(SystemMessage::AutocryptSetupMessage);
assert_eq!( assert_eq!(
get_summarytext_by_raw(Viewtype::File, no_text.as_ref(), &mut asm_file, 50, &ctx).await, get_summarytext_by_raw(Viewtype::File, no_text.as_ref(), &asm_file, 50, &ctx).await,
"Autocrypt Setup Message" // file name is not added for autocrypt setup messages "Autocrypt Setup Message" // file name is not added for autocrypt setup messages
); );
} }
@@ -2007,7 +2004,7 @@ mod tests {
let chatitems = chat::get_chat_msgs(&t.ctx, device_chat_id, 0, None).await; let chatitems = chat::get_chat_msgs(&t.ctx, device_chat_id, 0, None).await;
for chatitem in chatitems { for chatitem in chatitems {
if let ChatItem::Message { msg_id } = chatitem { if let ChatItem::Message { msg_id } = chatitem {
if let Ok(msg) = Message::load_from_db(&t.ctx, msg_id.clone()).await { if let Ok(msg) = Message::load_from_db(&t.ctx, msg_id).await {
if msg.get_viewtype() == Viewtype::Image { if msg.get_viewtype() == Viewtype::Image {
has_image = true; has_image = true;
// just check that width/height are inside some reasonable ranges // just check that width/height are inside some reasonable ranges

View File

@@ -1318,6 +1318,8 @@ where
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
#![allow(clippy::indexing_slicing)]
use super::*; use super::*;
use crate::test_utils::*; use crate::test_utils::*;

View File

@@ -475,8 +475,8 @@ mod tests {
); );
// Blob in blobdir, expect blob. // Blob in blobdir, expect blob.
let bar = t.ctx.get_blobdir().join("bar"); let bar_path = t.ctx.get_blobdir().join("bar");
p.set(Param::File, bar.to_str().unwrap()); p.set(Param::File, bar_path.to_str().unwrap());
let blob = p let blob = p
.get_blob(Param::File, &t.ctx, false) .get_blob(Param::File, &t.ctx, false)
.await .await

View File

@@ -439,9 +439,9 @@ mod tests {
let bob = bob_keypair(); let bob = bob_keypair();
TestKeys { TestKeys {
alice_secret: alice.secret.clone(), alice_secret: alice.secret.clone(),
alice_public: alice.public.clone(), alice_public: alice.public,
bob_secret: bob.secret.clone(), bob_secret: bob.secret.clone(),
bob_public: bob.public.clone(), bob_public: bob.public,
} }
} }
} }

View File

@@ -93,6 +93,8 @@ pub fn get_provider_info(addr: &str) -> Option<&Provider> {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
#![allow(clippy::indexing_slicing)]
use super::*; use super::*;
#[test] #[test]