Skip to content

Commit

Permalink
fixup! sort: support percent arguments to -S option
Browse files Browse the repository at this point in the history
  • Loading branch information
jfinkels committed Jan 20, 2025
1 parent cbbe9cc commit b6cd548
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/uucore/src/lib/parser/parse_size.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ fn total_physical_memory() -> Result<u128, SystemError> {
let line = line?;
if line.starts_with("MemTotal:") && line.ends_with("kB") {
let num_kilobytes: u128 = line[9..line.len() - 2].trim().parse()?;
dbg!(num_kilobytes);
let num_bytes = 1024 * num_kilobytes;
return Ok(num_bytes);
}
Expand Down Expand Up @@ -761,6 +760,7 @@ mod tests {
}

#[test]
#[cfg(target_os = "linux")]
fn parse_percent() {
assert!(parse_size_u64("0%").is_ok());
assert!(parse_size_u64("50%").is_ok());
Expand Down
6 changes: 6 additions & 0 deletions tests/by-util/test_sort.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@ fn test_helper(file_name: &str, possible_args: &[&str]) {

#[test]
fn test_buffer_sizes() {
#[cfg(target_os = "linux")]
let buffer_sizes = ["0", "50K", "50k", "1M", "100M", "0%", "10%"];
// TODO Percentage sizes are not yet supported beyond Linux.
#[cfg(not(target_os = "linux"))]
let buffer_sizes = ["0", "50K", "50k", "1M", "100M"];
for buffer_size in &buffer_sizes {
TestScenario::new(util_name!())
.ucmd()
Expand Down Expand Up @@ -73,6 +77,8 @@ fn test_invalid_buffer_size() {
.code_is(2)
.stderr_only("sort: invalid suffix in --buffer-size argument '100f'\n");

// TODO Percentage sizes are not yet supported beyond Linux.
#[cfg(target_os = "linux")]
new_ucmd!()
.arg("-S")
.arg("0x123%")
Expand Down

0 comments on commit b6cd548

Please sign in to comment.