Don't let a missing serial listing discard an 'all' discovery on Windows

Windows CI (run 415) ran the discovery tests: 48 passed and one failed,
because port listing reads Linux sysfs and the test assumed it exists.
That is a real limitation, not just a bad test - and in the example it
meant `all` would listen and sweep and then abort on the serial step,
throwing the results away.

The serial step in `all` is now a printed note on failure; the standalone
`serial` command still errors. The Linux-only test is gated to Linux and
a counterpart asserts that off Linux the listing is an error, not a clean
empty result.
This commit is contained in:
2026-10-29 11:17:01 +00:00
parent 970db780be
commit 9061d39684
2 changed files with 17 additions and 1 deletions
+6 -1
View File
@@ -69,7 +69,12 @@ async fn main() -> anyhow::Result<()> {
// picking one would mean probing a network nobody named. // picking one would mean probing a network nobody named.
None => println!("(no subnet given, so no sweep - pass one like 192.168.0.0/24 to include it)"), None => println!("(no subnet given, so no sweep - pass one like 192.168.0.0/24 to include it)"),
} }
found.extend(list_serial()?); // Not `?`: serial listing reads Linux sysfs and fails on any other
// OS, and that must not throw away what the listen and sweep found.
match list_serial() {
Ok(ports) => found.extend(ports),
Err(err) => println!("(serial ports skipped: {err})"),
}
found found
} }
"listen" | "raw" => { "listen" | "raw" => {
+11
View File
@@ -485,6 +485,7 @@ mod tests {
/// The one part of serial discovery this environment can demonstrate: /// The one part of serial discovery this environment can demonstrate:
/// with no ports attached it finds none, and does not error doing it. /// with no ports attached it finds none, and does not error doing it.
#[cfg(target_os = "linux")]
#[test] #[test]
fn listing_ports_where_there_are_none_is_empty_and_not_an_error() { fn listing_ports_where_there_are_none_is_empty_and_not_an_error() {
let ports = list_ports().expect("sysfs exists on this host"); let ports = list_ports().expect("sysfs exists on this host");
@@ -492,4 +493,14 @@ mod tests {
assert!(port.path.starts_with("/dev/"), "{port:?}"); assert!(port.path.starts_with("/dev/"), "{port:?}");
} }
} }
/// Port listing reads Linux sysfs, so elsewhere it must say so rather
/// than report "no ports" - which would look like a clean scan (found on
/// Windows CI, run 415, where the Linux test above failed).
#[cfg(not(target_os = "linux"))]
#[test]
fn listing_ports_off_linux_is_an_error_not_an_empty_list() {
let err = list_ports().expect_err("there is no sysfs here");
assert!(err.to_string().contains("not a Linux host"), "{err}");
}
} }