mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 11:37:44 +00:00
Merge pull request #2696 from jhscheer/fix_check_coreutil_version
common/util: fix parsing of coreutil version
This commit is contained in:
commit
fb5650951e
1 changed files with 45 additions and 1 deletions
|
@ -1169,7 +1169,7 @@ pub fn check_coreutil_version(
|
||||||
if s.contains(&format!("(GNU coreutils) {}", version_expected)) {
|
if s.contains(&format!("(GNU coreutils) {}", version_expected)) {
|
||||||
Ok(format!("{}: {}", UUTILS_INFO, s.to_string()))
|
Ok(format!("{}: {}", UUTILS_INFO, s.to_string()))
|
||||||
} else if s.contains("(GNU coreutils)") {
|
} else if s.contains("(GNU coreutils)") {
|
||||||
let version_found = s.split_whitespace().last().unwrap()[..4].parse::<f32>().unwrap_or_default();
|
let version_found = parse_coreutil_version(s);
|
||||||
let version_expected = version_expected.parse::<f32>().unwrap_or_default();
|
let version_expected = version_expected.parse::<f32>().unwrap_or_default();
|
||||||
if version_found > version_expected {
|
if version_found > version_expected {
|
||||||
Ok(format!("{}: version for the reference coreutil '{}' is higher than expected; expected: {}, found: {}", UUTILS_INFO, util_name, version_expected, version_found))
|
Ok(format!("{}: version for the reference coreutil '{}' is higher than expected; expected: {}, found: {}", UUTILS_INFO, util_name, version_expected, version_found))
|
||||||
|
@ -1182,6 +1182,20 @@ pub fn check_coreutil_version(
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// simple heuristic to parse the coreutils SemVer string, e.g. "id (GNU coreutils) 8.32.263-0475"
|
||||||
|
fn parse_coreutil_version(version_string: &str) -> f32 {
|
||||||
|
version_string
|
||||||
|
.split_whitespace()
|
||||||
|
.last()
|
||||||
|
.unwrap()
|
||||||
|
.split('.')
|
||||||
|
.take(2)
|
||||||
|
.collect::<Vec<_>>()
|
||||||
|
.join(".")
|
||||||
|
.parse::<f32>()
|
||||||
|
.unwrap_or_default()
|
||||||
|
}
|
||||||
|
|
||||||
/// This runs the GNU coreutils `util_name` binary in `$PATH` in order to
|
/// This runs the GNU coreutils `util_name` binary in `$PATH` in order to
|
||||||
/// dynamically gather reference values on the system.
|
/// dynamically gather reference values on the system.
|
||||||
/// If the `util_name` in `$PATH` doesn't include a coreutils version string,
|
/// If the `util_name` in `$PATH` doesn't include a coreutils version string,
|
||||||
|
@ -1474,6 +1488,36 @@ mod tests {
|
||||||
res.normalized_newlines_stdout_is("A\r\nB\nC\n");
|
res.normalized_newlines_stdout_is("A\r\nB\nC\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[cfg(unix)]
|
||||||
|
fn test_parse_coreutil_version() {
|
||||||
|
use std::assert_eq;
|
||||||
|
assert_eq!(
|
||||||
|
parse_coreutil_version("id (GNU coreutils) 9.0.123-0123").to_string(),
|
||||||
|
"9"
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
parse_coreutil_version("id (GNU coreutils) 8.32.263-0475").to_string(),
|
||||||
|
"8.32"
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
parse_coreutil_version("id (GNU coreutils) 8.25.123-0123").to_string(),
|
||||||
|
"8.25"
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
parse_coreutil_version("id (GNU coreutils) 9.0").to_string(),
|
||||||
|
"9"
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
parse_coreutil_version("id (GNU coreutils) 8.32").to_string(),
|
||||||
|
"8.32"
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
parse_coreutil_version("id (GNU coreutils) 8.25").to_string(),
|
||||||
|
"8.25"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
fn test_check_coreutil_version() {
|
fn test_check_coreutil_version() {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue