Skip to content

Commit

Permalink
test: Update doctests
Browse files Browse the repository at this point in the history
  • Loading branch information
sorairolake committed Oct 30, 2024
1 parent bdc3827 commit a581322
Showing 1 changed file with 40 additions and 20 deletions.
60 changes: 40 additions & 20 deletions src/exit_code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pub enum ExitCode {
/// ```
/// # use sysexits::ExitCode;
/// #
/// assert_eq!(ExitCode::Ok as u8, 0);
/// assert_eq!(u8::from(ExitCode::Ok), 0);
/// ```
#[default]
Ok,
Expand All @@ -39,7 +39,7 @@ pub enum ExitCode {
/// ```
/// # use sysexits::ExitCode;
/// #
/// assert_eq!(ExitCode::Usage as u8, 64);
/// assert_eq!(u8::from(ExitCode::Usage), 64);
/// ```
Usage = 64,

Expand All @@ -51,7 +51,7 @@ pub enum ExitCode {
/// ```
/// # use sysexits::ExitCode;
/// #
/// assert_eq!(ExitCode::DataErr as u8, 65);
/// assert_eq!(u8::from(ExitCode::DataErr), 65);
/// ```
DataErr,

Expand All @@ -64,7 +64,7 @@ pub enum ExitCode {
/// ```
/// # use sysexits::ExitCode;
/// #
/// assert_eq!(ExitCode::NoInput as u8, 66);
/// assert_eq!(u8::from(ExitCode::NoInput), 66);
/// ```
NoInput,

Expand All @@ -76,7 +76,7 @@ pub enum ExitCode {
/// ```
/// # use sysexits::ExitCode;
/// #
/// assert_eq!(ExitCode::NoUser as u8, 67);
/// assert_eq!(u8::from(ExitCode::NoUser), 67);
/// ```
NoUser,

Expand All @@ -88,7 +88,7 @@ pub enum ExitCode {
/// ```
/// # use sysexits::ExitCode;
/// #
/// assert_eq!(ExitCode::NoHost as u8, 68);
/// assert_eq!(u8::from(ExitCode::NoHost), 68);
/// ```
NoHost,

Expand All @@ -101,7 +101,7 @@ pub enum ExitCode {
/// ```
/// # use sysexits::ExitCode;
/// #
/// assert_eq!(ExitCode::Unavailable as u8, 69);
/// assert_eq!(u8::from(ExitCode::Unavailable), 69);
/// ```
Unavailable,

Expand All @@ -113,7 +113,7 @@ pub enum ExitCode {
/// ```
/// # use sysexits::ExitCode;
/// #
/// assert_eq!(ExitCode::Software as u8, 70);
/// assert_eq!(u8::from(ExitCode::Software), 70);
/// ```
Software,

Expand All @@ -127,7 +127,7 @@ pub enum ExitCode {
/// ```
/// # use sysexits::ExitCode;
/// #
/// assert_eq!(ExitCode::OsErr as u8, 71);
/// assert_eq!(u8::from(ExitCode::OsErr), 71);
/// ```
///
/// [`getuid(2)`]: https://man.openbsd.org/getuid.2
Expand All @@ -141,7 +141,7 @@ pub enum ExitCode {
/// ```
/// # use sysexits::ExitCode;
/// #
/// assert_eq!(ExitCode::OsFile as u8, 72);
/// assert_eq!(u8::from(ExitCode::OsFile), 72);
/// ```
OsFile,

Expand All @@ -152,7 +152,7 @@ pub enum ExitCode {
/// ```
/// # use sysexits::ExitCode;
/// #
/// assert_eq!(ExitCode::CantCreat as u8, 73);
/// assert_eq!(u8::from(ExitCode::CantCreat), 73);
/// ```
CantCreat,

Expand All @@ -163,7 +163,7 @@ pub enum ExitCode {
/// ```
/// # use sysexits::ExitCode;
/// #
/// assert_eq!(ExitCode::IoErr as u8, 74);
/// assert_eq!(u8::from(ExitCode::IoErr), 74);
/// ```
IoErr,

Expand All @@ -176,7 +176,7 @@ pub enum ExitCode {
/// ```
/// # use sysexits::ExitCode;
/// #
/// assert_eq!(ExitCode::TempFail as u8, 75);
/// assert_eq!(u8::from(ExitCode::TempFail), 75);
/// ```
TempFail,

Expand All @@ -188,7 +188,7 @@ pub enum ExitCode {
/// ```
/// # use sysexits::ExitCode;
/// #
/// assert_eq!(ExitCode::Protocol as u8, 76);
/// assert_eq!(u8::from(ExitCode::Protocol), 76);
/// ```
Protocol,

Expand All @@ -202,7 +202,7 @@ pub enum ExitCode {
/// ```
/// # use sysexits::ExitCode;
/// #
/// assert_eq!(ExitCode::NoPerm as u8, 77);
/// assert_eq!(u8::from(ExitCode::NoPerm), 77);
/// ```
NoPerm,

Expand All @@ -213,7 +213,7 @@ pub enum ExitCode {
/// ```
/// # use sysexits::ExitCode;
/// #
/// assert_eq!(ExitCode::Config as u8, 78);
/// assert_eq!(u8::from(ExitCode::Config), 78);
/// ```
Config,
}
Expand All @@ -227,8 +227,8 @@ impl ExitCode {
/// ```
/// # use sysexits::ExitCode;
/// #
/// assert_eq!(ExitCode::Ok.is_success(), true);
/// assert_eq!(ExitCode::Usage.is_success(), false);
/// assert!(ExitCode::Ok.is_success());
/// assert!(!ExitCode::Usage.is_success());
/// ```
#[must_use]
#[inline]
Expand All @@ -244,8 +244,8 @@ impl ExitCode {
/// ```
/// # use sysexits::ExitCode;
/// #
/// assert_eq!(ExitCode::Ok.is_failure(), false);
/// assert_eq!(ExitCode::Usage.is_failure(), true);
/// assert!(!ExitCode::Ok.is_failure());
/// assert!(ExitCode::Usage.is_failure());
/// ```
#[must_use]
#[inline]
Expand Down Expand Up @@ -305,6 +305,26 @@ impl std::process::Termination for ExitCode {
mod tests {
use super::*;

#[test]
fn exit_code() {
assert_eq!(ExitCode::Ok as u8, 0);
assert_eq!(ExitCode::Usage as u8, 64);
assert_eq!(ExitCode::DataErr as u8, 65);
assert_eq!(ExitCode::NoInput as u8, 66);
assert_eq!(ExitCode::NoUser as u8, 67);
assert_eq!(ExitCode::NoHost as u8, 68);
assert_eq!(ExitCode::Unavailable as u8, 69);
assert_eq!(ExitCode::Software as u8, 70);
assert_eq!(ExitCode::OsErr as u8, 71);
assert_eq!(ExitCode::OsFile as u8, 72);
assert_eq!(ExitCode::CantCreat as u8, 73);
assert_eq!(ExitCode::IoErr as u8, 74);
assert_eq!(ExitCode::TempFail as u8, 75);
assert_eq!(ExitCode::Protocol as u8, 76);
assert_eq!(ExitCode::NoPerm as u8, 77);
assert_eq!(ExitCode::Config as u8, 78);
}

#[test]
fn clone() {
assert_eq!(ExitCode::Ok.clone(), ExitCode::Ok);
Expand Down

0 comments on commit a581322

Please sign in to comment.