fix clippy issues in tests and add it to CI

This commit is contained in:
Marcel Märtens 2020-07-01 00:01:09 +02:00
parent 6535fa5744
commit e1b27c51f5
8 changed files with 30 additions and 31 deletions

View File

@ -11,6 +11,7 @@ code-quality:
script: script:
- ln -s /dockercache/cache-all target - ln -s /dockercache/cache-all target
- cargo clippy -- -D warnings - cargo clippy -- -D warnings
- cargo clippy --tests -- -D warnings
- cargo fmt --all -- --check - cargo fmt --all -- --check
security: security:

View File

@ -384,7 +384,7 @@ mod tests {
assert_eq!(sword, loadout.second_item); assert_eq!(sword, loadout.second_item);
// Verify inventory // Verify inventory
assert_eq!(inv.slots[0], Some(sword.clone().unwrap().item)); assert_eq!(inv.slots[0], Some(sword.unwrap().item));
assert_eq!(inv.slots.len(), 1); assert_eq!(inv.slots.len(), 1);
} }
@ -459,7 +459,7 @@ mod tests {
// The swap should return the sword // The swap should return the sword
assert_eq!( assert_eq!(
Some(sword.clone().unwrap().item), Some(sword.unwrap().item),
loadout_remove(EquipSlot::Mainhand, &mut loadout,) loadout_remove(EquipSlot::Mainhand, &mut loadout,)
); );

View File

@ -138,9 +138,9 @@ mod tests {
assert_eq!(mb.data[0], 3); assert_eq!(mb.data[0], 3);
assert_eq!(mb.data[1], 0); assert_eq!(mb.data[1], 0);
assert_eq!(mb.data[7], 0); assert_eq!(mb.data[7], 0);
assert_eq!(mb.data[8], 'a' as u8); assert_eq!(mb.data[8], b'a');
assert_eq!(mb.data[8], 97); assert_eq!(mb.data[8], 97);
assert_eq!(mb.data[9], 'b' as u8); assert_eq!(mb.data[9], b'b');
assert_eq!(mb.data[10], 'c' as u8); assert_eq!(mb.data[10], b'c');
} }
} }

View File

