File tree 8 files changed +46
-4
lines changed
8 files changed +46
-4
lines changed Original file line number Diff line number Diff line change @@ -293,10 +293,12 @@ macro_rules! create_config {
293
293
fn set_license_template( & mut self ) {
294
294
if self . was_set( ) . license_template_path( ) {
295
295
let lt_path = self . license_template_path( ) ;
296
- match license:: load_and_compile_template( & lt_path) {
297
- Ok ( re) => self . license_template = Some ( re) ,
298
- Err ( msg) => eprintln!( "Warning for license template file {:?}: {}" ,
299
- lt_path, msg) ,
296
+ if lt_path. len( ) > 0 {
297
+ match license:: load_and_compile_template( & lt_path) {
298
+ Ok ( re) => self . license_template = Some ( re) ,
299
+ Err ( msg) => eprintln!( "Warning for license template file {:?}: {}" ,
300
+ lt_path, msg) ,
301
+ }
300
302
}
301
303
}
302
304
}
Original file line number Diff line number Diff line change @@ -467,6 +467,20 @@ mod test {
467
467
assert_eq ! ( s. contains( "(unstable)" ) , true ) ;
468
468
}
469
469
470
+ #[ test]
471
+ fn test_empty_string_license_template_path ( ) {
472
+ let toml = r#"license_template_path = """# ;
473
+ let config = Config :: from_toml ( toml, Path :: new ( "" ) ) . unwrap ( ) ;
474
+ assert ! ( config. license_template. is_none( ) ) ;
475
+ }
476
+
477
+ #[ test]
478
+ fn test_valid_license_template_path ( ) {
479
+ let toml = r#"license_template_path = "tests/license-template/lt.txt""# ;
480
+ let config = Config :: from_toml ( toml, Path :: new ( "" ) ) . unwrap ( ) ;
481
+ assert ! ( config. license_template. is_some( ) ) ;
482
+ }
483
+
470
484
#[ test]
471
485
fn test_dump_default_config ( ) {
472
486
let default_config = format ! (
Original file line number Diff line number Diff line change
1
+ unstable_features = true
2
+ license_template_path = " "
Original file line number Diff line number Diff line change
1
+ // rustfmt-license_template_path: tests/license-template/lt.txt
2
+ // Copyright {\d+} The rustfmt developers.
Original file line number Diff line number Diff line change
1
+ // rustfmt-config: issue-3802.toml
2
+
3
+ fn main ( ) {
4
+ println ! ( "Hello world!" ) ;
5
+ }
Original file line number Diff line number Diff line change
1
+ // rustfmt-license_template_path: tests/license-template/lt.txt
2
+ // Copyright 2019 The rustfmt developers.
3
+
4
+ fn main ( ) {
5
+ println ! ( "Hello world!" ) ;
6
+ }
Original file line number Diff line number Diff line change
1
+ // rustfmt-config: issue-3802.toml
2
+
3
+ fn main ( ) {
4
+ println ! ( "Hello world!" ) ;
5
+ }
Original file line number Diff line number Diff line change
1
+ // rustfmt-license_template_path: tests/license-template/lt.txt
2
+ // Copyright 2019 The rustfmt developers.
3
+
4
+ fn main ( ) {
5
+ println ! ( "Hello world!" ) ;
6
+ }
You can’t perform that action at this time.
0 commit comments