summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRyan Leckey <ryan@launchbadge.com>2017-06-02 17:36:50 -0700
committerRyan Leckey <ryan@launchbadge.com>2017-06-02 17:36:50 -0700
commit028aaf5247dd3cd184b250afdba235d683525f97 (patch)
treef63aabb0d8eb8776005408786cb9f04189fa7416
parentbfc44c331a77d8c341c076e72df5ed0b56fbd422 (diff)
Started playing with error tests
-rw-r--r--src/error.rs4
-rw-r--r--tests/Settings.invalid.toml2
-rw-r--r--tests/Settings.toml3
-rw-r--r--tests/errors.rs31
4 files changed, 38 insertions, 2 deletions
diff --git a/src/error.rs b/src/error.rs
index b97ebac..8af5cee 100644
--- a/src/error.rs
+++ b/src/error.rs
@@ -105,7 +105,7 @@ impl fmt::Display for ConfigError {
unexpected, expected)?;
if let Some(ref origin) = *origin {
- write!(f, " in {}", origin)?;
+ write!(f, " from {}", origin)?;
}
Ok(())
@@ -115,7 +115,7 @@ impl fmt::Display for ConfigError {
write!(f, "{}", cause)?;
if let Some(ref uri) = *uri {
- write!(f, " in {}", uri)?;
+ write!(f, " from {}", uri)?;
}
Ok(())
diff --git a/tests/Settings.invalid.toml b/tests/Settings.invalid.toml
new file mode 100644
index 0000000..4d159a4
--- /dev/null
+++ b/tests/Settings.invalid.toml
@@ -0,0 +1,2 @@
+ok = true
+error = tru
diff --git a/tests/Settings.toml b/tests/Settings.toml
index f0d2547..58ff5f1 100644
--- a/tests/Settings.toml
+++ b/tests/Settings.toml
@@ -3,6 +3,9 @@ debug_s = "true"
production = false
production_s = "false"
+# errors
+boolean_s_parse = "fals"
+
[place]
name = "Torre di Pisa"
longitude = 43.7224985
diff --git a/tests/errors.rs b/tests/errors.rs
new file mode 100644
index 0000000..b69774c
--- /dev/null
+++ b/tests/errors.rs
@@ -0,0 +1,31 @@
+extern crate config;
+
+use config::*;
+
+fn make() -> Config {
+ let mut c = Config::default();
+ c.merge(File::new("tests/Settings", FileFormat::Toml))
+ .unwrap();
+
+ c
+}
+
+#[test]
+fn test_error_parse() {
+ let mut c = Config::default();
+ c.merge(File::new("tests/Settings.invalid", FileFormat::Toml))
+ .unwrap();
+
+ assert!(false)
+}
+
+#[test]
+fn test_error_type_bool() {
+ let c = make();
+
+ let err = c.get::<bool>("boolean_s_parse");
+
+ assert!(err.is_err());
+ assert_eq!(err.unwrap_err().to_string(),
+ "invalid type: string \"fals\", expected a boolean from tests/Settings.toml".to_string());
+}