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

Fix overriding license header bug #4488

Conversation

cmichi
Copy link
Contributor

@cmichi cmichi commented Oct 22, 2020

Closes #4487.

@calebcartwright
Copy link
Member

LGTM! Would you mind adding a test case to prevent any future regressions?

This would probably be a good place to put it:

rustfmt/src/config.rs

Lines 547 to 562 in cbe01e4

#[test]
fn test_empty_string_license_template_path() {
let toml = r#"license_template_path = """#;
let config = Config::from_toml(toml, Path::new("")).unwrap();
assert!(config.license_template.is_none());
}
#[test]
fn test_valid_license_template_path() {
if !option_env!("CFG_RELEASE_CHANNEL").map_or(true, |c| c == "nightly" || c == "dev") {
return;
}
let toml = r#"license_template_path = "tests/license-template/lt.txt""#;
let config = Config::from_toml(toml, Path::new("")).unwrap();
assert!(config.license_template.is_some());
}

Using a toml config that sets some value (doesn't really matter what) and then overriding the value with an empty string (this is what the cli override uses) and asserting it's none should suffice. Here's two example tests that respectively each do one of those for reference

rustfmt/src/config.rs

Lines 976 to 990 in cbe01e4

fn test_single_line_if_else_max_width_config_exceeds_max_width() {
let toml = r#"
max_width = 70
single_line_if_else_max_width = 90
"#;
let config = Config::from_toml(toml, Path::new("")).unwrap();
assert_eq!(config.single_line_if_else_max_width(), 70);
}
#[test]
fn test_override_fn_call_width_exceeds_max_width() {
let mut config = Config::default();
config.override_value("fn_call_width", "101");
assert_eq!(config.fn_call_width(), 100);
}

@calebcartwright
Copy link
Member

Sorry I forgot to mention, add this to the test

if !is_nightly_channel!() {
    // This test requires nightly
    return;
}

@cmichi
Copy link
Contributor Author

cmichi commented Oct 24, 2020

@calebcartwright Thanks, I think the failing tests are due to network latency, could you restart them please?

And if you would be so kind, do you have any idea when this will land in a published release?

Copy link
Member

@calebcartwright calebcartwright left a comment

Choose a reason for hiding this comment

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

Thanks!

@calebcartwright
Copy link
Member

And if you would be so kind, do you have any idea when this will land in a published release?

Planning to backport this into the upcoming 1.4.23 release, but no date yet on when that'll hit nightly

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

Successfully merging this pull request may close these issues.

2 participants