Skip to content

Commit

Permalink
manage the special case 'find %A+'
Browse files Browse the repository at this point in the history
Closes: #451
  • Loading branch information
sylvestre committed Sep 22, 2024
1 parent 5cfac37 commit 40d29c2
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/find/matchers/printf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,11 @@ impl TimeFormat {
.to_string()
}
TimeFormat::Strftime(format) => {
DateTime::<Local>::from(time).format(format).to_string()
// Handle a special case
let custom_format = format.replace("%+", "%Y-%m-%d+%H:%M:%S%.f0");
DateTime::<Local>::from(time)
.format(&custom_format)
.to_string()
}
};

Expand Down
23 changes: 23 additions & 0 deletions tests/find_cmd_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

use assert_cmd::Command;
use predicates::prelude::*;
use regex::Regex;
use serial_test::serial;
use std::fs::{self, File};
use std::io::{Read, Write};
Expand Down Expand Up @@ -367,6 +368,28 @@ fn find_printf() {
./test_data/simple/subdir/ABBBC subdir/ABBBC f\n",
)));

fs::create_dir_all("a").expect("Failed to create directory 'a'");
let output = Command::cargo_bin("find")
.expect("found binary")
.args(["a", "-printf", "%A+"])
.assert()
.success()
.get_output()
.stdout
.clone();

let output_str = String::from_utf8(output).expect("Invalid UTF-8 in output");

println!("Actual output: '{}'", output_str.trim());

let re = Regex::new(r"^\d{4}-\d{2}-\d{2}\+\d{2}:\d{2}:\d{2}\.\d{9}0$")
.expect("Failed to compile regex");

assert!(

Check warning on line 388 in tests/find_cmd_tests.rs

View check run for this annotation

Codecov / codecov/patch

tests/find_cmd_tests.rs#L388

Added line #L388 was not covered by tests
re.is_match(output_str.trim()),
"Output did not match expected timestamp format"
);

Command::cargo_bin("find")
.expect("found binary")
.args([
Expand Down

0 comments on commit 40d29c2

Please sign in to comment.