Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

find: Implement -amin -cmin -mmin age ranges. #355

Merged
merged 14 commits into from
Jun 1, 2024

Conversation

hanbings
Copy link
Collaborator

implement: #221

Copy link

codecov bot commented Apr 19, 2024

Codecov Report

Attention: Patch coverage is 77.96610% with 13 lines in your changes are missing coverage. Please review.

Project coverage is 59.12%. Comparing base (add14db) to head (6579285).

Files Patch % Lines
src/find/matchers/time.rs 73.07% 3 Missing and 4 partials ⚠️
src/find/matchers/mod.rs 50.00% 2 Missing and 4 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #355      +/-   ##
==========================================
+ Coverage   58.83%   59.12%   +0.28%     
==========================================
  Files          30       30              
  Lines        3855     3914      +59     
  Branches      846      863      +17     
==========================================
+ Hits         2268     2314      +46     
- Misses       1254     1259       +5     
- Partials      333      341       +8     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

File::create(temp_dir.path().join(new_file_name)).expect("create temp file");
let new_file = get_dir_entry_for(&temp_dir_path, new_file_name);

// mores test
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// mores test
// more test

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. Changed in new commit.

@cakebaker cakebaker linked an issue Apr 20, 2024 that may be closed by this pull request
@sylvestre
Copy link
Contributor

please add integrations tests in https://github.com/uutils/findutils/blob/main/tests/find_cmd_tests.rs
and please tests with invalid values (like string for numerical values)

@hanbings
Copy link
Collaborator Author

hanbings commented Apr 20, 2024

please add integrations tests in https://github.com/uutils/findutils/blob/main/tests/find_cmd_tests.rs and please tests with invalid values (like string for numerical values)

I've added tests for string type numbers.
But I found that it is able to recognize error parameters such as 1%2 and +-321, which is different from the GNU find results.

This has to do with the way the convert_arg_to_comparable_value function recognizes and converts numbers, meaning that this problem occurs with both the a/c/mtime and a/c/mmin arguments.

Should I fix them in a new PR?

$ find . -atime 1%2
find: invalid argument `1%2' to `-atime'
$ find . -amin 1%2
find: invalid argument `1%2' to `-amin'
$ ./target/debug/find . -atime 1%2
$ ./target/debug/find . -amin 1%2
./.git
./.git/objects/b1
./.git/objects/7f
./.git/objects/a8
./target/debug/deps
./target/debug/incremental/find_cmd_tests-8yeq2sf4g2ts
...

"\"-60\"", "\"-120\"", "\"-240\"", "\"-60\"", "\"-120\"", "\"-240\"",
];

for (arg, time) in args.iter().zip(times.iter()) {
Copy link
Contributor

@cakebaker cakebaker May 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this piece of code doesn't do what you think it does ;-) It doesn't create the Cartesian product of args and times:

for (arg, time) in args.iter().zip(times.iter()) {
    println!("{arg}: {time}");
}

outputs:

-amin: -60
-cmin: -120
-mmin: -240

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree. I replaced it with a nested loop. : )

.code(0);
}

for (arg, time_string) in args.iter().zip(time_strings.iter()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See my previous comment.

Comment on lines 530 to 531
for arg in args.iter() {
for time in times.iter() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Calling iter() is not necessary here.

Suggested change
for arg in args.iter() {
for time in times.iter() {
for arg in args {
for time in times {

Comment on lines 541 to 542
for arg in args.iter() {
for time_string in time_strings.iter() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
for arg in args.iter() {
for time_string in time_strings.iter() {
for arg in args {
for time_string in time_strings {

for arg in args.iter() {
for time_string in time_strings.iter() {
Command::cargo_bin("find")
.expect("the except time should not match")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure about this one:

Suggested change
.expect("the except time should not match")
.expect("the time should not match")

src/find/mod.rs Outdated
let args = ["-amin", "-cmin", "-mmin"];
let times = ["-60", "-120", "-240", "+60", "+120", "+240"];

for (arg, time) in args.iter().zip(times.iter()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here you need a nested loop to get the expected result because zip doesn't generate the Cartesian product of args and times.

@hanbings
Copy link
Collaborator Author

Thanks, the conflict has been resolved and the code modified in new commits.

@sylvestre
Copy link
Contributor

it would be nice to work on #360 next
it will be easier to detect improvement / regression wrt the GNU test suite

@sylvestre sylvestre merged commit d7057e0 into uutils:main Jun 1, 2024
18 checks passed
@hanbings hanbings deleted the implement-221 branch June 1, 2024 09:41
@hanbings
Copy link
Collaborator Author

hanbings commented Jun 1, 2024

it would be nice to work on #360 next it will be easier to detect improvement / regression wrt the GNU test suite

Thanks! I will complete it as soon as I can.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature request: support -amin -cmin -mmin age ranges
3 participants