mirror of
https://github.com/uutils/coreutils.git
synced 2026-06-10 15:48:22 -07:00
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:
committed by
Daniel Hofstetter
parent
6e118e600d
commit
b372e0ff9e
@@ -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!()
|
||||
|
||||
Reference in New Issue
Block a user