Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions src/config/config_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(&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 {

Choose a reason for hiding this comment

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

Prefer !lt_path.is_empty()?

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),
}
}
}
}
Expand Down
14 changes: 14 additions & 0 deletions src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!(
Expand Down
2 changes: 2 additions & 0 deletions tests/config/issue-3802.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
unstable_features = true
license_template_path = ""
2 changes: 2 additions & 0 deletions tests/license-template/lt.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// rustfmt-license_template_path: tests/license-template/lt.txt
// Copyright {\d+} The rustfmt developers.
5 changes: 5 additions & 0 deletions tests/source/license-templates/empty_license_path.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// rustfmt-config: issue-3802.toml

fn main() {
println!("Hello world!");
}
6 changes: 6 additions & 0 deletions tests/source/license-templates/license.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// rustfmt-license_template_path: tests/license-template/lt.txt
// Copyright 2019 The rustfmt developers.

fn main() {
println!("Hello world!");
}
5 changes: 5 additions & 0 deletions tests/target/license-templates/empty_license_path.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// rustfmt-config: issue-3802.toml

fn main() {
println!("Hello world!");
}
6 changes: 6 additions & 0 deletions tests/target/license-templates/license.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// rustfmt-license_template_path: tests/license-template/lt.txt
// Copyright 2019 The rustfmt developers.

fn main() {
println!("Hello world!");
}