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
This commit is contained in:
@@ -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";
|
||||
@@ -108,3 +108,27 @@ fn test_short_invalid_utmp_file() {
|
||||
.succeeds()
|
||||
.stdout_matches(®ex);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[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",
|
||||
"ferris tty2 Sat Mar 8 16:24 - 16:29 (00:04) :0",
|
||||
"reboot system boot Sat Mar 8 16:24 still running 6.8.0-55-generic",
|
||||
];
|
||||
|
||||
let hostlast_arg = "--hostlast";
|
||||
let result = new_ucmd!()
|
||||
.arg("--file")
|
||||
.arg("last.input.1")
|
||||
.arg(hostlast_arg)
|
||||
.arg("-n")
|
||||
.arg("3")
|
||||
.succeeds();
|
||||
|
||||
// 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);
|
||||
}
|
||||
|
||||
BIN
tests/fixtures/last/last.input.1
vendored
Normal file
BIN
tests/fixtures/last/last.input.1
vendored
Normal file
Binary file not shown.
Reference in New Issue
Block a user