Skip to content

Commit

Permalink
test: add core
Browse files Browse the repository at this point in the history
  • Loading branch information
oneofthezombies committed Feb 12, 2024
1 parent 0cd0c46 commit 5a64cbd
Showing 1 changed file with 10 additions and 13 deletions.
23 changes: 10 additions & 13 deletions crates/libs/kill_tree/src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,10 +166,7 @@ mod tests {
process_id: 0,
reason: "reason".to_string(),
};
assert_eq!(
format!("{}", error),
"Invalid process id: 0. Reason: reason"
);
assert_eq!(format!("{error}"), "Invalid process id: 0. Reason: reason");
}

#[test]
Expand All @@ -179,7 +176,7 @@ mod tests {
source: u32::try_from(-1).unwrap_err(),
};
assert_eq!(
format!("{}", error),
format!("{error}"),
"Invalid cast. Reason: reason. Source: out of range integral type conversion attempted"
);
}
Expand All @@ -193,23 +190,23 @@ mod tests {
source: Some("source".parse::<u32>().unwrap_err()),
};
assert_eq!(
format!("{}", error),
format!("{error}"),
"Invalid proc entry. Process id: 0. Path: /proc/0. Reason: reason. Source: Some(ParseIntError { kind: InvalidDigit })"
);
}

#[test]
fn error_display_io() {
let error = Error::Io(std::io::Error::new(std::io::ErrorKind::Other, "error"));
assert_eq!(format!("{}", error), "I/O error: error");
assert_eq!(format!("{error}"), "I/O error: error");
}

#[cfg(windows)]
#[test]
fn error_display_windows() {
let error = Error::Windows(windows::core::Error::OK);
assert_eq!(
format!("{}", error),
format!("{error}"),
"Windows error: The operation completed successfully. (0x00000000)"
);
}
Expand All @@ -218,14 +215,14 @@ mod tests {
#[test]
fn error_display_unix() {
let error = Error::Unix(nix::Error::UnsupportedOperation);
assert_eq!(format!("{}", error), "Unix error: UnsupportedOperation");
assert_eq!(format!("{error}"), "Unix error: UnsupportedOperation");
}

#[test]
fn from_io_error() {
let error = std::io::Error::new(std::io::ErrorKind::Other, "error");
let error = Error::from(error);
assert_eq!(format!("{}", error), "I/O error: error");
assert_eq!(format!("{error}"), "I/O error: error");
}

#[cfg(windows)]
Expand All @@ -234,7 +231,7 @@ mod tests {
let error = windows::core::Error::OK;
let error = Error::from(error);
assert_eq!(
format!("{}", error),
format!("{error}"),
"Windows error: The operation completed successfully. (0x00000000)"
);
}
Expand All @@ -244,13 +241,13 @@ mod tests {
fn from_unix_error() {
let error = nix::Error::UnsupportedOperation;
let error = Error::from(error);
assert_eq!(format!("{}", error), "Unix error: UnsupportedOperation");
assert_eq!(format!("{error}"), "Unix error: UnsupportedOperation");
}

#[test]
fn default_config() {
let config = Config::default();
assert_eq!(config.signal, "SIGTERM");
assert_eq!(config.include_target, true);
assert!(config.include_target);
}
}

0 comments on commit 5a64cbd

Please sign in to comment.