Skip to content

Commit

Permalink
Fix paths in tests expectations for all platforms
Browse files Browse the repository at this point in the history
  • Loading branch information
szarykott committed Sep 6, 2020
1 parent 05f6d42 commit 53b8bf7
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 11 deletions.
11 changes: 7 additions & 4 deletions tests/errors.rs
Expand Up @@ -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();
Expand All @@ -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())
);
}

Expand All @@ -33,12 +36,12 @@ fn test_error_type() {

let res = c.get::<bool>("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())
);
}

Expand Down
5 changes: 4 additions & 1 deletion tests/file_hjson.rs
Expand Up @@ -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 {
Expand Down Expand Up @@ -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())
);
}
5 changes: 4 additions & 1 deletion tests/file_ini.rs
Expand Up @@ -8,6 +8,7 @@ extern crate serde;
extern crate serde_derive;

use config::*;
use std::path::PathBuf;

#[derive(Debug, Deserialize, PartialEq)]
struct Place {
Expand Down Expand Up @@ -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())
);
}
5 changes: 4 additions & 1 deletion tests/file_json.rs
Expand Up @@ -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 {
Expand Down Expand Up @@ -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())
);
}
5 changes: 4 additions & 1 deletion tests/file_toml.rs
Expand Up @@ -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 {
Expand Down Expand Up @@ -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())
);
}
8 changes: 5 additions & 3 deletions tests/file_yaml.rs
Expand Up @@ -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 {
Expand Down Expand Up @@ -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())
);
}

0 comments on commit 53b8bf7

Please sign in to comment.