From fcb079e20e6cd6008d7146a9a5dc04ddda0e5bdd Mon Sep 17 00:00:00 2001 From: David Carlier Date: Thu, 20 May 2021 20:09:41 +0100 Subject: [PATCH] who freebsd build fix unsupported RUN_LVL option only for other platforms. --- src/uu/who/src/who.rs | 17 +++++++++++------ tests/by-util/test_who.rs | 17 ++++++++++++++++- 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/src/uu/who/src/who.rs b/src/uu/who/src/who.rs index 1ae4f1c8d..81fc2a687 100644 --- a/src/uu/who/src/who.rs +++ b/src/uu/who/src/who.rs @@ -29,7 +29,7 @@ mod options { pub const ONLY_HOSTNAME_USER: &str = "only_hostname_user"; pub const PROCESS: &str = "process"; pub const COUNT: &str = "count"; - #[cfg(any(target_vendor = "apple", target_os = "linux", target_os = "android"))] + #[cfg(any(target_os = "linux", target_os = "android"))] pub const RUNLEVEL: &str = "runlevel"; pub const SHORT: &str = "short"; pub const TIME: &str = "time"; @@ -119,11 +119,13 @@ pub fn uumain(args: impl uucore::Args) -> i32 { .help("all login names and number of users logged on"), ) .arg( - #[cfg(any(target_vendor = "apple", target_os = "linux", target_os = "android"))] + #[cfg(any(target_os = "linux", target_os = "android"))] Arg::with_name(options::RUNLEVEL) .long(options::RUNLEVEL) .short("r") .help("print current runlevel"), + #[cfg(any(target_vendor = "apple", target_os = "freebsd"))] + Arg::with_name(""), ) .arg( Arg::with_name(options::SHORT) @@ -265,10 +267,13 @@ pub fn uumain(args: impl uucore::Args) -> i32 { assumptions = false; } - if matches.is_present(options::RUNLEVEL) { - need_runlevel = true; - include_idle = true; - assumptions = false; + #[cfg(any(target_os = "linux", target_os = "android"))] + { + if matches.is_present(options::RUNLEVEL) { + need_runlevel = true; + include_idle = true; + assumptions = false; + } } if matches.is_present(options::SHORT) { diff --git a/tests/by-util/test_who.rs b/tests/by-util/test_who.rs index 725ec0b1e..1aa8d604d 100644 --- a/tests/by-util/test_who.rs +++ b/tests/by-util/test_who.rs @@ -83,7 +83,7 @@ fn test_process() { } } -#[cfg(any(target_vendor = "apple", target_os = "linux"))] +#[cfg(target_os = "linux")] #[test] fn test_runlevel() { for opt in vec!["-r", "--runlevel"] { @@ -94,6 +94,19 @@ fn test_runlevel() { } } +#[cfg(any(target_vendor = "apple", target_os = "freebsd"))] +#[test] +fn test_runlevel() { + let expected = + "error: Found argument"; + for opt in vec!["-r", "--runlevel"] { + new_ucmd!() + .arg(opt) + .fails() + .stderr_contains(expected); + } +} + #[cfg(any(target_vendor = "apple", target_os = "linux"))] #[test] fn test_time() { @@ -122,6 +135,7 @@ fn test_mesg() { } } +#[cfg(target_os = "linux")] #[test] fn test_arg1_arg2() { let args = ["am", "i"]; @@ -132,6 +146,7 @@ fn test_arg1_arg2() { .stdout_is(expected_result(&args)); } +#[cfg(target_os = "linux")] #[test] fn test_too_many_args() { const EXPECTED: &str =