From 55c8ee013b436f46786f0a06189090fb5793b274 Mon Sep 17 00:00:00 2001 From: Lionel Mendes <62207225+LionelMeli@users.noreply.github.com> Date: Thu, 8 May 2025 17:32:25 +0200 Subject: [PATCH] last: fix some hostnames are not shown properly with --hostname option issue 212 (#246) * last: fix not all hostnames are shown in the last column with --hostlast option * last: fix not all hostnames are shown in the last column with --hostlast option * Added test case related to the hostlast option in last command. * Change binary input fixture name for last command and Fix format source code. * feat: add macOS platform & update tests for compatibility * fix: correct formatting in platform and test files for macOS compatibility * fix: format * fix: correct variable name and improve test output handling --- src/uu/last/src/platform/macos.rs | 17 ++++++++++++++ src/uu/last/src/platform/mod.rs | 9 ++++++-- src/uu/last/src/platform/unix.rs | 22 +++++++++--------- tests/by-util/test_last.rs | 36 +++++++++++++++++++++++++----- tests/fixtures/last/last.input.1 | Bin 0 -> 1920 bytes 5 files changed, 66 insertions(+), 18 deletions(-) create mode 100644 src/uu/last/src/platform/macos.rs create mode 100644 tests/fixtures/last/last.input.1 diff --git a/src/uu/last/src/platform/macos.rs b/src/uu/last/src/platform/macos.rs new file mode 100644 index 0000000..d0c2dc8 --- /dev/null +++ b/src/uu/last/src/platform/macos.rs @@ -0,0 +1,17 @@ +// This file is part of the uutils util-linux package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. + +// Specific implementation for OpenBSD: tool unsupported (utmpx not supported) + +use crate::uu_app; + +use uucore::error::UResult; + +pub fn uumain(args: impl uucore::Args) -> UResult<()> { + let _matches = uu_app().try_get_matches_from(args)?; + + println!("unsupported command on macOS"); + Ok(()) +} diff --git a/src/uu/last/src/platform/mod.rs b/src/uu/last/src/platform/mod.rs index b3b1aa6..73deaaf 100644 --- a/src/uu/last/src/platform/mod.rs +++ b/src/uu/last/src/platform/mod.rs @@ -3,9 +3,9 @@ // For the full copyright and license information, please view the LICENSE // file that was distributed with this source code. -#[cfg(unix)] +#[cfg(all(unix, not(target_os = "macos")))] mod unix; -#[cfg(unix)] +#[cfg(all(unix, not(target_os = "macos")))] pub use self::unix::*; #[cfg(target_os = "openbsd")] @@ -17,3 +17,8 @@ pub use self::openbsd::*; mod windows; #[cfg(windows)] pub use self::windows::*; + +#[cfg(target_os = "macos")] +mod macos; +#[cfg(target_os = "macos")] +pub use self::macos::*; diff --git a/src/uu/last/src/platform/unix.rs b/src/uu/last/src/platform/unix.rs index d8f3f2c..8241770 100644 --- a/src/uu/last/src/platform/unix.rs +++ b/src/uu/last/src/platform/unix.rs @@ -369,7 +369,7 @@ impl Last { .unwrap_or_else(|| time::OffsetDateTime::from_unix_timestamp(0).unwrap()); let time_delta = duration_string(calculate_time_delta(&curr_datetime, &shutdown)); if ut.is_user_process() { - proc_status = Some("- down"); + proc_status = Some("- down "); } ( self.end_time_string(proc_status, &shutdown), @@ -520,16 +520,18 @@ impl Last { write!(buf, " {host_to_print:<16}").unwrap_or_default(); } - let time_size = 3 + 2 + 2 + 1 + 2; - if self.host_last && !self.no_host && self.time_format != "notime" { - write!(buf, " {time: = result.stdout_str().lines().take(3).collect(); + + assert_eq!(output_expected, output_result); +} diff --git a/tests/fixtures/last/last.input.1 b/tests/fixtures/last/last.input.1 new file mode 100644 index 0000000000000000000000000000000000000000..2d7e211ff91b65a92a8ce316c76111beb1bb8650 GIT binary patch literal 1920 zcmZQ#fPgv(g_EqSV_+ysP0G(N!KsA7OwU5kK-bh%H$62kwJ0+gx60uy zlp!s(s3@}-w<;?G+;SsHCLsSzx?Bq