test: fix tests when '-' is absent from kernel version (#6681)

On my machine, any test that calls `is_pidfd_available` fails as my
kernel string does not contain a '-'; the code expects there to be one.

Fix the test so that is works regardless on whether the kernel string
contains a '-'.
This commit is contained in:
Matthew Leach
2024-07-14 13:38:23 +09:00
committed by GitHub
parent c8f3539bc1
commit 4825c444eb
+6 -1
View File
@@ -245,7 +245,12 @@ mod test {
assert!(status.success());
let stdout = String::from_utf8_lossy(&stdout);
let mut kernel_version_iter = stdout.split_once('-').unwrap().0.split('.');
let mut kernel_version_iter = match stdout.split_once('-') {
Some((version, _)) => version,
_ => &stdout,
}
.split('.');
let major: u32 = kernel_version_iter.next().unwrap().parse().unwrap();
let minor: u32 = kernel_version_iter.next().unwrap().parse().unwrap();