Skip to content

Commit

Permalink
chore: improve code coverage for src/error.rs (#204)
Browse files Browse the repository at this point in the history
  • Loading branch information
Boshen authored Jun 30, 2024
1 parent a1d9419 commit 078a298
Showing 1 changed file with 24 additions and 10 deletions.
34 changes: 24 additions & 10 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,14 +147,28 @@ fn test_into_io_error() {

assert_eq!(resolve_io_error, ResolveError::from(string_error));
assert_eq!(resolve_io_error.clone(), resolve_io_error);
if let ResolveError::IOError(io_error) = resolve_io_error {
// fix for https://github.com/web-infra-dev/rspack/issues/4564
let std_io_error: io::Error = io_error.into();
assert_eq!(std_io_error.kind(), ErrorKind::Interrupted);
assert_eq!(std_io_error.to_string(), error_string);
assert_eq!(
format!("{std_io_error:?}"),
r#"Custom { kind: Interrupted, error: "IOError occurred" }"#
);
}
let ResolveError::IOError(io_error) = resolve_io_error else { unreachable!() };
assert_eq!(
format!("{io_error:?}"),
r#"IOError(Custom { kind: Interrupted, error: "IOError occurred" })"#
);
// fix for https://github.com/web-infra-dev/rspack/issues/4564
let std_io_error: io::Error = io_error.into();
assert_eq!(std_io_error.kind(), ErrorKind::Interrupted);
assert_eq!(std_io_error.to_string(), error_string);
assert_eq!(
format!("{std_io_error:?}"),
r#"Custom { kind: Interrupted, error: "IOError occurred" }"#
);
}

#[test]
fn test_coverage() {
let error = ResolveError::NotFound("x".into());
assert_eq!(format!("{error:?}"), r#"NotFound("x")"#);
assert_eq!(error.clone(), error);

let error = ResolveError::Specifier(SpecifierError::Empty("x".into()));
assert_eq!(format!("{error:?}"), r#"Specifier(Empty("x"))"#);
assert_eq!(error.clone(), error);
}

0 comments on commit 078a298

Please sign in to comment.