Skip to content
Open
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
18 changes: 17 additions & 1 deletion src/uu/pgrep/src/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,8 @@ impl TryFrom<&str> for Teletype {
type Error = ();

fn try_from(value: &str) -> Result<Self, Self::Error> {
Self::try_from(PathBuf::from(value))
let name = value.strip_prefix("/dev/").unwrap_or(value);
Ok(Self::Known(format!("/dev/{name}")))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TryFrom<PathBuf> just below seems unused now, could it be removed?

}
}

Expand Down Expand Up @@ -800,6 +801,21 @@ mod tests {
#[cfg(target_os = "linux")]
use std::collections::HashSet;

#[test]
fn test_teletype_from_name_without_dev_prefix() {
for (input, expected) in [
("pts/0", "/dev/pts/0"),
("tty1", "/dev/tty1"),
("/dev/pts/0", "/dev/pts/0"),
("/dev/tty1", "/dev/tty1"),
] {
assert_eq!(
Teletype::try_from(input),
Ok(Teletype::Known(expected.to_string()))
);
}
}

#[test]
#[cfg(target_os = "linux")]
fn test_tty_resolution() {
Expand Down
Loading