diff --git a/src/config/config_type.rs b/src/config/config_type.rs index 7f7e8905fba92..2eff7561392c3 100644 --- a/src/config/config_type.rs +++ b/src/config/config_type.rs @@ -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), + } } } } diff --git a/src/config/mod.rs b/src/config/mod.rs index a4930b7c57515..1d0217f27b10d 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -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!( diff --git a/tests/config/issue-3802.toml b/tests/config/issue-3802.toml new file mode 100644 index 0000000000000..74ee8b010dd05 --- /dev/null +++ b/tests/config/issue-3802.toml @@ -0,0 +1,2 @@ +unstable_features = true +license_template_path = "" diff --git a/tests/license-template/lt.txt b/tests/license-template/lt.txt new file mode 100644 index 0000000000000..ea4390371a09a --- /dev/null +++ b/tests/license-template/lt.txt @@ -0,0 +1,2 @@ +// rustfmt-license_template_path: tests/license-template/lt.txt +// Copyright {\d+} The rustfmt developers. diff --git a/tests/source/license-templates/empty_license_path.rs b/tests/source/license-templates/empty_license_path.rs new file mode 100644 index 0000000000000..d3a91e4231d19 --- /dev/null +++ b/tests/source/license-templates/empty_license_path.rs @@ -0,0 +1,5 @@ +// rustfmt-config: issue-3802.toml + +fn main() { +println!("Hello world!"); +} diff --git a/tests/source/license-templates/license.rs b/tests/source/license-templates/license.rs new file mode 100644 index 0000000000000..6816011c60dc5 --- /dev/null +++ b/tests/source/license-templates/license.rs @@ -0,0 +1,6 @@ +// rustfmt-license_template_path: tests/license-template/lt.txt +// Copyright 2019 The rustfmt developers. + +fn main() { +println!("Hello world!"); +} diff --git a/tests/target/license-templates/empty_license_path.rs b/tests/target/license-templates/empty_license_path.rs new file mode 100644 index 0000000000000..950f103ed3922 --- /dev/null +++ b/tests/target/license-templates/empty_license_path.rs @@ -0,0 +1,5 @@ +// rustfmt-config: issue-3802.toml + +fn main() { + println!("Hello world!"); +} diff --git a/tests/target/license-templates/license.rs b/tests/target/license-templates/license.rs new file mode 100644 index 0000000000000..7169c7b257615 --- /dev/null +++ b/tests/target/license-templates/license.rs @@ -0,0 +1,6 @@ +// rustfmt-license_template_path: tests/license-template/lt.txt +// Copyright 2019 The rustfmt developers. + +fn main() { + println!("Hello world!"); +}