fix: handling of empty str for license template path (#3804)

This commit is contained in:
Caleb Cartwright
2019-09-23 19:24:05 -05:00
committed by Seiichi Uchida
parent 6b0a447150
commit 3bb266180e
8 changed files with 46 additions and 4 deletions
+6 -4
View File
@@ -293,10 +293,12 @@ fn set_heuristics(&mut self) {
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(&lt_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(&lt_path) {
Ok(re) => self.license_template = Some(re),
Err(msg) => eprintln!("Warning for license template file {:?}: {}",
lt_path, msg),
}
}
}
}
+14
View File
@@ -467,6 +467,20 @@ fn test_print_docs_include_unstable() {
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
View File
@@ -0,0 +1,2 @@
unstable_features = true
license_template_path = ""
+2
View File
@@ -0,0 +1,2 @@
// rustfmt-license_template_path: tests/license-template/lt.txt
// Copyright {\d+} The rustfmt developers.
@@ -0,0 +1,5 @@
// rustfmt-config: issue-3802.toml
fn main() {
println!("Hello world!");
}
@@ -0,0 +1,6 @@
// rustfmt-license_template_path: tests/license-template/lt.txt
// Copyright 2019 The rustfmt developers.
fn main() {
println!("Hello world!");
}
@@ -0,0 +1,5 @@
// rustfmt-config: issue-3802.toml
fn main() {
println!("Hello world!");
}
@@ -0,0 +1,6 @@
// rustfmt-license_template_path: tests/license-template/lt.txt
// Copyright 2019 The rustfmt developers.
fn main() {
println!("Hello world!");
}