Skip to content

Commit

Permalink
Try to cover more lines in tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
TheVeryDarkness committed Aug 30, 2024
1 parent 9a7838b commit 23c26bc
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 14 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ license = "MIT OR Apache-2.0"

[dev-dependencies]
anyhow = "1.0.86"
rayon = "1.10.0"
24 changes: 14 additions & 10 deletions src/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ mod tracked {

#[cfg(test)]
mod tests {
use rayon::iter::{IntoParallelIterator, ParallelIterator};

use super::{
array_from_fn,
tracked::{check, Tracked},
Expand All @@ -139,18 +141,20 @@ mod tests {

#[test]
fn array_tracked_caught_panic() {
let res = catch_unwind(|| {
let mut i = 0;
let array: [Tracked; 3] = array_from_fn(|| {
if i >= 2 {
panic!("Sorry, something is wrong with the array.");
}
i += 1;
Tracked::new()
(0..16).into_par_iter().for_each(|_| {
let res = catch_unwind(|| {
let mut i = 0;
let array: [Tracked; 3] = array_from_fn(|| {
if i >= 2 {
panic!("Sorry, something is wrong with the array.");
}
i += 1;
Tracked::new()
});
array
});
array
assert!(res.is_err());
});
assert!(res.is_err());
check();
}
}
4 changes: 1 addition & 3 deletions src/read_into.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,9 +252,7 @@ macro_rules! impl_read_into_for_tuple {
}
impl<$($t: std::error::Error, )* > Display for $e<$($t, )* > {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
$(Self::$t(err) => Display::fmt(err, f), )*
}
match self { $( Self::$t(err) => Display::fmt(err, f), )* }
}
}
impl<$($t: std::error::Error, )* > std::error::Error for $e<$($t, )* > {}
Expand Down
6 changes: 5 additions & 1 deletion tests/tuple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,13 @@ fn try_read_tuple_3_from_str_err() {
let reader = Cursor::new("1 2 -3".as_bytes());
let mut reader = InputStream::new(reader);

let vec: Result<(u32, u32, u32), _> = reader.try_read();
let vec: Result<(i32, i8, u32), _> = reader.try_read();
let err = vec.unwrap_err();
assert_eq!(err.to_string(), "invalid digit found in string");
assert_eq!(
format!("{:?}", err),
"T3(ParseIntError { kind: InvalidDigit })"
);
}

#[test]
Expand Down

0 comments on commit 23c26bc

Please sign in to comment.