@ -353,8 +353,8 @@ mod tests {
#[test] #[test]
fn pid_cid_frame_cache() { fn pid_cid_frame_cache() {
let pid = Pid::fake(1); let pid = Pid::fake(1);
let frame1 = Frame::Raw("Foo".as_bytes().to_vec()); let frame1 = Frame::Raw(b"Foo".to_vec());
let frame2 = Frame::Raw("Bar".as_bytes().to_vec()); let frame2 = Frame::Raw(b"Bar".to_vec());
let metrics = NetworkMetrics::new(&pid).unwrap(); let metrics = NetworkMetrics::new(&pid).unwrap();
let mut cache = PidCidFrameCache::new(metrics.frames_in_total, pid); let mut cache = PidCidFrameCache::new(metrics.frames_in_total, pid);
let v1 = cache.with_label_values(1, &frame1); let v1 = cache.with_label_values(1, &frame1);
@ -377,8 +377,8 @@ mod tests {
#[test] #[test]
fn cid_frame_cache() { fn cid_frame_cache() {
let pid = Pid::fake(1); let pid = Pid::fake(1);
let frame1 = Frame::Raw("Foo".as_bytes().to_vec()); let frame1 = Frame::Raw(b"Foo".to_vec());
let frame2 = Frame::Raw("Bar".as_bytes().to_vec()); let frame2 = Frame::Raw(b"Bar".to_vec());
let metrics = NetworkMetrics::new(&pid).unwrap(); let metrics = NetworkMetrics::new(&pid).unwrap();
let mut cache = CidFrameCache::new(metrics.frames_wire_out_total, 1); let mut cache = CidFrameCache::new(metrics.frames_wire_out_total, 1);
let v1 = cache.with_label_values(&frame1); let v1 = cache.with_label_values(&frame1);

View File

@ -327,6 +327,7 @@ mod tests {
const SIZE: u64 = PrioManager::FRAME_DATA_SIZE; const SIZE: u64 = PrioManager::FRAME_DATA_SIZE;
const USIZE: usize = PrioManager::FRAME_DATA_SIZE as usize; const USIZE: usize = PrioManager::FRAME_DATA_SIZE as usize;
#[allow(clippy::type_complexity)]
fn mock_new() -> ( fn mock_new() -> (
PrioManager, PrioManager,
Sender<(Prio, Sid, OutgoingMessage)>, Sender<(Prio, Sid, OutgoingMessage)>,
@ -605,10 +606,10 @@ mod tests {
fn gigantic_message() { fn gigantic_message() {
let (mut mgr, msg_tx, _flush_tx) = mock_new(); let (mut mgr, msg_tx, _flush_tx) = mock_new();
let mut data = vec![1; USIZE]; let mut data = vec![1; USIZE];
data.extend_from_slice(&vec![2; USIZE]); data.extend_from_slice(&[2; USIZE]);
data.extend_from_slice(&vec![3; USIZE]); data.extend_from_slice(&[3; USIZE]);
data.extend_from_slice(&vec![4; USIZE]); data.extend_from_slice(&[4; USIZE]);
data.extend_from_slice(&vec![5; USIZE]); data.extend_from_slice(&[5; USIZE]);
let sid = Sid::new(2); let sid = Sid::new(2);
msg_tx msg_tx
.send((16, sid, OutgoingMessage { .send((16, sid, OutgoingMessage {
@ -634,10 +635,10 @@ mod tests {
fn gigantic_message_order() { fn gigantic_message_order() {
let (mut mgr, msg_tx, _flush_tx) = mock_new(); let (mut mgr, msg_tx, _flush_tx) = mock_new();
let mut data = vec![1; USIZE]; let mut data = vec![1; USIZE];
data.extend_from_slice(&vec![2; USIZE]); data.extend_from_slice(&[2; USIZE]);
data.extend_from_slice(&vec![3; USIZE]); data.extend_from_slice(&[3; USIZE]);
data.extend_from_slice(&vec![4; USIZE]); data.extend_from_slice(&[4; USIZE]);
data.extend_from_slice(&vec![5; USIZE]); data.extend_from_slice(&[5; USIZE]);
let sid = Sid::new(2); let sid = Sid::new(2);
msg_tx msg_tx
.send((16, sid, OutgoingMessage { .send((16, sid, OutgoingMessage {
@ -666,10 +667,10 @@ mod tests {
fn gigantic_message_order_other_prio() { fn gigantic_message_order_other_prio() {
let (mut mgr, msg_tx, _flush_tx) = mock_new(); let (mut mgr, msg_tx, _flush_tx) = mock_new();
let mut data = vec![1; USIZE]; let mut data = vec![1; USIZE];
data.extend_from_slice(&vec![2; USIZE]); data.extend_from_slice(&[2; USIZE]);
data.extend_from_slice(&vec![3; USIZE]); data.extend_from_slice(&[3; USIZE]);
data.extend_from_slice(&vec![4; USIZE]); data.extend_from_slice(&[4; USIZE]);
data.extend_from_slice(&vec![5; USIZE]); data.extend_from_slice(&[5; USIZE]);
let sid = Sid::new(2); let sid = Sid::new(2);
msg_tx msg_tx
.send((16, sid, OutgoingMessage { .send((16, sid, OutgoingMessage {

View File

@ -322,7 +322,7 @@ mod tests {
#[test] #[test]
fn frame_get_int() { fn frame_get_int() {
assert_eq!(Frame::get_int(&Frame::Raw("Foo".as_bytes().to_vec())), 7); assert_eq!(Frame::get_int(&Frame::Raw(b"Foo".to_vec())), 7);
assert_eq!(Frame::get_int(&Frame::Shutdown), 2); assert_eq!(Frame::get_int(&Frame::Shutdown), 2);
} }

View File

@ -101,11 +101,11 @@ fn failed_listen_on_used_ports() -> std::result::Result<(), Box<dyn std::error::
let e2 = block_on(network2.listen(tcp1)); let e2 = block_on(network2.listen(tcp1));
match e1 { match e1 {
Err(NetworkError::ListenFailed(e)) if e.kind() == ErrorKind::AddrInUse => (), Err(NetworkError::ListenFailed(e)) if e.kind() == ErrorKind::AddrInUse => (),
_ => assert!(false), _ => panic!(),
}; };
match e2 { match e2 {
Err(NetworkError::ListenFailed(e)) if e.kind() == ErrorKind::AddrInUse => (), Err(NetworkError::ListenFailed(e)) if e.kind() == ErrorKind::AddrInUse => (),
_ => assert!(false), _ => panic!(),
}; };
Ok(()) Ok(())
} }
@ -178,7 +178,7 @@ fn wrong_parse() {
s1_a.send(1337).unwrap(); s1_a.send(1337).unwrap();
match block_on(s1_b.recv::<String>()) { match block_on(s1_b.recv::<String>()) {
Err(StreamError::DeserializeError(_)) => assert!(true), Err(StreamError::DeserializeError(_)) => (),
_ => assert!(false, "this should fail, but it doesnt!"), _ => panic!("this should fail, but it doesnt!"),
} }
} }

View File

@ -81,15 +81,12 @@ fn generate_key_version<'a>(
.map(|k| (k.to_owned(), LocalizationEntryState::new())) .map(|k| (k.to_owned(), LocalizationEntryState::new()))
.collect(); .collect();
let mut to_process: HashSet<&String> = localization.string_map.keys().map(|k| k).collect(); let mut to_process: HashSet<&String> = localization.string_map.keys().map(|k| k).collect();
let mut line_nb = 0;
// Find key start lines // Find key start lines
for line in std::str::from_utf8(file_blob.content()) for (line_nb, line) in std::str::from_utf8(file_blob.content())
.expect("UTF-8 file") .expect("UTF-8 file")
.split('\n') .split('\n')
.enumerate()
{ {
line_nb += 1;
let mut found_key = None; let mut found_key = None;
for key in to_process.iter() { for key in to_process.iter() {