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.
This commit is contained in:
Nihal Ajayakumar
2026-02-23 15:08:31 -05:00
committed by Daniel Hofstetter
parent 6e118e600d
commit b372e0ff9e
+17
View File
@@ -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!()