From 53b8bf74381dc292834a356e4a760755d64fc60e Mon Sep 17 00:00:00 2001 From: rdkt13 Date: Sun, 6 Sep 2020 11:23:18 +0200 Subject: Fix paths in tests expectations for all platforms --- tests/errors.rs | 11 +++++++---- tests/file_hjson.rs | 5 ++++- tests/file_ini.rs | 5 ++++- tests/file_json.rs | 5 ++++- tests/file_toml.rs | 5 ++++- tests/file_yaml.rs | 8 +++++--- 6 files changed, 28 insertions(+), 11 deletions(-) diff --git a/tests/errors.rs b/tests/errors.rs index 5f4a1a5..159473e 100644 --- a/tests/errors.rs +++ b/tests/errors.rs @@ -6,6 +6,7 @@ extern crate config; extern crate serde_derive; use config::*; +use std::path::PathBuf; fn make() -> Config { let mut c = Config::default(); @@ -20,10 +21,12 @@ fn test_error_parse() { let mut c = Config::default(); let res = c.merge(File::new("tests/Settings-invalid", FileFormat::Toml)); + let path : PathBuf = ["tests", "Settings-invalid.toml"].iter().collect(); + assert!(res.is_err()); assert_eq!( res.unwrap_err().to_string(), - "failed to parse datetime for key `error` at line 2 column 9 in tests/Settings-invalid.toml".to_string() + format!("failed to parse datetime for key `error` at line 2 column 9 in {}", path.to_str().unwrap()) ); } @@ -33,12 +36,12 @@ fn test_error_type() { let res = c.get::("boolean_s_parse"); + let path : PathBuf = ["tests", "Settings.toml"].iter().collect(); + assert!(res.is_err()); assert_eq!( res.unwrap_err().to_string(), - "invalid type: string \"fals\", expected a boolean for key \ - `boolean_s_parse` in tests/Settings.toml" - .to_string() + format!("invalid type: string \"fals\", expected a boolean for key `boolean_s_parse` in {}", path.to_str().unwrap()) ); } diff --git a/tests/file_hjson.rs b/tests/file_hjson.rs index 086489b..1e99b87 100644 --- a/tests/file_hjson.rs +++ b/tests/file_hjson.rs @@ -10,6 +10,7 @@ extern crate serde_derive; use config::*; use float_cmp::ApproxEqUlps; use std::collections::HashMap; +use std::path::PathBuf; #[derive(Debug, Deserialize)] struct Place { @@ -69,9 +70,11 @@ fn test_error_parse() { let mut c = Config::default(); let res = c.merge(File::new("tests/Settings-invalid", FileFormat::Hjson)); + let path : PathBuf = ["tests", "Settings-invalid.hjson"].iter().collect(); + assert!(res.is_err()); assert_eq!( res.unwrap_err().to_string(), - "Found a punctuator where a key name was expected (check your syntax or use quotes if the key name includes {}[],: or whitespace) at line 4 column 1 in tests/Settings-invalid.hjson".to_string() + format!("Found a punctuator where a key name was expected (check your syntax or use quotes if the key name includes {{}}[],: or whitespace) at line 4 column 1 in {}", path.to_str().unwrap()) ); } diff --git a/tests/file_ini.rs b/tests/file_ini.rs index 833cab0..057e496 100644 --- a/tests/file_ini.rs +++ b/tests/file_ini.rs @@ -8,6 +8,7 @@ extern crate serde; extern crate serde_derive; use config::*; +use std::path::PathBuf; #[derive(Debug, Deserialize, PartialEq)] struct Place { @@ -57,9 +58,11 @@ fn test_error_parse() { let mut c = Config::default(); let res = c.merge(File::new("tests/Settings-invalid", FileFormat::Ini)); + let path : PathBuf = ["tests", "Settings-invalid.ini"].iter().collect(); + assert!(res.is_err()); assert_eq!( res.unwrap_err().to_string(), - r#"2:0 Expecting "[Some('='), Some(':')]" but found EOF. in tests/Settings-invalid.ini"# + format!(r#"2:0 Expecting "[Some('='), Some(':')]" but found EOF. in {}"#, path.to_str().unwrap()) ); } diff --git a/tests/file_json.rs b/tests/file_json.rs index 4b586b2..1262585 100644 --- a/tests/file_json.rs +++ b/tests/file_json.rs @@ -10,6 +10,7 @@ extern crate serde_derive; use config::*; use float_cmp::ApproxEqUlps; use std::collections::HashMap; +use std::path::PathBuf; #[derive(Debug, Deserialize)] struct Place { @@ -69,9 +70,11 @@ fn test_error_parse() { let mut c = Config::default(); let res = c.merge(File::new("tests/Settings-invalid", FileFormat::Json)); + let path_with_extension : PathBuf = ["tests", "Settings-invalid.json"].iter().collect(); + assert!(res.is_err()); assert_eq!( res.unwrap_err().to_string(), - "expected `:` at line 4 column 1 in tests/Settings-invalid.json".to_string() + format!("expected `:` at line 4 column 1 in {}", path_with_extension.to_str().unwrap()) ); } diff --git a/tests/file_toml.rs b/tests/file_toml.rs index d1ae5db..a2a1caf 100644 --- a/tests/file_toml.rs +++ b/tests/file_toml.rs @@ -10,6 +10,7 @@ extern crate serde_derive; use config::*; use float_cmp::ApproxEqUlps; use std::collections::HashMap; +use std::path::PathBuf; #[derive(Debug, Deserialize)] struct Place { @@ -79,9 +80,11 @@ fn test_error_parse() { let mut c = Config::default(); let res = c.merge(File::new("tests/Settings-invalid", FileFormat::Toml)); + let path_with_extension : PathBuf = ["tests", "Settings-invalid.toml"].iter().collect(); + assert!(res.is_err()); assert_eq!( res.unwrap_err().to_string(), - "failed to parse datetime for key `error` at line 2 column 9 in tests/Settings-invalid.toml".to_string() + format!("failed to parse datetime for key `error` at line 2 column 9 in {}", path_with_extension.to_str().unwrap()) ); } diff --git a/tests/file_yaml.rs b/tests/file_yaml.rs index 85788c4..efc2908 100644 --- a/tests/file_yaml.rs +++ b/tests/file_yaml.rs @@ -10,6 +10,7 @@ extern crate serde_derive; use config::*; use float_cmp::ApproxEqUlps; use std::collections::HashMap; +use std::path::PathBuf; #[derive(Debug, Deserialize)] struct Place { @@ -69,11 +70,12 @@ fn test_error_parse() { let mut c = Config::default(); let res = c.merge(File::new("tests/Settings-invalid", FileFormat::Yaml)); + let path_with_extension : PathBuf = ["tests", "Settings-invalid.yaml"].iter().collect(); + assert!(res.is_err()); assert_eq!( res.unwrap_err().to_string(), - "while parsing a block mapping, did not find expected key at \ - line 2 column 1 in tests/Settings-invalid.yaml" - .to_string() + format!("while parsing a block mapping, did not find expected key at \ + line 2 column 1 in {}", path_with_extension.to_str().unwrap()) ); } -- cgit v1.2.3 From 79f5254c3926431063d0b2d6ffbd8154984a22ef Mon Sep 17 00:00:00 2001 From: rdkt13 Date: Mon, 7 Sep 2020 23:37:59 +0200 Subject: Use `display` method on PathBuf in tests --- tests/errors.rs | 4 ++-- tests/file_hjson.rs | 2 +- tests/file_ini.rs | 2 +- tests/file_json.rs | 2 +- tests/file_toml.rs | 2 +- tests/file_yaml.rs | 2 +- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/tests/errors.rs b/tests/errors.rs index 159473e..3a626c7 100644 --- a/tests/errors.rs +++ b/tests/errors.rs @@ -26,7 +26,7 @@ fn test_error_parse() { assert!(res.is_err()); assert_eq!( res.unwrap_err().to_string(), - format!("failed to parse datetime for key `error` at line 2 column 9 in {}", path.to_str().unwrap()) + format!("failed to parse datetime for key `error` at line 2 column 9 in {}", path.display()) ); } @@ -41,7 +41,7 @@ fn test_error_type() { assert!(res.is_err()); assert_eq!( res.unwrap_err().to_string(), - format!("invalid type: string \"fals\", expected a boolean for key `boolean_s_parse` in {}", path.to_str().unwrap()) + format!("invalid type: string \"fals\", expected a boolean for key `boolean_s_parse` in {}", path.display()) ); } diff --git a/tests/file_hjson.rs b/tests/file_hjson.rs index 1e99b87..70d7ca0 100644 --- a/tests/file_hjson.rs +++ b/tests/file_hjson.rs @@ -75,6 +75,6 @@ fn test_error_parse() { assert!(res.is_err()); assert_eq!( res.unwrap_err().to_string(), - format!("Found a punctuator where a key name was expected (check your syntax or use quotes if the key name includes {{}}[],: or whitespace) at line 4 column 1 in {}", path.to_str().unwrap()) + format!("Found a punctuator where a key name was expected (check your syntax or use quotes if the key name includes {{}}[],: or whitespace) at line 4 column 1 in {}", path.display()) ); } diff --git a/tests/file_ini.rs b/tests/file_ini.rs index 057e496..0b7b6a0 100644 --- a/tests/file_ini.rs +++ b/tests/file_ini.rs @@ -63,6 +63,6 @@ fn test_error_parse() { assert!(res.is_err()); assert_eq!( res.unwrap_err().to_string(), - format!(r#"2:0 Expecting "[Some('='), Some(':')]" but found EOF. in {}"#, path.to_str().unwrap()) + format!(r#"2:0 Expecting "[Some('='), Some(':')]" but found EOF. in {}"#, path.display()) ); } diff --git a/tests/file_json.rs b/tests/file_json.rs index 1262585..09c42bb 100644 --- a/tests/file_json.rs +++ b/tests/file_json.rs @@ -75,6 +75,6 @@ fn test_error_parse() { assert!(res.is_err()); assert_eq!( res.unwrap_err().to_string(), - format!("expected `:` at line 4 column 1 in {}", path_with_extension.to_str().unwrap()) + format!("expected `:` at line 4 column 1 in {}", path_with_extension.display()) ); } diff --git a/tests/file_toml.rs b/tests/file_toml.rs index a2a1caf..4d2015e 100644 --- a/tests/file_toml.rs +++ b/tests/file_toml.rs @@ -85,6 +85,6 @@ fn test_error_parse() { assert!(res.is_err()); assert_eq!( res.unwrap_err().to_string(), - format!("failed to parse datetime for key `error` at line 2 column 9 in {}", path_with_extension.to_str().unwrap()) + format!("failed to parse datetime for key `error` at line 2 column 9 in {}", path_with_extension.display()) ); } diff --git a/tests/file_yaml.rs b/tests/file_yaml.rs index efc2908..8f7814e 100644 --- a/tests/file_yaml.rs +++ b/tests/file_yaml.rs @@ -76,6 +76,6 @@ fn test_error_parse() { assert_eq!( res.unwrap_err().to_string(), format!("while parsing a block mapping, did not find expected key at \ - line 2 column 1 in {}", path_with_extension.to_str().unwrap()) + line 2 column 1 in {}", path_with_extension.display()) ); } -- cgit v1.2.3