-
Notifications
You must be signed in to change notification settings - Fork 901
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
Add repo cloning to check-diff crate #6187
Conversation
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.
Great first pass, though I think we can make some changes to take better advantage of the type system, and keep functions more focused on a single task. There are also a few other suggestions that I've made. Take a look and let me know if you've got any questions on the feedback.
e428b98
to
7ff0250
Compare
@ytmimi Sorry for the big PR. Things updated based on the previous review:
Some questions though:
Let me know what do you think of the updated implementation! ps the PR is huge because I added |
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.
Great to see that you've added some test cases to cover the functionality that you're adding. I left a few more comments about returning Results
from functions instead of panicing and also I think the tempfile
crate would be a nice addition to the test suite so that we don't need to roll our own temporary file and directory cleanup.
Changes made from last review:
Questions:
|
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 left some additional comments on the cd_test
and clone_repo_test
functions. When testing I think it's totally fine to call unwrap
, and I think doing so would simplify the test cases. I also left some suggestions for more direct assertions. Overall I think the addition of the tempfile
crate helped improve the tests.
check_diff/tests/bash_commands.rs
Outdated
#[test] | ||
fn cd_test() { | ||
// create directory in current directory | ||
let dir = Builder::new().tempdir_in(""); |
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 we need to use the builder here. Probably simpler to use the tempdir function and just unwrap
since we're in a test case. If we fail to create the temporary directory then there's not much more we can do.
check_diff/tests/bash_commands.rs
Outdated
match d.close() { | ||
Ok(_) => {} | ||
Err(e) => { | ||
error!("Error from closing: {}", e); | ||
assert_eq!(1, 2); | ||
} | ||
} |
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 explain why we need to call close
here.
check_diff/tests/bash_commands.rs
Outdated
match dir { | ||
Ok(d) => { | ||
let dest_path = d.path(); | ||
let _ = change_directory_to_path(dest_path); |
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.
Probably simpler to just unwrap
in the test instead of silently ignoring the returned Result
.
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.
the Result
here is actually ignored because we are actually changing the env
variable.
check_diff/tests/bash_commands.rs
Outdated
Ok(d) => { | ||
let dest_path = d.path(); | ||
let _ = change_directory_to_path(dest_path); | ||
assert_eq!(env::current_dir().is_ok(), true); |
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 feel like it would be a more direct test if you asserted that the current working directory is the same as the dest_path
check_diff/tests/bash_commands.rs
Outdated
assert_ne!( | ||
env::current_dir().unwrap().file_name(), | ||
Some(OsStr::new("check_diff")) | ||
); |
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.
This is the code you were referring to in #6187 (comment), right? My feeling is that this isn't a necessary check and if we assert that we've correctly changed the working directory to the tempdir then I don't think this is necessary.
check_diff/tests/git.rs
Outdated
|
||
#[test] | ||
fn clone_repo_test() { | ||
let dir = Builder::new().tempdir_in(""); |
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.
Similar comment as before. It's probably simpler to use the tempdir function and just unwrap
if we fail to create a tempdir.
check_diff/tests/git.rs
Outdated
// check whether we can read this directory | ||
assert_eq!(directory.is_err(), false); | ||
// check that the directory is non-empty | ||
assert_eq!(directory.iter().next().is_none(), false); |
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.
Since we've cloned a git repo into this repository we might want to double check that a .git
directory exists with the tempdir
. That might be a more direct assertion. Checking that we're able to reach the directly could be useful, but my assumption would be that if we're able to write to the tempdir then we'd be able to read from it as well.
check_diff/tests/git.rs
Outdated
match d.close() { | ||
Ok(_) => {} | ||
Err(e) => { | ||
error!("Error from closing: {}", e); | ||
assert_eq!(1, 2); | ||
} | ||
} | ||
} |
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.
Similar question as before. I'm not sure if we need to manually close the directory since it should be closed and cleaned up at the end of the test already.
Updated most of the changes that were requested as I agreed with them. The use of |
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 continuing to work on this. Take a look at my suggestions for simplifying the assertions.
From what I can tell I don't think we're actually running the |
I will update the respective files - doing something similar to |
@benluiwj thanks for the updates. It's good to see CI passing. This PR has gone through several rounds of review and there are a lot of intermedia commits that could be squashed down. I think it might make sense to squash the implementation and unit test commits into a single commit and then have another commit that updates CI. let me know if that's something you'd want to do, otherwise I can make that change. |
ff4c37c
to
66ea607
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.
Things are looking good here!
66ea607
to
fe1eb36
Compare
Included unit tests for the new functionality as well.
fe1eb36
to
6e7f0fb
Compare
TLDR: Added repo cloning to check-diff. Included sample execution as screenshot.
This PR adds git functionalities to the
check-diff
crate. The current script has ainit_submodules
function. However, it seems that the repos used does not require initialising of submodules. Hence, this function was not converted to Rust.Sample execution attached. Parameters to the program is currently not in used.
The screenshot shows the following things:
rustfmt
into atmp
directory createdtmp
contains the entirerustfmt
repo