diff --git a/src/uu/who/src/who.rs b/src/uu/who/src/who.rs index 81fc2a687..19ae3addb 100644 --- a/src/uu/who/src/who.rs +++ b/src/uu/who/src/who.rs @@ -29,7 +29,6 @@ mod options { pub const ONLY_HOSTNAME_USER: &str = "only_hostname_user"; pub const PROCESS: &str = "process"; pub const COUNT: &str = "count"; - #[cfg(any(target_os = "linux", target_os = "android"))] pub const RUNLEVEL: &str = "runlevel"; pub const SHORT: &str = "short"; pub const TIME: &str = "time"; @@ -41,6 +40,11 @@ mod options { static VERSION: &str = env!("CARGO_PKG_VERSION"); static ABOUT: &str = "Print information about users who are currently logged in."; +#[cfg(any(target_os = "linux"))] +static RUNLEVEL_HELP: &str = "print current runlevel"; +#[cfg(not(target_os = "linux"))] +static RUNLEVEL_HELP: &str = "print current runlevel (This is meaningless on non Linux)"; + fn get_usage() -> String { format!("{0} [OPTION]... [ FILE | ARG1 ARG2 ]", executable!()) } @@ -119,13 +123,10 @@ pub fn uumain(args: impl uucore::Args) -> i32 { .help("all login names and number of users logged on"), ) .arg( - #[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(""), + .help(RUNLEVEL_HELP), ) .arg( Arg::with_name(options::SHORT) @@ -267,13 +268,10 @@ pub fn uumain(args: impl uucore::Args) -> i32 { 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::RUNLEVEL) { + need_runlevel = true; + include_idle = true; + assumptions = false; } if matches.is_present(options::SHORT) { @@ -389,15 +387,12 @@ fn current_tty() -> String { impl Who { fn exec(&mut self) { - let run_level_chk = |record: i16| { - #[allow(unused_assignments)] - let mut res = false; + let run_level_chk = |_record: i16| { + #[cfg(not(target_os = "linux"))] + return false; - #[cfg(any(target_vendor = "apple", target_os = "linux", target_os = "android"))] - { - res = record == utmpx::RUN_LVL; - } - res + #[cfg(target_os = "linux")] + return _record == utmpx::RUN_LVL; }; let f = if self.args.len() == 1 { @@ -430,7 +425,9 @@ impl Who { if self.need_users && ut.is_user_process() { self.print_user(&ut); } else if self.need_runlevel && run_level_chk(ut.record_type()) { - self.print_runlevel(&ut); + if cfg!(target_os = "linux") { + self.print_runlevel(&ut); + } } else if self.need_boottime && ut.record_type() == utmpx::BOOT_TIME { self.print_boottime(&ut); } else if self.need_clockchange && ut.record_type() == utmpx::NEW_TIME { diff --git a/tests/by-util/test_who.rs b/tests/by-util/test_who.rs index 1aa8d604d..21b5eb93e 100644 --- a/tests/by-util/test_who.rs +++ b/tests/by-util/test_who.rs @@ -83,27 +83,17 @@ fn test_process() { } } -#[cfg(target_os = "linux")] #[test] fn test_runlevel() { for opt in vec!["-r", "--runlevel"] { + #[cfg(any(target_vendor = "apple", target_os = "linux"))] new_ucmd!() .arg(opt) .succeeds() .stdout_is(expected_result(&[opt])); - } -} -#[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(not(target_os = "linux"))] + new_ucmd!().arg(opt).succeeds().stdout_is(""); } } @@ -135,7 +125,6 @@ fn test_mesg() { } } -#[cfg(target_os = "linux")] #[test] fn test_arg1_arg2() { let args = ["am", "i"]; @@ -146,7 +135,6 @@ fn test_arg1_arg2() { .stdout_is(expected_result(&args)); } -#[cfg(target_os = "linux")] #[test] fn test_too_many_args() { const EXPECTED: &str = @@ -168,11 +156,11 @@ fn test_users() { let mut v_actual: Vec<&str> = actual.split_whitespace().collect(); let mut v_expect: Vec<&str> = expect.split_whitespace().collect(); - // TODO: `--users` differs from GNU's output on manOS running in CI + // TODO: `--users` differs from GNU's output on macOS // Diff < left / right > : // <"runner console 2021-05-20 22:03 00:08 196\n" // >"runner console 2021-05-20 22:03 old 196\n" - if is_ci() && cfg!(target_os = "macos") { + if cfg!(target_os = "macos") { v_actual.remove(4); v_expect.remove(4); } @@ -206,7 +194,7 @@ fn test_dead() { #[cfg(any(target_vendor = "apple", target_os = "linux"))] #[test] fn test_all_separately() { - if is_ci() && cfg!(target_os = "macos") { + if cfg!(target_os = "macos") { // TODO: fix `-u`, see: test_users return; } @@ -229,7 +217,7 @@ fn test_all_separately() { #[cfg(any(target_vendor = "apple", target_os = "linux"))] #[test] fn test_all() { - if is_ci() && cfg!(target_os = "macos") { + if cfg!(target_os = "macos") { // TODO: fix `-u`, see: test_users return; }