diff options
author | Krysztal Huang <krysztal.huang@outlook.com> | 2024-07-25 23:41:00 +0800 |
---|---|---|
committer | Sylvestre Ledru <sylvestre@debian.org> | 2024-07-26 00:49:03 +0200 |
commit | 4bca4898f439445fe405d69e2a17d7b649fe3064 (patch) | |
tree | d37025028780d85ae27070c100f568999c2640de | |
parent | 58d0fb6fb2fe85e40d96be835db40567917b645c (diff) |
uucore: Move tests for `Teletype`to `tty.rs`
-rw-r--r-- | src/uucore/src/lib/features.rs | 4 | ||||
-rw-r--r-- | src/uucore/src/lib/features/proc_info.rs | 31 | ||||
-rw-r--r-- | src/uucore/src/lib/features/tty.rs | 34 |
3 files changed, 37 insertions, 32 deletions
diff --git a/src/uucore/src/lib/features.rs b/src/uucore/src/lib/features.rs index 7237788c91..cf24637f7b 100644 --- a/src/uucore/src/lib/features.rs +++ b/src/uucore/src/lib/features.rs @@ -47,10 +47,10 @@ pub mod perms; pub mod pipes; #[cfg(all(target_os = "linux", feature = "proc-info"))] pub mod proc_info; -#[cfg(all(target_os = "linux", feature = "tty"))] -pub mod tty; #[cfg(all(unix, feature = "process"))] pub mod process; +#[cfg(all(target_os = "linux", feature = "tty"))] +pub mod tty; #[cfg(all(unix, not(target_os = "macos"), feature = "fsxattr"))] pub mod fsxattr; diff --git a/src/uucore/src/lib/features/proc_info.rs b/src/uucore/src/lib/features/proc_info.rs index fc359492ec..f6c4edf4c2 100644 --- a/src/uucore/src/lib/features/proc_info.rs +++ b/src/uucore/src/lib/features/proc_info.rs @@ -351,35 +351,6 @@ mod tests { use std::str::FromStr; #[test] - fn test_tty_from() { - assert_eq!(Teletype::try_from("?").unwrap(), Teletype::Unknown); - assert_eq!(Teletype::try_from("/dev/tty1").unwrap(), Teletype::Tty(1)); - assert_eq!(Teletype::try_from("/dev/tty10").unwrap(), Teletype::Tty(10)); - assert_eq!(Teletype::try_from("/dev/pts/1").unwrap(), Teletype::Pts(1)); - assert_eq!( - Teletype::try_from("/dev/pts/10").unwrap(), - Teletype::Pts(10) - ); - assert_eq!(Teletype::try_from("/dev/ttyS1").unwrap(), Teletype::TtyS(1)); - assert_eq!( - Teletype::try_from("/dev/ttyS10").unwrap(), - Teletype::TtyS(10) - ); - assert_eq!(Teletype::try_from("ttyS10").unwrap(), Teletype::TtyS(10)); - - assert!(Teletype::try_from("value").is_err()); - assert!(Teletype::try_from("TtyS10").is_err()); - } - - #[test] - fn test_terminal_type_display() { - assert_eq!(Teletype::Pts(10).to_string(), "/dev/pts/10"); - assert_eq!(Teletype::Tty(10).to_string(), "/dev/tty10"); - assert_eq!(Teletype::TtyS(10).to_string(), "/dev/ttyS10"); - assert_eq!(Teletype::Unknown.to_string(), "?"); - } - - #[test] fn test_run_state_conversion() { assert_eq!(RunState::try_from("R").unwrap(), RunState::Running); assert_eq!(RunState::try_from("S").unwrap(), RunState::Sleeping); @@ -431,7 +402,7 @@ mod tests { .flat_map(Teletype::try_from) .collect::<HashSet<_>>(); - assert_eq!(pid_entry.ttys().unwrap(), result.into()) + assert_eq!(pid_entry.ttys().unwrap(), result.into()); } #[test] diff --git a/src/uucore/src/lib/features/tty.rs b/src/uucore/src/lib/features/tty.rs index 49ec700da7..67d34c5d0a 100644 --- a/src/uucore/src/lib/features/tty.rs +++ b/src/uucore/src/lib/features/tty.rs @@ -91,3 +91,37 @@ impl TryFrom<PathBuf> for Teletype { } } } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_tty_from() { + assert_eq!(Teletype::try_from("?").unwrap(), Teletype::Unknown); + assert_eq!(Teletype::try_from("/dev/tty1").unwrap(), Teletype::Tty(1)); + assert_eq!(Teletype::try_from("/dev/tty10").unwrap(), Teletype::Tty(10)); + assert_eq!(Teletype::try_from("/dev/pts/1").unwrap(), Teletype::Pts(1)); + assert_eq!( + Teletype::try_from("/dev/pts/10").unwrap(), + Teletype::Pts(10) + ); + assert_eq!(Teletype::try_from("/dev/ttyS1").unwrap(), Teletype::TtyS(1)); + assert_eq!( + Teletype::try_from("/dev/ttyS10").unwrap(), + Teletype::TtyS(10) + ); + assert_eq!(Teletype::try_from("ttyS10").unwrap(), Teletype::TtyS(10)); + + assert!(Teletype::try_from("value").is_err()); + assert!(Teletype::try_from("TtyS10").is_err()); + } + + #[test] + fn test_terminal_type_display() { + assert_eq!(Teletype::Pts(10).to_string(), "/dev/pts/10"); + assert_eq!(Teletype::Tty(10).to_string(), "/dev/tty10"); + assert_eq!(Teletype::TtyS(10).to_string(), "/dev/ttyS10"); + assert_eq!(Teletype::Unknown.to_string(), "?"); + } +} |