Skip to content

Commit aedec9a

Browse files
committed
more disciplined path handling
1 parent d200939 commit aedec9a

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

dropshot/src/logging.rs

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -440,17 +440,20 @@ mod test {
440440
#[test]
441441
fn test_config_bad_file_path_exists_fail() {
442442
let mut logtest = LogTest::setup("bad_file_path_exists_fail_dir");
443-
let path = logtest.will_create_file("log.out");
444-
fs::write(&path, "").expect("writing empty file");
443+
let logpath = logtest.will_create_file("log.out");
444+
fs::write(&logpath, "").expect("writing empty file");
445+
446+
// Windows paths need to have \ turned into \\
447+
let escaped_path = logpath.display().to_string().escape_default().to_string();
445448

446449
let bad_config = format!(
447450
r#"
448451
mode = "file"
449452
level = "warn"
450453
if_exists = "fail"
451-
path = {:?}
454+
path = "{}"
452455
"#,
453-
path
456+
escaped_path
454457
);
455458

456459
let error = read_config_and_create_logger(
@@ -474,15 +477,18 @@ mod test {
474477
let logpath = logtest.will_create_file("log.out");
475478
let time_before = chrono::offset::Utc::now();
476479

480+
// Windows paths need to have \ turned into \\
481+
let escaped_path = logpath.display().to_string().escape_default().to_string();
482+
477483
/* The first attempt should succeed. The log file doesn't exist yet. */
478484
let config = format!(
479485
r#"
480486
mode = "file"
481487
level = "warn"
482488
if_exists = "fail"
483-
path = {:?}
489+
path = "{}"
484490
"#,
485-
&logpath
491+
escaped_path
486492
);
487493

488494
{
@@ -502,9 +508,9 @@ mod test {
502508
mode = "file"
503509
level = "warn"
504510
if_exists = "append"
505-
path = {:?}
511+
path = "{}"
506512
"#,
507-
&logpath
513+
escaped_path
508514
);
509515

510516
{
@@ -544,9 +550,9 @@ mod test {
544550
mode = "file"
545551
level = "trace"
546552
if_exists = "truncate"
547-
path = {:?}
553+
path = "{}"
548554
"#,
549-
&logpath
555+
escaped_path
550556
);
551557

552558
{

0 commit comments

Comments
 (0)