-
Notifications
You must be signed in to change notification settings - Fork 9
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
Display modification times of input files in context and unified diff #33
Display modification times of input files in context and unified diff #33
Conversation
Could you please add tests |
Thanks |
Okay! The current tests are failing.
Isn't this strange? We check if file exists in Edit: These are unit tests. My bad! |
Can you guide me more on these 😅? |
This one is pretty simple, no ? :) |
@sylvestre I was looking at the unit tests and I see we are not actually creating files but only passing filename literals to |
yes please :) |
392f726
to
9d4346e
Compare
9d4346e
to
9ff8f89
Compare
I'm not sure on how the tests are failing on CI, we are creating the files now. It should have worked. Strange 🤔 The tests are working fine on my machine: test context_diff::tests::test_permutations_missing_lines ... ok
test context_diff::tests::test_permutations_empty_lines ... ok
test context_diff::tests::test_permutations_reverse ... ok
test context_diff::tests::test_permutations ... ok
test normal_diff::tests::test_stop_early ... ok |
sorry, could you please fix the conflict? Sorry :( |
38bd174
to
88a7568
Compare
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #33 +/- ##
==========================================
- Coverage 76.29% 75.85% -0.45%
==========================================
Files 9 9
Lines 2582 2597 +15
Branches 663 662 -1
==========================================
Hits 1970 1970
- Misses 459 476 +17
+ Partials 153 151 -2
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
I realized that the tests were passing locally because files were generated during previous test runs. |
Yeah, just https://crates.io/crates/tempfile to create these files |
a760034
to
a3a372f
Compare
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.
Thanks for the update, this is looking promising!
See inline for a few suggestions.
Also, note that the read_from_stdin()
integration test is failing. The expectation on the output will need to be updated to ignore the timestamps.
…il105/diffutils into context-diff-modification-time
81c1346
to
0a77fe1
Compare
Hey @oSoMoN , I have made the necessary changes! Can you review the MR? |
src/utils.rs
Outdated
let target = "target/utils"; | ||
let _ = std::fs::create_dir(target); | ||
let filename = &format!("{target}/foo"); | ||
let temp = File::create(filename).unwrap(); |
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.
Can you use a tempfile.NamedTempFile instead?
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 don't think there are APIs to set modification time for a NamedTempFile
.
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.
NamedTempFile::as_file()
exposes a reference to the underlying file, so you could do something like this:
use tempfile::NamedTempFile;
let temp = NamedTempFile::new().unwrap();
let current = SystemTime::now();
let _ = temp.as_file().set_modified(current);
…
assert_eq!(current, get_modification_time(&temp.path().to_string_lossy()));
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.
Thanks Tanmay, that looks quite good!
I have left a handful of comments/suggestions, see inline.
Halfway through the changes. I'll complete them shortly! |
d9d7b56
to
aab1a13
Compare
Since we now returning SystemTime::now() for invalid file input, there is no need to crate dummy files
aab1a13
to
ba7cb0a
Compare
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.
Thanks, that looks really good now. Almost ready to merge, see only my suggestion on the use of NamedTempFile
.
src/utils.rs
Outdated
let target = "target/utils"; | ||
let _ = std::fs::create_dir(target); | ||
let filename = &format!("{target}/foo"); | ||
let temp = File::create(filename).unwrap(); |
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.
NamedTempFile::as_file()
exposes a reference to the underlying file, so you could do something like this:
use tempfile::NamedTempFile;
let temp = NamedTempFile::new().unwrap();
let current = SystemTime::now();
let _ = temp.as_file().set_modified(current);
…
assert_eq!(current, get_modification_time(&temp.path().to_string_lossy()));
It's worth noting that with the changes in this PR, one test from the GNU test suite which currently fails in main now passes (the timezone test). Nice improvement! |
Done! |
Sorry for the noise! I forgot to run |
Merged, thanks Tanmay for the contribution! |
Fixes #31