From 41b313e956a63030e4515715a2e19d8acf3a0e9b Mon Sep 17 00:00:00 2001 From: Boshen Date: Sun, 30 Jun 2024 23:47:39 +0800 Subject: [PATCH] chore: improve code coverage for src/error.rs --- src/error.rs | 34 ++++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/src/error.rs b/src/error.rs index ff2aaa4f..d8b190ba 100644 --- a/src/error.rs +++ b/src/error.rs @@ -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); }