Skip to content

Commit

Permalink
clippy on tests and thanks clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
Byron committed Jul 30, 2021
1 parent e1964e4 commit a77a71c
Show file tree
Hide file tree
Showing 26 changed files with 160 additions and 170 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ doc: ## Run cargo doc on all crates
cargo doc --features=max,lean,light,small

clippy: ## Run cargo clippy on all crates
cargo clippy --all
cargo clippy --all --tests
cargo clippy --all --no-default-features --features small
cargo clippy --all --no-default-features --features light-async
cargo clippy --all --no-default-features --features light-async --tests

check: ## Build all code in suitable configurations
cargo check --all
Expand Down
104 changes: 51 additions & 53 deletions git-actor/tests/mutable/signature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,66 +38,65 @@ mod time {
}
}

mod signature {
mod write_to {
mod invalid {
use git_actor::{Sign, Signature, Time};
mod write_to {
mod invalid {
use git_actor::{Sign, Signature, Time};

#[test]
fn name() {
let signature = Signature {
name: "invalid < middlename".into(),
email: "ok".into(),
time: default_time(),
};
assert_eq!(
format!("{:?}", signature.write_to(Vec::new())),
"Err(Custom { kind: Other, error: IllegalCharacter })"
);
}
#[test]
fn name() {
let signature = Signature {
name: "invalid < middlename".into(),
email: "ok".into(),
time: default_time(),
};
assert_eq!(
format!("{:?}", signature.write_to(Vec::new())),
"Err(Custom { kind: Other, error: IllegalCharacter })"
);
}

#[test]
fn email() {
let signature = Signature {
name: "ok".into(),
email: "server>.example.com".into(),
time: default_time(),
};
assert_eq!(
format!("{:?}", signature.write_to(Vec::new())),
"Err(Custom { kind: Other, error: IllegalCharacter })"
);
}
#[test]
fn email() {
let signature = Signature {
name: "ok".into(),
email: "server>.example.com".into(),
time: default_time(),
};
assert_eq!(
format!("{:?}", signature.write_to(Vec::new())),
"Err(Custom { kind: Other, error: IllegalCharacter })"
);
}

#[test]
fn name_with_newline() {
let signature = Signature {
name: "hello\nnewline".into(),
email: "name@example.com".into(),
time: default_time(),
};
assert_eq!(
format!("{:?}", signature.write_to(Vec::new())),
"Err(Custom { kind: Other, error: IllegalCharacter })"
);
}
#[test]
fn name_with_newline() {
let signature = Signature {
name: "hello\nnewline".into(),
email: "name@example.com".into(),
time: default_time(),
};
assert_eq!(
format!("{:?}", signature.write_to(Vec::new())),
"Err(Custom { kind: Other, error: IllegalCharacter })"
);
}

fn default_time() -> Time {
Time {
time: 0,
offset: 0,
sign: Sign::Plus,
}
fn default_time() -> Time {
Time {
time: 0,
offset: 0,
sign: Sign::Plus,
}
}
}
}

use bstr::ByteSlice;
use git_actor::Signature;
use bstr::ByteSlice;
use git_actor::Signature;

#[test]
fn round_trip() -> Result<(), Box<dyn std::error::Error>> {
for input in &[
#[test]
fn round_trip() -> Result<(), Box<dyn std::error::Error>> {
for input in &[
&b"Sebastian Thiel <byronimo@gmail.com> 1 -0030"[..],
".. ☺️Sebastian 王知明 Thiel🙌 .. <byronimo@gmail.com> 1528473343 +0230".as_bytes(),
".. whitespace \t is explicitly allowed - unicode aware trimming must be done elsewhere <byronimo@gmail.com> 1528473343 +0230".as_bytes(),
Expand All @@ -107,6 +106,5 @@ mod signature {
signature.write_to(&mut output)?;
assert_eq!(output.as_bstr(), input.as_bstr());
}
Ok(())
}
Ok(())
}
10 changes: 5 additions & 5 deletions git-config/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1441,12 +1441,12 @@ mod section_headers {

#[test]
fn newline_in_header() {
assert!(section_header(b"[hello\n]").is_err())
assert!(section_header(b"[hello\n]").is_err());
}

#[test]
fn null_byte_in_header() {
assert!(section_header(b"[hello\0]").is_err())
assert!(section_header(b"[hello\0]").is_err());
}

#[test]
Expand Down Expand Up @@ -1476,7 +1476,7 @@ mod config_name {

#[test]
fn cannot_be_empty() {
assert!(config_name(b"").is_err())
assert!(config_name(b"").is_err());
}
}

Expand Down Expand Up @@ -1727,7 +1727,7 @@ mod section {
},
3
))
)
);
}

#[test]
Expand Down Expand Up @@ -1840,7 +1840,7 @@ mod section {
},
0
))
)
);
}

