Skip to content

Commit a77a71c

Browse files
committed
clippy on tests and thanks clippy
1 parent e1964e4 commit a77a71c

File tree

26 files changed

+160
-170
lines changed

26 files changed

+160
-170
lines changed

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,9 @@ doc: ## Run cargo doc on all crates
6868
cargo doc --features=max,lean,light,small
6969

7070
clippy: ## Run cargo clippy on all crates
71-
cargo clippy --all
71+
cargo clippy --all --tests
7272
cargo clippy --all --no-default-features --features small
73-
cargo clippy --all --no-default-features --features light-async
73+
cargo clippy --all --no-default-features --features light-async --tests
7474

7575
check: ## Build all code in suitable configurations
7676
cargo check --all

git-actor/tests/mutable/signature.rs

Lines changed: 51 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -38,66 +38,65 @@ mod time {
3838
}
3939
}
4040

41-
mod signature {
42-
mod write_to {
43-
mod invalid {
44-
use git_actor::{Sign, Signature, Time};
41+
mod write_to {
42+
mod invalid {
43+
use git_actor::{Sign, Signature, Time};
4544

46-
#[test]
47-
fn name() {
48-
let signature = Signature {
49-
name: "invalid < middlename".into(),
50-
email: "ok".into(),
51-
time: default_time(),
52-
};
53-
assert_eq!(
54-
format!("{:?}", signature.write_to(Vec::new())),
55-
"Err(Custom { kind: Other, error: IllegalCharacter })"
56-
);
57-
}
45+
#[test]
46+
fn name() {
47+
let signature = Signature {
48+
name: "invalid < middlename".into(),
49+
email: "ok".into(),
50+
time: default_time(),
51+
};
52+
assert_eq!(
53+
format!("{:?}", signature.write_to(Vec::new())),
54+
"Err(Custom { kind: Other, error: IllegalCharacter })"
55+
);
56+
}
5857

59-
#[test]
60-
fn email() {
61-
let signature = Signature {
62-
name: "ok".into(),
63-
email: "server>.example.com".into(),
64-
time: default_time(),
65-
};
66-
assert_eq!(
67-
format!("{:?}", signature.write_to(Vec::new())),
68-
"Err(Custom { kind: Other, error: IllegalCharacter })"
69-
);
70-
}
58+
#[test]
59+
fn email() {
60+
let signature = Signature {
61+
name: "ok".into(),
62+
email: "server>.example.com".into(),
63+
time: default_time(),
64+
};
65+
assert_eq!(
66+
format!("{:?}", signature.write_to(Vec::new())),
67+
"Err(Custom { kind: Other, error: IllegalCharacter })"
68+
);
69+
}
7170

72-
#[test]
73-
fn name_with_newline() {
74-
let signature = Signature {
75-
name: "hello\nnewline".into(),
76-
email: "[email protected]".into(),
77-
time: default_time(),
78-
};
79-
assert_eq!(
80-
format!("{:?}", signature.write_to(Vec::new())),
81-
"Err(Custom { kind: Other, error: IllegalCharacter })"
82-
);
83-
}
71+
#[test]
72+
fn name_with_newline() {
73+
let signature = Signature {
74+
name: "hello\nnewline".into(),
75+
email: "[email protected]".into(),
76+
time: default_time(),
77+
};
78+
assert_eq!(
79+
format!("{:?}", signature.write_to(Vec::new())),
80+
"Err(Custom { kind: Other, error: IllegalCharacter })"
81+
);
82+
}
8483

85-
fn default_time() -> Time {
86-
Time {
87-
time: 0,
88-
offset: 0,
89-
sign: Sign::Plus,
90-
}
84+
fn default_time() -> Time {
85+
Time {
86+
time: 0,
87+
offset: 0,
88+
sign: Sign::Plus,
9189
}
9290
}
9391
}
92+
}
9493

95-
use bstr::ByteSlice;
96-
use git_actor::Signature;
94+
use bstr::ByteSlice;
95+
use git_actor::Signature;
9796

98-
#[test]
99-
fn round_trip() -> Result<(), Box<dyn std::error::Error>> {
100-
for input in &[
97+
#[test]
98+
fn round_trip() -> Result<(), Box<dyn std::error::Error>> {
99+
for input in &[
101100
&b"Sebastian Thiel <[email protected]> 1 -0030"[..],
102101
".. ☺️Sebastian 王知明 Thiel🙌 .. <[email protected]> 1528473343 +0230".as_bytes(),
103102
".. whitespace \t is explicitly allowed - unicode aware trimming must be done elsewhere <[email protected]> 1528473343 +0230".as_bytes(),
@@ -107,6 +106,5 @@ mod signature {
107106
signature.write_to(&mut output)?;
108107
assert_eq!(output.as_bstr(), input.as_bstr());
109108
}
110-
Ok(())
111-
}
109+
Ok(())
112110
}

git-config/src/parser.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1441,12 +1441,12 @@ mod section_headers {
14411441

14421442
#[test]
14431443
fn newline_in_header() {
1444-
assert!(section_header(b"[hello\n]").is_err())
1444+
assert!(section_header(b"[hello\n]").is_err());
14451445
}
14461446

14471447
#[test]
14481448
fn null_byte_in_header() {
1449-
assert!(section_header(b"[hello\0]").is_err())
1449+
assert!(section_header(b"[hello\0]").is_err());
14501450
}
14511451

14521452
#[test]
@@ -1476,7 +1476,7 @@ mod config_name {
14761476

14771477
#[test]
14781478
fn cannot_be_empty() {
1479-
assert!(config_name(b"").is_err())
1479+
assert!(config_name(b"").is_err());
14801480
}
14811481
}
14821482

@@ -1727,7 +1727,7 @@ mod section {
17271727
},
17281728
3
17291729
))
1730-
)
1730+
);
17311731
}
17321732

17331733
#[test]
@@ -1840,7 +1840,7 @@ mod section {
18401840
},
18411841
0
18421842
))
1843-
)
1843+
);
18441844
}
18451845

