From b372e0ff9ea99b931cb41dffd13df8332bb0f26d Mon Sep 17 00:00:00 2001 From: Nihal Ajayakumar Date: Mon, 23 Feb 2026 15:08:31 -0500 Subject: [PATCH] hostid: add output format and help flag tests The existing test_normal test used the unanchored regex `^[0-9a-f]{8}`, which checks only the start of stdout. This would incorrectly accept output like "00000000garbage\n". The source formats output with `{result:0>8x}` via `writeln!`, producing exactly 8 lowercase hex digits and a newline. - Add test_output_format: asserts the complete output matches `^[0-9a-f]{8}\n$`, enforcing the full expected line format. - Add test_help: asserts --help exits with code 0 and stdout contains the expected about text. Follows the same pattern as test_arch_help in test_arch.rs. No production code is modified. --- tests/by-util/test_hostid.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/tests/by-util/test_hostid.rs b/tests/by-util/test_hostid.rs index 7d96adf59..98d9ba6f7 100644 --- a/tests/by-util/test_hostid.rs +++ b/tests/by-util/test_hostid.rs @@ -11,6 +11,23 @@ fn test_normal() { new_ucmd!().succeeds().stdout_matches(&re); } +#[test] +fn test_output_format() { + // Output must be exactly 8 lowercase hex digits followed by a newline. + // The stricter anchored regex catches outputs like "00000000garbage" + // that the existing test_normal regex would incorrectly accept. + let re = Regex::new(r"^[0-9a-f]{8}\n$").unwrap(); + new_ucmd!().succeeds().stdout_matches(&re); +} + +#[test] +fn test_help() { + new_ucmd!() + .arg("--help") + .succeeds() + .stdout_contains("Print the numeric identifier"); +} + #[test] fn test_invalid_flag() { new_ucmd!()