fix: handling of empty str for license template path (#3804)
This commit is contained in:
parent
6b0a447150
commit
3bb266180e
8 changed files with 46 additions and 4 deletions
|
|
@ -293,10 +293,12 @@ macro_rules! create_config {
|
|||
fn set_license_template(&mut self) {
|
||||
if self.was_set().license_template_path() {
|
||||
let lt_path = self.license_template_path();
|
||||
match license::load_and_compile_template(<_path) {
|
||||
Ok(re) => self.license_template = Some(re),
|
||||
Err(msg) => eprintln!("Warning for license template file {:?}: {}",
|
||||
lt_path, msg),
|
||||
if lt_path.len() > 0 {
|
||||
match license::load_and_compile_template(<_path) {
|
||||
Ok(re) => self.license_template = Some(re),
|
||||
Err(msg) => eprintln!("Warning for license template file {:?}: {}",
|
||||
lt_path, msg),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -467,6 +467,20 @@ mod test {
|
|||
assert_eq!(s.contains("(unstable)"), true);
|
||||
}
|
||||
|
||||
#[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() {
|
||||
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());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_dump_default_config() {
|
||||
let default_config = format!(
|
||||
|
|
|
|||
2
tests/config/issue-3802.toml
Normal file
2
tests/config/issue-3802.toml
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
unstable_features = true
|
||||
license_template_path = ""
|
||||
2
tests/license-template/lt.txt
Normal file
2
tests/license-template/lt.txt
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
// rustfmt-license_template_path: tests/license-template/lt.txt
|
||||
// Copyright {\d+} The rustfmt developers.
|
||||
5
tests/source/license-templates/empty_license_path.rs
Normal file
5
tests/source/license-templates/empty_license_path.rs
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
// rustfmt-config: issue-3802.toml
|
||||
|
||||
fn main() {
|
||||
println!("Hello world!");
|
||||
}
|
||||
6
tests/source/license-templates/license.rs
Normal file
6
tests/source/license-templates/license.rs
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
// rustfmt-license_template_path: tests/license-template/lt.txt
|
||||
// Copyright 2019 The rustfmt developers.
|
||||
|
||||
fn main() {
|
||||
println!("Hello world!");
|
||||
}
|
||||
5
tests/target/license-templates/empty_license_path.rs
Normal file
5
tests/target/license-templates/empty_license_path.rs
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
// rustfmt-config: issue-3802.toml
|
||||
|
||||
fn main() {
|
||||
println!("Hello world!");
|
||||
}
|
||||
6
tests/target/license-templates/license.rs
Normal file
6
tests/target/license-templates/license.rs
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
// rustfmt-license_template_path: tests/license-template/lt.txt
|
||||
// Copyright 2019 The rustfmt developers.
|
||||
|
||||
fn main() {
|
||||
println!("Hello world!");
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue