-
Notifications
You must be signed in to change notification settings - Fork 297
Fix 050568f1: run unit tests in generated git repo #1034
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
Conversation
test_info_style_info() and test_info_style_subtitle() fail with "Error: Could not find a git repository in '.' or in any of its parents" if the current working directory is not a git repository. * Provide the git repository setup function as a opt-in library utility. Deduplicate the repo setup for benchmarking, integration tests and unit tests.
via `cargo fmt`
IMO, the issue lies with the What do you think @antecrescent ? smth like: fn style_info(info: &str, with_color: bool, text_colors: &TextColors) -> String {
if with_color {
let info_style = get_style(false, text_colors.info);
format!("{}", info.style(info_style))
} else {
info.into()
}
}
fn style_subtitle(subtitle: &str, no_bold: bool, text_colors: &TextColors) -> String {
let subtitle_style = get_style(!no_bold, text_colors.subtitle);
let colon_style = get_style(!no_bold, text_colors.colon);
format!(
"{}{}",
subtitle.style(subtitle_style),
":".style(colon_style)
)
} |
Agree with @o2sh that we're jumping through too many hoops to even set up our tests to be run. We could also possibly refactor Seems like it's very idiomatic in Rust to have a // Example:
let info = Info::builder() // returns InfoBuilder::default()
.no_color_palette()
.title(Title::builder().build()) // Maybe a title builder since it's a complex struct?
.build();
// No color palette, no info fields, so now this test can focus solely on the title
assert_eq!(info.to_string(), "Name ...");
|
I think I've been staring at it for so long that it doesn't even shock me anymore 😄 , but yeah, I agree this constructor needs some serious refactoring.
Very cool idea 👍 With this in place, we should be able to add some unit tests on the @antecrescent It's your call if you want to take care of this refactor suggested by @spenserblack . IMO, this may be out of scope considering your initial issue. Just updating |
Thank you for the thorough reviews. Unfortunately, I am very new to Rust and quite unfamiliar with the code base. I will try to update |
Closed as part of #1047 |
test_info_style_info() and test_info_style_subtitle() fail with
Error: Could not find a git repository in '.' or in any of its parents
if the current working directory is not a git repository. This breaks workflows of e.g. Linux distributions which download tarballs from Github.Currently, the
fn repo(name: &str) -> Result<Repository>
git repository setup function is duplicated across benchmarking, integration and unit tests. This pull requests unifies it under an opt-in library function via thetest-utils
feature and fixes the aforementioned tests.I chose to handle this with a feature, because when compiling integration tests,
#[cfg(test)]
is not active and the normally compiled lib gets linked against them.Using a workaround, the
test-utils
feature and all tests depending on it, are enabled by default for testing and benchmarking.As of now, it is not possible to add dependencies based on optional features, which is why I had to move
gix-testtools
to [dependencies].