Skip to content

Commit 69629c4

Browse files
authoredDec 22, 2024··
chore: fix clippy lists in tests/benchmarks (#717)
* chore: fix clippy lists in tests/benchmarks * build: extend clippy checks to tests
1 parent 90708ae commit 69629c4

File tree

4 files changed

+76
-35
lines changed

4 files changed

+76
-35
lines changed
 

‎benches/benchmark_portscan.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ fn portscan_udp(scanner: &Scanner) {
1515
}
1616

1717
fn bench_address() {
18-
let _addrs = vec!["127.0.0.1".parse::<IpAddr>().unwrap()];
18+
let _addrs = ["127.0.0.1".parse::<IpAddr>().unwrap()];
1919
}
2020

2121
fn bench_port_strategy() {
@@ -71,9 +71,9 @@ fn criterion_benchmark(c: &mut Criterion) {
7171
udp_group.finish();
7272

7373
// Benching helper functions
74-
c.bench_function("parse address", |b| b.iter(|| bench_address()));
74+
c.bench_function("parse address", |b| b.iter(bench_address));
7575

76-
c.bench_function("port strategy", |b| b.iter(|| bench_port_strategy()));
76+
c.bench_function("port strategy", |b| b.iter(bench_port_strategy));
7777
}
7878

7979
criterion_group!(benches, criterion_benchmark);

‎justfile

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
test:
22
cargo nextest run
33
cargo clippy -- --deny warnings
4+
cargo clippy --tests -- --deny warnings
45
cargo fmt --check
56
cargo doc --workspace --all-features --no-deps --document-private-items
67

‎src/address.rs

+46-18
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,11 @@ mod tests {
193193

194194
#[test]
195195
fn parse_correct_addresses() {
196-
let mut opts = Opts::default();
197-
opts.addresses = vec!["127.0.0.1".to_owned(), "192.168.0.0/30".to_owned()];
196+
let opts = Opts {
197+
addresses: vec!["127.0.0.1".to_owned(), "192.168.0.0/30".to_owned()],
198+
..Default::default()
199+
};
200+
198201
let ips = parse_addresses(&opts);
199202

200203
assert_eq!(
@@ -211,61 +214,84 @@ mod tests {
211214

212215
#[test]
213216
fn parse_correct_host_addresses() {
214-
let mut opts = Opts::default();
215-
opts.addresses = vec!["google.com".to_owned()];
217+
let opts = Opts {
218+
addresses: vec!["google.com".to_owned()],
219+
..Default::default()
220+
};
221+
216222
let ips = parse_addresses(&opts);
217223

218224
assert_eq!(ips.len(), 1);
219225
}
220226

221227
#[test]
222228
fn parse_correct_and_incorrect_addresses() {
223-
let mut opts = Opts::default();
224-
opts.addresses = vec!["127.0.0.1".to_owned(), "im_wrong".to_owned()];
229+
let opts = Opts {
230+
addresses: vec!["127.0.0.1".to_owned(), "im_wrong".to_owned()],
231+
..Default::default()
232+
};
233+
225234
let ips = parse_addresses(&opts);
226235

227236
assert_eq!(ips, [Ipv4Addr::new(127, 0, 0, 1),]);
228237
}
229238

230239
#[test]
231240
fn parse_incorrect_addresses() {
232-
let mut opts = Opts::default();
233-
opts.addresses = vec!["im_wrong".to_owned(), "300.10.1.1".to_owned()];
241+
let opts = Opts {
242+
addresses: vec!["im_wrong".to_owned(), "300.10.1.1".to_owned()],
243+
..Default::default()
244+
};
245+
234246
let ips = parse_addresses(&opts);
235247

236248
assert!(ips.is_empty());
237249
}
238250
#[test]
239251
fn parse_hosts_file_and_incorrect_hosts() {
240252
// Host file contains IP, Hosts, incorrect IPs, incorrect hosts
241-
let mut opts = Opts::default();
242-
opts.addresses = vec!["fixtures/hosts.txt".to_owned()];
253+
let opts = Opts {
254+
addresses: vec!["fixtures/hosts.txt".to_owned()],
255+
..Default::default()
256+
};
257+
243258
let ips = parse_addresses(&opts);
259+
244260
assert_eq!(ips.len(), 3);
245261
}
246262

247263
#[test]
248264
fn parse_empty_hosts_file() {
249265
// Host file contains IP, Hosts, incorrect IPs, incorrect hosts
250-
let mut opts = Opts::default();
251-
opts.addresses = vec!["fixtures/empty_hosts.txt".to_owned()];
266+
let opts = Opts {
267+
addresses: vec!["fixtures/empty_hosts.txt".to_owned()],
268+
..Default::default()
269+
};
270+
252271
let ips = parse_addresses(&opts);
272+
253273
assert_eq!(ips.len(), 0);
254274
}
255275

256276
#[test]
257277
fn parse_naughty_host_file() {
258278
// Host file contains IP, Hosts, incorrect IPs, incorrect hosts
259-
let mut opts = Opts::default();
260-
opts.addresses = vec!["fixtures/naughty_string.txt".to_owned()];
279+
let opts = Opts {
280+
addresses: vec!["fixtures/naughty_string.txt".to_owned()],
281+
..Default::default()
282+
};
283+
261284
let ips = parse_addresses(&opts);
285+
262286
assert_eq!(ips.len(), 0);
263287
}
264288

265289
#[test]
266290
fn parse_duplicate_cidrs() {
267-
let mut opts = Opts::default();
268-
opts.addresses = vec!["79.98.104.0/21".to_owned(), "79.98.104.0/24".to_owned()];
291+
let opts = Opts {
292+
addresses: vec!["79.98.104.0/21".to_owned(), "79.98.104.0/24".to_owned()],
293+
..Default::default()
294+
};
269295

270296
let ips = parse_addresses(&opts);
271297

@@ -285,9 +311,11 @@ mod tests {
285311

286312
#[test]
287313
fn resolver_args_google_dns() {
288-
let mut opts = Opts::default();
289314
// https://developers.google.com/speed/public-dns
290-
opts.resolver = Some("8.8.8.8,8.8.4.4".to_owned());
315+
let opts = Opts {
316+
resolver: Some("8.8.8.8,8.8.4.4".to_owned()),
317+
..Default::default()
318+
};
291319

292320
let resolver = get_resolver(&opts.resolver);
293321
let lookup = resolver.lookup_ip("www.example.com.").unwrap();

‎src/main.rs

+26-14
Original file line numberDiff line numberDiff line change
@@ -295,8 +295,10 @@ mod tests {
295295
#[test]
296296
#[cfg(unix)]
297297
fn batch_size_lowered() {
298-
let mut opts = Opts::default();
299-
opts.batch_size = 50_000;
298+
let opts = Opts {
299+
batch_size: 50_000,
300+
..Default::default()
301+
};
300302
let batch_size = infer_batch_size(&opts, 120);
301303

302304
assert!(batch_size < opts.batch_size);
@@ -305,8 +307,10 @@ mod tests {
305307
#[test]
306308
#[cfg(unix)]
307309
fn batch_size_lowered_average_size() {
308-
let mut opts = Opts::default();
309-
opts.batch_size = 50_000;
310+
let opts = Opts {
311+
batch_size: 50_000,
312+
..Default::default()
313+
};
310314
let batch_size = infer_batch_size(&opts, 9_000);
311315

312316
assert!(batch_size == 3_000);
@@ -316,8 +320,10 @@ mod tests {
316320
fn batch_size_equals_ulimit_lowered() {
317321
// because ulimit and batch size are same size, batch size is lowered
318322
// to ULIMIT - 100
319-
let mut opts = Opts::default();
320-
opts.batch_size = 50_000;
323+
let opts = Opts {
324+
batch_size: 50_000,
325+
..Default::default()
326+
};
321327
let batch_size = infer_batch_size(&opts, 5_000);
322328

323329
assert!(batch_size == 4_900);
@@ -326,9 +332,11 @@ mod tests {
326332
#[cfg(unix)]
327333
fn batch_size_adjusted_2000() {
328334
// ulimit == batch_size
329-
let mut opts = Opts::default();
330-
opts.batch_size = 50_000;
331-
opts.ulimit = Some(2_000);
335+
let opts = Opts {
336+
batch_size: 50_000,
337+
ulimit: Some(2_000),
338+
..Default::default()
339+
};
332340
let batch_size = adjust_ulimit_size(&opts);
333341

334342
assert!(batch_size == 2_000);
@@ -337,9 +345,11 @@ mod tests {
337345
#[test]
338346
#[cfg(unix)]
339347
fn test_high_ulimit_no_greppable_mode() {
340-
let mut opts = Opts::default();
341-
opts.batch_size = 10;
342-
opts.greppable = false;
348+
let opts = Opts {
349+
batch_size: 10,
350+
greppable: false,
351+
..Default::default()
352+
};
343353

344354
let batch_size = infer_batch_size(&opts, 1_000_000);
345355

@@ -348,8 +358,10 @@ mod tests {
348358

349359
#[test]
350360
fn test_print_opening_no_panic() {
351-
let mut opts = Opts::default();
352-
opts.ulimit = Some(2_000);
361+
let opts = Opts {
362+
ulimit: Some(2_000),
363+
..Default::default()
364+
};
353365
// print opening should not panic
354366
print_opening(&opts);
355367
}

0 commit comments

Comments
 (0)
Please sign in to comment.