diff --git a/src/uu/test/src/test.rs b/src/uu/test/src/test.rs index c220ef7e9..e6e2e5360 100644 --- a/src/uu/test/src/test.rs +++ b/src/uu/test/src/test.rs @@ -245,12 +245,12 @@ fn integers(a: &OsStr, b: &OsStr, op: &OsStr) -> Result { let format_err = |value: &OsStr| format!("invalid integer {}", value.quote()); // Parse the two inputs - let a: i64 = a + let a: i128 = a .to_str() .and_then(|s| s.parse().ok()) .ok_or_else(|| format_err(a))?; - let b: i64 = b + let b: i128 = b .to_str() .and_then(|s| s.parse().ok()) .ok_or_else(|| format_err(b))?; @@ -442,3 +442,28 @@ fn path(path: &OsStr, condition: &PathCondition) -> bool { PathCondition::Executable => false, // TODO } } + +#[cfg(test)] +mod tests { + use super::integers; + use std::ffi::OsStr; + + #[test] + fn test_integer_op() { + let a = OsStr::new("18446744073709551616"); + let b = OsStr::new("0"); + assert_eq!(integers(a, b, OsStr::new("-lt")).unwrap(), false); + let a = OsStr::new("18446744073709551616"); + let b = OsStr::new("0"); + assert_eq!(integers(a, b, OsStr::new("-gt")).unwrap(), true); + let a = OsStr::new("-1"); + let b = OsStr::new("0"); + assert_eq!(integers(a, b, OsStr::new("-lt")).unwrap(), true); + let a = OsStr::new("42"); + let b = OsStr::new("42"); + assert_eq!(integers(a, b, OsStr::new("-eq")).unwrap(), true); + let a = OsStr::new("42"); + let b = OsStr::new("42"); + assert_eq!(integers(a, b, OsStr::new("-ne")).unwrap(), false); + } +} diff --git a/tests/by-util/test_test.rs b/tests/by-util/test_test.rs index 028babc4b..54ee03985 100644 --- a/tests/by-util/test_test.rs +++ b/tests/by-util/test_test.rs @@ -929,3 +929,26 @@ fn test_file_N() { at.touch("regular_file"); scene.ucmd().args(&["-N", "regular_file"]).succeeds(); } + +#[test] +fn test_long_integer() { + let scene = TestScenario::new(util_name!()); + scene + .ucmd() + .args(&["18446744073709551616", "-eq", "0"]) + .fails(); + scene + .ucmd() + .args(&["-9223372036854775809", "-ge", "18446744073709551616"]) + .fails(); + scene + .ucmd() + .args(&[ + "'('", + "-9223372036854775809", + "-ge", + "18446744073709551616", + "')'", + ]) + .fails(); +}