From e4aa8ee1593e24d5fc064e0cd2c83a000f3ec0d4 Mon Sep 17 00:00:00 2001 From: Jan Scheer Date: Sat, 29 May 2021 01:51:00 +0200 Subject: [PATCH] users: fix long_help text and clippy warning --- src/uu/users/src/users.rs | 21 +++++++++++++-------- tests/by-util/test_users.rs | 28 ++++++++++++---------------- 2 files changed, 25 insertions(+), 24 deletions(-) diff --git a/src/uu/users/src/users.rs b/src/uu/users/src/users.rs index 4bb628441..99e06c1af 100644 --- a/src/uu/users/src/users.rs +++ b/src/uu/users/src/users.rs @@ -6,19 +6,14 @@ // * For the full copyright and license information, please view the LICENSE // * file that was distributed with this source code. -/* last synced with: whoami (GNU coreutils) 8.22 */ -// Allow dead code here in order to keep all fields, constants here, for consistency. -#![allow(dead_code)] - #[macro_use] extern crate uucore; -use uucore::utmpx::*; - use clap::{App, Arg}; +use uucore::utmpx::{self, Utmpx}; -static ABOUT: &str = "Display who is currently logged in, according to FILE."; static VERSION: &str = env!("CARGO_PKG_VERSION"); +static ABOUT: &str = "Print the user names of users currently logged in to the current host"; static ARG_FILES: &str = "files"; @@ -26,13 +21,23 @@ fn get_usage() -> String { format!("{0} [FILE]", executable!()) } +fn get_long_usage() -> String { + format!( + "Output who is currently logged in according to FILE. +If FILE is not specified, use {}. /var/log/wtmp as FILE is common.", + utmpx::DEFAULT_FILE + ) +} + pub fn uumain(args: impl uucore::Args) -> i32 { let usage = get_usage(); + let after_help = get_long_usage(); let matches = App::new(executable!()) .version(VERSION) .about(ABOUT) .usage(&usage[..]) + .after_help(&after_help[..]) .arg(Arg::with_name(ARG_FILES).takes_value(true).max_values(1)) .get_matches_from(args); @@ -44,7 +49,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 { let filename = if !files.is_empty() { files[0].as_ref() } else { - DEFAULT_FILE + utmpx::DEFAULT_FILE }; let mut users = Utmpx::iter_all_records() diff --git a/tests/by-util/test_users.rs b/tests/by-util/test_users.rs index 3c5789820..89c3fdd0f 100644 --- a/tests/by-util/test_users.rs +++ b/tests/by-util/test_users.rs @@ -1,27 +1,23 @@ use crate::common::util::*; -use std::env; #[test] fn test_users_noarg() { new_ucmd!().succeeds(); } + #[test] +#[cfg(any(target_vendor = "apple", target_os = "linux"))] fn test_users_check_name() { - let result = TestScenario::new(util_name!()).ucmd_keepenv().succeeds(); + #[cfg(target_os = "linux")] + let util_name = util_name!(); + #[cfg(target_vendor = "apple")] + let util_name = format!("g{}", util_name!()); - // Expectation: USER is often set - let key = "USER"; + let expected = TestScenario::new(&util_name) + .cmd_keepenv(util_name) + .env("LANGUAGE", "C") + .succeeds() + .stdout_move_str(); - match env::var(key) { - Err(e) => println!("Key {} isn't set. Found {}", &key, e), - Ok(username) => - // Check if "users" contains the name of the user - { - println!("username found {}", &username); - // println!("result.stdout {}", &result.stdout); - if !result.stdout_str().is_empty() { - result.stdout_contains(&username); - } - } - } + new_ucmd!().succeeds().stdout_is(&expected); }