From 208d8a7821e7aaa2102d79027a819d6f45c2e62e Mon Sep 17 00:00:00 2001 From: Lionel Mendes <62207225+LionelMeli@users.noreply.github.com> Date: Sat, 8 Mar 2025 09:35:18 +0100 Subject: [PATCH 1/8] last: fix not all hostnames are shown in the last column with --hostlast option --- src/uu/last/src/platform/unix.rs | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/uu/last/src/platform/unix.rs b/src/uu/last/src/platform/unix.rs index d8f3f2c8..05c224fc 100644 --- a/src/uu/last/src/platform/unix.rs +++ b/src/uu/last/src/platform/unix.rs @@ -520,16 +520,15 @@ 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: Date: Sat, 8 Mar 2025 10:07:52 +0100 Subject: [PATCH 2/8] last: fix not all hostnames are shown in the last column with --hostlast option --- src/uu/last/src/platform/unix.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/uu/last/src/platform/unix.rs b/src/uu/last/src/platform/unix.rs index 05c224fc..48ecb568 100644 --- a/src/uu/last/src/platform/unix.rs +++ b/src/uu/last/src/platform/unix.rs @@ -520,8 +520,8 @@ impl Last { write!(buf, " {host_to_print:<16}").unwrap_or_default(); } - let end_time_delta = format!("{end_time:<6} {delta}"); if self.time_format != "notime" { + let end_time_delta = format!("{end_time:<6} {delta}"); write!(buf, " {time:<12}").unwrap_or_default(); write!(buf, " {end_time_delta:<18}").unwrap_or_default(); } From e1438d255f666caf5485f114e8e615917f3eb712 Mon Sep 17 00:00:00 2001 From: Lionel Mendes <62207225+LionelMeli@users.noreply.github.com> Date: Sun, 9 Mar 2025 08:33:28 +0100 Subject: [PATCH 3/8] Added test case related to the hostlast option in last command. --- src/uu/last/src/platform/unix.rs | 9 ++++++--- tests/by-util/test_last.rs | 27 +++++++++++++++++++++++++++ tests/fixtures/last/last.input.bin | Bin 0 -> 1920 bytes 3 files changed, 33 insertions(+), 3 deletions(-) create mode 100644 tests/fixtures/last/last.input.bin diff --git a/src/uu/last/src/platform/unix.rs b/src/uu/last/src/platform/unix.rs index 48ecb568..beffc00e 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), @@ -521,9 +521,12 @@ impl Last { } if self.time_format != "notime" { + let time_ftm = 12; let end_time_delta = format!("{end_time:<6} {delta}"); - write!(buf, " {time:<12}").unwrap_or_default(); - write!(buf, " {end_time_delta:<18}").unwrap_or_default(); + let end_time_delta_fmt = 18; + + write!(buf, " {time: = ouput.split('\n').collect(); + // Remove the last 3 lines to compare easier with the expected output (so without the information about the begin of file) + output_result.truncate(output_result.len() - 3); + + assert_eq!(output_expected, output_result); +} diff --git a/tests/fixtures/last/last.input.bin b/tests/fixtures/last/last.input.bin new file mode 100644 index 0000000000000000000000000000000000000000..2d7e211ff91b65a92a8ce316c76111beb1bb8650 GIT binary patch literal 1920 zcmZQ#fPgwEjf<)SDkw@#%Fi#srGkOMOwU5kK-bh%H$62kwJ0+gx60uy_FZLRtAQWl1d{K2`rqn z)S{xyVk{C+Au9viawAD502uyqEu2JonFFYb*zhN0;Ar?mLa4IfOnTiy7DB-VmItN( Y3}94^rhlS>izr3S!0_ju!A6u?0HFFU^Z)<= literal 0 HcmV?d00001 From 7759fc58b4b37e31750c47acf27a2a7a0bb4cdd5 Mon Sep 17 00:00:00 2001 From: Lionel Mendes <62207225+LionelMeli@users.noreply.github.com> Date: Sun, 9 Mar 2025 19:20:13 +0100 Subject: [PATCH 4/8] Change binary input fixture name for last command and Fix format source code. --- tests/by-util/test_last.rs | 6 +++--- .../fixtures/last/{last.input.bin => last.input.1} | Bin 2 files changed, 3 insertions(+), 3 deletions(-) rename tests/fixtures/last/{last.input.bin => last.input.1} (100%) diff --git a/tests/by-util/test_last.rs b/tests/by-util/test_last.rs index 67f60d18..ecc5db14 100644 --- a/tests/by-util/test_last.rs +++ b/tests/by-util/test_last.rs @@ -121,14 +121,14 @@ fn test_display_hostname_last_column() { let hostlast_arg = "--hostlast"; let result = new_ucmd!() .arg("--file") - .arg("last.input.bin") + .arg("last.input.1") .arg(hostlast_arg) .arg("-n") .arg("3") .succeeds(); - let ouput = - String::from_utf8(result.stdout().to_vec()).unwrap_or("Failed to convert output to string".to_string()); + let ouput = String::from_utf8(result.stdout().to_vec()) + .unwrap_or("Failed to convert output to string".to_string()); let mut output_result: Vec<&str> = ouput.split('\n').collect(); // Remove the last 3 lines to compare easier with the expected output (so without the information about the begin of file) output_result.truncate(output_result.len() - 3); diff --git a/tests/fixtures/last/last.input.bin b/tests/fixtures/last/last.input.1 similarity index 100% rename from tests/fixtures/last/last.input.bin rename to tests/fixtures/last/last.input.1 From ed64cf7ec36b51785deed0cef43267f2e9c00193 Mon Sep 17 00:00:00 2001 From: Lionel Mendes <62207225+LionelMeli@users.noreply.github.com> Date: Thu, 8 May 2025 10:36:07 +0200 Subject: [PATCH 5/8] feat: add macOS platform & update tests for compatibility --- src/uu/last/src/platform/macos.rs | 17 +++++++++++++++++ src/uu/last/src/platform/mod.rs | 9 +++++++-- tests/by-util/test_last.rs | 2 +- 3 files changed, 25 insertions(+), 3 deletions(-) create mode 100644 src/uu/last/src/platform/macos.rs diff --git a/src/uu/last/src/platform/macos.rs b/src/uu/last/src/platform/macos.rs new file mode 100644 index 00000000..d0c2dc85 --- /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 b3b1aa6c..dc953bf0 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::*; \ No newline at end of file diff --git a/tests/by-util/test_last.rs b/tests/by-util/test_last.rs index ecc5db14..260f2541 100644 --- a/tests/by-util/test_last.rs +++ b/tests/by-util/test_last.rs @@ -110,7 +110,7 @@ fn test_short_invalid_utmp_file() { } #[test] -#[cfg(unix)] +#[cfg(all(unix, not(target_os="macos"), not(target_os="openbsd")))] fn test_display_hostname_last_column() { let output_expected = vec![ "ferris tty2 Sat Mar 8 16:29 still logged in :0", From 8f9e7b8ffada674d3ade787da9c0f11abf3c5921 Mon Sep 17 00:00:00 2001 From: Lionel Mendes <62207225+LionelMeli@users.noreply.github.com> Date: Thu, 8 May 2025 11:50:24 +0200 Subject: [PATCH 6/8] fix: correct formatting in platform and test files for macOS compatibility --- src/uu/last/src/platform/mod.rs | 4 ++-- tests/by-util/test_last.rs | 14 +++++++------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/uu/last/src/platform/mod.rs b/src/uu/last/src/platform/mod.rs index dc953bf0..c63cac62 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(all(unix,not(target_os = "macos")))] +#[cfg(all(unix, not(target_os = "macos")))] mod unix; -#[cfg(all(unix,not(target_os = "macos")))] +#[cfg(all(unix, not(target_os = "macos")))] pub use self::unix::*; #[cfg(target_os = "openbsd")] diff --git a/tests/by-util/test_last.rs b/tests/by-util/test_last.rs index 260f2541..79b644d0 100644 --- a/tests/by-util/test_last.rs +++ b/tests/by-util/test_last.rs @@ -17,7 +17,7 @@ fn test_invalid_arg() { } #[test] -#[cfg(unix)] +#[cfg(all(unix, not(target_os = "macos")))] fn test_last() { let regex = Regex::new("still running|still logged in").unwrap(); TestScenario::new(util_name!()) @@ -27,7 +27,7 @@ fn test_last() { } #[test] -#[cfg(unix)] +#[cfg(all(unix, not(target_os = "macos")))] fn test_limit_arg() { let line_check = |input: &str| input.lines().count() == 3; new_ucmd!() @@ -58,7 +58,7 @@ fn test_timestamp_format_no_time() { } #[test] -#[cfg(unix)] +#[cfg(all(unix, not(target_os = "macos")))] fn test_timestamp_format_short() { let regex = Regex::new(" [0-9][0-9]:[0-9][0-9] ").unwrap(); new_ucmd!() @@ -68,7 +68,7 @@ fn test_timestamp_format_short() { } #[test] -#[cfg(unix)] +#[cfg(all(unix, not(target_os = "macos")))] fn test_timestamp_format_full() { let regex = Regex::new(" [0-9][0-9]:[0-9][0-9]:[0-9][0-9] ").unwrap(); new_ucmd!() @@ -79,7 +79,7 @@ fn test_timestamp_format_full() { // 2024-07-11T19:30:44+08:00 #[test] -#[cfg(unix)] +#[cfg(all(unix, not(target_os = "macos")))] fn test_timestamp_format_iso() { let regex = Regex::new(" [0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]T[0-9][0-9]:[0-9][0-9]:[0-9][0-9]") @@ -91,7 +91,7 @@ fn test_timestamp_format_iso() { } #[test] -#[cfg(unix)] +#[cfg(all(unix, not(target_os = "macos")))] fn test_short_invalid_utmp_file() { let (at, mut ucmd) = at_and_ucmd!(); let file = "testfile"; @@ -110,7 +110,7 @@ fn test_short_invalid_utmp_file() { } #[test] -#[cfg(all(unix, not(target_os="macos"), not(target_os="openbsd")))] +#[cfg(all(unix, not(target_os = "macos"), not(target_os = "openbsd")))] fn test_display_hostname_last_column() { let output_expected = vec![ "ferris tty2 Sat Mar 8 16:29 still logged in :0", From 14e6068d5ba96f207872174075e281cdd76162a0 Mon Sep 17 00:00:00 2001 From: Lionel Mendes <62207225+LionelMeli@users.noreply.github.com> Date: Thu, 8 May 2025 12:03:04 +0200 Subject: [PATCH 7/8] fix: format --- src/uu/last/src/platform/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/uu/last/src/platform/mod.rs b/src/uu/last/src/platform/mod.rs index c63cac62..73deaaf6 100644 --- a/src/uu/last/src/platform/mod.rs +++ b/src/uu/last/src/platform/mod.rs @@ -21,4 +21,4 @@ pub use self::windows::*; #[cfg(target_os = "macos")] mod macos; #[cfg(target_os = "macos")] -pub use self::macos::*; \ No newline at end of file +pub use self::macos::*; From e1c094d234b878b8943f17fa47d1d1bf3f336458 Mon Sep 17 00:00:00 2001 From: Lionel Mendes <62207225+LionelMeli@users.noreply.github.com> Date: Thu, 8 May 2025 17:05:18 +0200 Subject: [PATCH 8/8] fix: correct variable name and improve test output handling --- src/uu/last/src/platform/unix.rs | 4 ++-- tests/by-util/test_last.rs | 7 ++----- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/src/uu/last/src/platform/unix.rs b/src/uu/last/src/platform/unix.rs index beffc00e..8241770d 100644 --- a/src/uu/last/src/platform/unix.rs +++ b/src/uu/last/src/platform/unix.rs @@ -521,11 +521,11 @@ impl Last { } if self.time_format != "notime" { - let time_ftm = 12; + let time_fmt = 12; let end_time_delta = format!("{end_time:<6} {delta}"); let end_time_delta_fmt = 18; - write!(buf, " {time: = ouput.split('\n').collect(); - // Remove the last 3 lines to compare easier with the expected output (so without the information about the begin of file) - output_result.truncate(output_result.len() - 3); + // Keep only the three 1st lines to compare easier with the expected output (so without the information about the begin date of file) + let output_result: Vec<_> = result.stdout_str().lines().take(3).collect(); assert_eq!(output_expected, output_result); }