#[test]
Expand Down
20 changes: 10 additions & 10 deletions git-config/src/test_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,45 +28,45 @@ pub fn section_header(
}
}

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

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

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

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

pub(crate) fn newline_event() -> Event<'static> {
pub(crate) const fn newline_event() -> Event<'static> {
newline_custom_event("\n")
}

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

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

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

pub(crate) fn comment(comment_tag: char, comment: &'static str) -> ParsedComment<'static> {
pub(crate) const fn comment(comment_tag: char, comment: &'static str) -> ParsedComment<'static> {
ParsedComment {
comment_tag,
comment: Cow::Borrowed(comment.as_bytes()),
}
}

pub(crate) fn fully_consumed<T>(t: T) -> (&'static [u8], T) {
pub(crate) const fn fully_consumed<T>(t: T) -> (&'static [u8], T) {
(&[], t)
}
12 changes: 6 additions & 6 deletions git-diff/tests/visit/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ mod changes {
) -> crate::Result<immutable::TreeIter<'a>> {
let tree_id = db
.find(commit, buf, &mut pack::cache::Never)?
.ok_or_else(|| String::from(format!("start commit {:?} to be present", commit)))?
.ok_or_else(|| format!("start commit {:?} to be present", commit))?
.decode()?
.into_commit()
.expect("id is actually a commit")
Expand Down Expand Up @@ -66,7 +66,7 @@ mod changes {
let (main_tree_id, parent_commit_id) = {
let commit = db
.find(commit_id, &mut buf, &mut pack::cache::Never)?
.ok_or_else(|| String::from(format!("start commit {:?} to be present", commit_id)))?
.ok_or_else(|| format!("start commit {:?} to be present", commit_id))?
.decode()?
.into_commit()
.expect("id is actually a commit");
Expand Down Expand Up @@ -109,7 +109,7 @@ mod changes {

fn head_of(db: &linked::Store) -> ObjectId {
ObjectId::from_hex(
&std::fs::read(
std::fs::read(
db.dbs[0]
.loose
.path
Expand Down Expand Up @@ -238,14 +238,14 @@ mod changes {
previous_entry_mode: EntryMode::Tree,
previous_oid: hex_to_id("849bd76db90b65ebbd2e6d3970ca70c96ee5592c"),
entry_mode: EntryMode::Tree,
oid: tree_with_link_id.clone(),
oid: tree_with_link_id,
path: "f".into()
},
Modification {
previous_entry_mode: EntryMode::Blob,
previous_oid: hex_to_id("13c2aca72ab576cb5f22dc8e7f8ba8ddab553a8a"),
entry_mode: link_entry_mode,
oid: link_entry_oid.clone(),
oid: link_entry_oid,
path: "f/f".into()
},
],
Expand Down Expand Up @@ -507,7 +507,7 @@ mod changes {
diff_commits(
&db,
all_commits[0].to_owned(),
&all_commits.last().expect("we have many commits")
all_commits.last().expect("we have many commits")
)?,
vec![
Addition {
Expand Down
4 changes: 2 additions & 2 deletions git-features/tests/pipe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,10 @@ mod io {
#[test]
fn continue_on_empty_writes() {
let (mut writer, mut reader) = io::pipe::unidirectional(2);
writer.write(&[]).expect("write successful and non-blocking");
writer.write_all(&[]).expect("write successful and non-blocking");
let input = b"hello";
writer
.write(input)
.write_all(input)
.expect("second write works as well as there is capacity");
let mut buf = vec![0u8; input.len()];
assert_eq!(reader.read(&mut buf).expect("read succeeds"), input.len());
Expand Down
9 changes: 4 additions & 5 deletions git-object/tests/immutable/commit.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
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-----";
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-----";

const LONG_MESSAGE: &'static str =
"Merge tag 'thermal-v5.8-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/thermal/linux
const LONG_MESSAGE: &str = "Merge tag 'thermal-v5.8-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/thermal/linux
Pull thermal updates from Daniel Lezcano:
Expand Down Expand Up @@ -74,7 +73,7 @@ Pull thermal updates from Daniel Lezcano:
...
";

const MERGE_TAG: &'static str = "object 8d485da0ddee79d0e6713405694253d401e41b93
const MERGE_TAG: &str = "object 8d485da0ddee79d0e6713405694253d401e41b93
type commit
tag thermal-v5.8-rc1
tagger Daniel Lezcano <daniel.lezcano@linaro.org> 1591979433 +0200
Expand Down Expand Up @@ -491,7 +490,7 @@ mod from_bytes {
Ok(())
}

const OTHER_SIGNATURE: &'static [u8; 455] = b"-----BEGIN PGP SIGNATURE-----
const OTHER_SIGNATURE: &[u8; 455] = b"-----BEGIN PGP SIGNATURE-----
wsBcBAABCAAQBQJeqxW4CRBK7hj4Ov3rIwAAdHIIAFD98qgN/k8ybukCLf6kpzvi
5V8gf6BflONXc/oIDySurW7kfS9/r6jOgu08UN8KlQx4Q4g8yY7PROABhwGI70B3
Expand Down
2 changes: 1 addition & 1 deletion git-odb/tests/odb/store/loose/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ mod write {
let mut buf2 = Vec::new();

for oid in object_ids() {
let obj = locate_oid(oid.clone(), &mut buf);
let obj = locate_oid(oid, &mut buf);
let actual = db.write(&obj.decode()?.into(), git_hash::Kind::Sha1)?;
assert_eq!(actual, oid);
assert_eq!(db.find(oid, &mut buf2)?.expect("id present").decode()?, obj.decode()?);
Expand Down
2 changes: 1 addition & 1 deletion git-packetline/tests/async-packetline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ pub fn assert_err_display<T: std::fmt::Debug, E: std::error::Error>(
expected: impl AsRef<str>,
) {
match res {
Ok(v) => assert!(false, "Expected error '{}', got value {:?}", expected.as_ref(), v),
Ok(v) => panic!("Expected error '{}', got value {:?}", expected.as_ref(), v),
Err(err) => assert_eq!(err.to_string(), expected.as_ref()),
}
}
Expand Down
2 changes: 1 addition & 1 deletion git-packetline/tests/blocking-packetline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ pub fn assert_err_display<T: std::fmt::Debug, E: std::error::Error>(
expected: impl AsRef<str>,
) {
match res {
Ok(v) => assert!(false, "Expected error '{}', got value {:?}", expected.as_ref(), v),
Ok(v) => panic!("Expected error '{}', got value {:?}", expected.as_ref(), v),
Err(err) => assert_eq!(err.to_string(), expected.as_ref()),
}
}
Expand Down
2 changes: 1 addition & 1 deletion git-packetline/tests/read/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ pub mod streaming_peek_iter {
#[maybe_async::maybe_async]
async fn exhaust(rd: &mut git_packetline::StreamingPeekableIter<&[u8]>) -> i32 {
let mut count = 0;
while let Some(_) = rd.read_line().await {
while rd.read_line().await.is_some() {
count += 1;
}
count
Expand Down
8 changes: 5 additions & 3 deletions git-packetline/tests/read/sideband.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,19 +54,21 @@ async fn read_pack_with_progress_extraction() -> crate::Result {
};
let pack_read = rd.as_read_with_sidebands(&mut do_nothing);
#[cfg(all(not(feature = "blocking-io"), feature = "async-io"))]
let pack_entries = pack::data::input::BytesToEntriesIter::new_from_header(
let mut pack_entries = pack::data::input::BytesToEntriesIter::new_from_header(
util::BlockOn(pack_read),
pack::data::input::Mode::Verify,
pack::data::input::EntryDataMode::Ignore,
)?;
#[cfg(feature = "blocking-io")]
let pack_entries = pack::data::input::BytesToEntriesIter::new_from_header(
let mut pack_entries = pack::data::input::BytesToEntriesIter::new_from_header(
pack_read,
pack::data::input::Mode::Verify,
pack::data::input::EntryDataMode::Ignore,
)?;
let all_but_last = pack_entries.size_hint().0 - 1;
let last = pack_entries.skip(all_but_last).next().expect("last entry")?;
let last = pack_entries.nth(all_but_last).expect("last entry")?;
drop(pack_entries);

assert_eq!(
last.trailer
.expect("trailer to exist on last entry")
Expand Down

0 comments on commit a77a71c

Please sign in to comment.