18461846
#[test]

git-config/src/test_util.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,45 +28,45 @@ pub fn section_header(
2828
}
2929
}
3030

31-
pub(crate) fn name_event(name: &'static str) -> Event<'static> {
31+
pub(crate) const fn name_event(name: &'static str) -> Event<'static> {
3232
Event::Key(Key(Cow::Borrowed(name)))
3333
}
3434

35-
pub(crate) fn value_event(value: &'static str) -> Event<'static> {
35+
pub(crate) const fn value_event(value: &'static str) -> Event<'static> {
3636
Event::Value(Cow::Borrowed(value.as_bytes()))
3737
}
3838

39-
pub(crate) fn value_not_done_event(value: &'static str) -> Event<'static> {
39+
pub(crate) const fn value_not_done_event(value: &'static str) -> Event<'static> {
4040
Event::ValueNotDone(Cow::Borrowed(value.as_bytes()))
4141
}
4242

43-
pub(crate) fn value_done_event(value: &'static str) -> Event<'static> {
43+
pub(crate) const fn value_done_event(value: &'static str) -> Event<'static> {
4444
Event::ValueDone(Cow::Borrowed(value.as_bytes()))
4545
}
4646

47-
pub(crate) fn newline_event() -> Event<'static> {
47+
pub(crate) const fn newline_event() -> Event<'static> {
4848
newline_custom_event("\n")
4949
}
5050

51-
pub(crate) fn newline_custom_event(value: &'static str) -> Event<'static> {
51+
pub(crate) const fn newline_custom_event(value: &'static str) -> Event<'static> {
5252
Event::Newline(Cow::Borrowed(value))
5353
}
5454

55-
pub(crate) fn whitespace_event(value: &'static str) -> Event<'static> {
55+
pub(crate) const fn whitespace_event(value: &'static str) -> Event<'static> {
5656
Event::Whitespace(Cow::Borrowed(value))
5757
}
5858

59-
pub(crate) fn comment_event(tag: char, msg: &'static str) -> Event<'static> {
59+
pub(crate) const fn comment_event(tag: char, msg: &'static str) -> Event<'static> {
6060
Event::Comment(comment(tag, msg))
6161
}
6262

63-
pub(crate) fn comment(comment_tag: char, comment: &'static str) -> ParsedComment<'static> {
63+
pub(crate) const fn comment(comment_tag: char, comment: &'static str) -> ParsedComment<'static> {
6464
ParsedComment {
6565
comment_tag,
6666
comment: Cow::Borrowed(comment.as_bytes()),
6767
}
6868
}
6969

70-
pub(crate) fn fully_consumed<T>(t: T) -> (&'static [u8], T) {
70+
pub(crate) const fn fully_consumed<T>(t: T) -> (&'static [u8], T) {
7171
(&[], t)
7272
}

git-diff/tests/visit/mod.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ mod changes {
2626
) -> crate::Result<immutable::TreeIter<'a>> {
2727
let tree_id = db
2828
.find(commit, buf, &mut pack::cache::Never)?
29-
.ok_or_else(|| String::from(format!("start commit {:?} to be present", commit)))?
29+
.ok_or_else(|| format!("start commit {:?} to be present", commit))?
3030
.decode()?
3131
.into_commit()
3232
.expect("id is actually a commit")
@@ -66,7 +66,7 @@ mod changes {
6666
let (main_tree_id, parent_commit_id) = {
6767
let commit = db
6868
.find(commit_id, &mut buf, &mut pack::cache::Never)?
69-
.ok_or_else(|| String::from(format!("start commit {:?} to be present", commit_id)))?
69+
.ok_or_else(|| format!("start commit {:?} to be present", commit_id))?
7070
.decode()?
7171
.into_commit()
7272
.expect("id is actually a commit");
@@ -109,7 +109,7 @@ mod changes {
109109

110110
fn head_of(db: &linked::Store) -> ObjectId {
111111
ObjectId::from_hex(
112-
&std::fs::read(
112+
std::fs::read(
113113
db.dbs[0]
114114
.loose
115115
.path
@@ -238,14 +238,14 @@ mod changes {
238238
previous_entry_mode: EntryMode::Tree,
239239
previous_oid: hex_to_id("849bd76db90b65ebbd2e6d3970ca70c96ee5592c"),
240240
entry_mode: EntryMode::Tree,
241-
oid: tree_with_link_id.clone(),
241+
oid: tree_with_link_id,
242242
path: "f".into()
243243
},
244244
Modification {
245245
previous_entry_mode: EntryMode::Blob,
246246
previous_oid: hex_to_id("13c2aca72ab576cb5f22dc8e7f8ba8ddab553a8a"),
247247
entry_mode: link_entry_mode,
248-
oid: link_entry_oid.clone(),
248+
oid: link_entry_oid,
249249
path: "f/f".into()
250250
},
251251
],
@@ -507,7 +507,7 @@ mod changes {
507507
diff_commits(
508508
&db,
509509
all_commits[0].to_owned(),
510-
&all_commits.last().expect("we have many commits")
510+
all_commits.last().expect("we have many commits")
511511
)?,
512512
vec![
513513
Addition {

git-features/tests/pipe.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,10 @@ mod io {
8181
#[test]
8282
fn continue_on_empty_writes() {
8383
let (mut writer, mut reader) = io::pipe::unidirectional(2);
84-
writer.write(&[]).expect("write successful and non-blocking");
84+
writer.write_all(&[]).expect("write successful and non-blocking");
8585
let input = b"hello";
8686
writer
87-
.write(input)
87+
.write_all(input)
8888
.expect("second write works as well as there is capacity");
8989
let mut buf = vec![0u8; input.len()];
9090
assert_eq!(reader.read(&mut buf).expect("read succeeds"), input.len());

git-object/tests/immutable/commit.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
const SIGNATURE: &'static [u8; 487] = b"-----BEGIN PGP SIGNATURE-----\n\niQEzBAABCAAdFiEEdjYp/sh4j8NRKLX27gKdHl60AwAFAl7q2DsACgkQ7gKdHl60\nAwDvewgAkL5UjEztzeVXlzceom0uCrAkCw9wSGLTmYcMKW3JwEaTRgQ4FX+sDuFT\nLZ8DoPu3UHUP0QnKrUwHulTTlKcOAvsczHbVPIKtXCxo6QpUfhsJQwz/J29kiE4L\nsOd+lqKGnn4oati/de2xwqNGi081fO5KILX75z6KfsAe7Qz7R3jxRF4uzHI033O+\nJc2Y827XeaELxW40SmzoLanWgEcdreXf3PstXEWW77CAu0ozXmvYj56vTviVybxx\nG7bc8lwc+SSKVe2VVB+CCfVbs0i541gmghUpZfMhUgaqttcCH8ysrUJDhne1BLG8\nCrOJIWTwAeEDtomV1p76qrMeqr1GFg==\n=qlSN\n-----END PGP SIGNATURE-----";
1+
const SIGNATURE: & [u8; 487] = b"-----BEGIN PGP SIGNATURE-----\n\niQEzBAABCAAdFiEEdjYp/sh4j8NRKLX27gKdHl60AwAFAl7q2DsACgkQ7gKdHl60\nAwDvewgAkL5UjEztzeVXlzceom0uCrAkCw9wSGLTmYcMKW3JwEaTRgQ4FX+sDuFT\nLZ8DoPu3UHUP0QnKrUwHulTTlKcOAvsczHbVPIKtXCxo6QpUfhsJQwz/J29kiE4L\nsOd+lqKGnn4oati/de2xwqNGi081fO5KILX75z6KfsAe7Qz7R3jxRF4uzHI033O+\nJc2Y827XeaELxW40SmzoLanWgEcdreXf3PstXEWW77CAu0ozXmvYj56vTviVybxx\nG7bc8lwc+SSKVe2VVB+CCfVbs0i541gmghUpZfMhUgaqttcCH8ysrUJDhne1BLG8\nCrOJIWTwAeEDtomV1p76qrMeqr1GFg==\n=qlSN\n-----END PGP SIGNATURE-----";
22

3-
const LONG_MESSAGE: &'static str =
4-
"Merge tag 'thermal-v5.8-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/thermal/linux
3+
const LONG_MESSAGE: &str = "Merge tag 'thermal-v5.8-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/thermal/linux
54
65
Pull thermal updates from Daniel Lezcano:
76
@@ -74,7 +73,7 @@ Pull thermal updates from Daniel Lezcano:
7473
...
7574
";
7675

77-
const MERGE_TAG: &'static str = "object 8d485da0ddee79d0e6713405694253d401e41b93
76+
const MERGE_TAG: &str = "object 8d485da0ddee79d0e6713405694253d401e41b93
7877
type commit
7978
tag thermal-v5.8-rc1
8079
tagger Daniel Lezcano <[email protected]> 1591979433 +0200
@@ -491,7 +490,7 @@ mod from_bytes {
491490
Ok(())
492491
}
493492

494-
const OTHER_SIGNATURE: &'static [u8; 455] = b"-----BEGIN PGP SIGNATURE-----
493+
const OTHER_SIGNATURE: &[u8; 455] = b"-----BEGIN PGP SIGNATURE-----
495494
496495
wsBcBAABCAAQBQJeqxW4CRBK7hj4Ov3rIwAAdHIIAFD98qgN/k8ybukCLf6kpzvi
497496
5V8gf6BflONXc/oIDySurW7kfS9/r6jOgu08UN8KlQx4Q4g8yY7PROABhwGI70B3

git-odb/tests/odb/store/loose/backend.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ mod write {
4343
let mut buf2 = Vec::new();
4444

4545
for oid in object_ids() {
46-
let obj = locate_oid(oid.clone(), &mut buf);
46+
let obj = locate_oid(oid, &mut buf);
4747
let actual = db.write(&obj.decode()?.into(), git_hash::Kind::Sha1)?;
4848
assert_eq!(actual, oid);
4949
assert_eq!(db.find(oid, &mut buf2)?.expect("id present").decode()?, obj.decode()?);

git-packetline/tests/async-packetline.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ pub fn assert_err_display<T: std::fmt::Debug, E: std::error::Error>(
55
expected: impl AsRef<str>,
66
) {
77
match res {
8-
Ok(v) => assert!(false, "Expected error '{}', got value {:?}", expected.as_ref(), v),
8+
Ok(v) => panic!("Expected error '{}', got value {:?}", expected.as_ref(), v),
99
Err(err) => assert_eq!(err.to_string(), expected.as_ref()),
1010
}
1111
}

git-packetline/tests/blocking-packetline.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ pub fn assert_err_display<T: std::fmt::Debug, E: std::error::Error>(
55
expected: impl AsRef<str>,
66
) {
77
match res {
8-
Ok(v) => assert!(false, "Expected error '{}', got value {:?}", expected.as_ref(), v),
8+
Ok(v) => panic!("Expected error '{}', got value {:?}", expected.as_ref(), v),
99
Err(err) => assert_eq!(err.to_string(), expected.as_ref()),
1010
}
1111
}

git-packetline/tests/read/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ pub mod streaming_peek_iter {
200200
#[maybe_async::maybe_async]
201201
async fn exhaust(rd: &mut git_packetline::StreamingPeekableIter<&[u8]>) -> i32 {
202202
let mut count = 0;
203-
while let Some(_) = rd.read_line().await {
203+
while rd.read_line().await.is_some() {
204204
count += 1;
205205
}
206206
count

git-packetline/tests/read/sideband.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,19 +54,21 @@ async fn read_pack_with_progress_extraction() -> crate::Result {
5454
};
5555
let pack_read = rd.as_read_with_sidebands(&mut do_nothing);
5656
#[cfg(all(not(feature = "blocking-io"), feature = "async-io"))]
57-
let pack_entries = pack::data::input::BytesToEntriesIter::new_from_header(
57+
let mut pack_entries = pack::data::input::BytesToEntriesIter::new_from_header(
5858
util::BlockOn(pack_read),
5959
pack::data::input::Mode::Verify,
6060
pack::data::input::EntryDataMode::Ignore,
6161
)?;
6262
#[cfg(feature = "blocking-io")]
63-
let pack_entries = pack::data::input::BytesToEntriesIter::new_from_header(
63+
let mut pack_entries = pack::data::input::BytesToEntriesIter::new_from_header(
6464
pack_read,
6565
pack::data::input::Mode::Verify,
6666
pack::data::input::EntryDataMode::Ignore,
6767
)?;
6868
let all_but_last = pack_entries.size_hint().0 - 1;
69-
let last = pack_entries.skip(all_but_last).next().expect("last entry")?;
69+
let last = pack_entries.nth(all_but_last).expect("last entry")?;
70+
drop(pack_entries);
71+
7072
assert_eq!(
7173
last.trailer
7274
.expect("trailer to exist on last entry")

0 commit comments

Comments
 (0)