Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: improve code coverage for src/error.rs #204

Merged
merged 1 commit into from
Jun 30, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}