mirror of
https://github.com/rust-lang/rust.git
synced 2026-05-02 00:07:42 +03:00
fix: handling of empty str for license template path (#3804)
This commit is contained in:
committed by
Seiichi Uchida
parent
6b0a447150
commit
3bb266180e
@@ -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(<_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 @@ 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!(
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
unstable_features = true
|
||||
license_template_path = ""
|
||||
@@ -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!");
|
||||
}
|
||||
Reference in New Issue
Block a user