-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
cksum: stops when one of given files doesn't exist #5809 #5820
Conversation
I don't know if you have seen that one tests fails:
|
Thank you for pointing out |
@biplab5464 please replace the screenshot by text. Screenshots are terrible for accessibility and search |
**TEST CASE ** Compiling uu_cksum v0.0.23 (/home/biplab/project/coreutils/src/uu/cksum) running 1 test stack backtrace: failures: failures: test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 2637 filtered out; finished in 0.05s error: test failed, to rerun pass
OUTPUT Thanks for letting me know @sylvestre |
Well, the test expects that
Hope that helps :) |
i have check with cksum the output is same only but i am using eprintln. this shoud print to the std error std right
can you guide me |
Yes, that's correct. You can save the "cksum: " part by using our |
Thanks for the help :) |
GNU testsuite comparison:
|
i understand why code quality fails but i don't understand why the other 2 fails |
src/uu/cksum/src/cksum.rs
Outdated
file_buf = match File::open(filename) { | ||
Ok(file) => file, | ||
Err(_) => { | ||
eprintln!("cksum: {}: No such file or directory", filename.display()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you got the control flow right, but the error message would now be wrong if there is another reason that the file can't be opened, for example if the permissions are incorrect.
A more correct approach would look like this:
file_buf = match File::open(filename) {
Ok(file) => file,
Err(e) => {
show!(e.map_err_context(|| filename.to_string_lossy().to_string());
continue;
}
};
This will automatically add "cksum" and print the error message corresponding to the io error that occurred.
See also the docs for
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the kind gesture
GNU testsuite comparison:
|
I think watching this solution for a similar case would help you: https://github.com/uutils/coreutils/pull/5806/files |
can give little bit more hint |
run: /Users/runner/work/coreutils/coreutils/target/x86_64-apple-darwin/debug/coreutils stat - can anyone confirm this test is failing because of my code and if it is , why |
This error is unrelated to your PR. |
Thank you for information |
The code looks good :) Can you please add a test (or adapt |
I was busy so missed your comment |
You can run the Hope that helps :) |
i am sorry i tried but i couldn't do it |
What do you struggle with? Today I merged a PR similar to this one that shows an error if the user specifies a directory. Its test might give you an idea for your test: https://github.com/uutils/coreutils/blob/main/tests/by-util/test_cksum.rs#L346 The part relevant for you starts on line 346. I think this should allow you to adapt |
ok i will try again i may need some time because i am busy with another task |
is this test case is okay
|
Something like that. I would do it like the others, by creating a new file in tests/fixtures/cksum. fn test_nonexisting_file_continue() {
let file_name = "asdf";
new_ucmd!()
.arg(file_name)
.arg("lorem_ipsum.txt")
.arg("alice_in_wonderland.txt")
.fails()
.stdout_is_fixture("nonexisting_file_continue.expected")
.stderr_contains(format!("cksum: {file_name}: No such file or directory"));
} |
oh,can you explain me a little, i mean do i need to change anything i think my test case is when one file is missing when giving multiple files |
… given files doesn't exist #5809
Two small things:
Thanks! |
okay i will do it |
…ops when one of given files doesn't exist #5809
GNU testsuite comparison:
|
Thanks for your PR :) |
Thank you for your cooperation, I learnt a lot |
continue if the file not found