From dc4c5a3fdd0f01d331e9e53ed4038e4653f5bea1 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Sat, 9 May 2020 10:24:37 +0200 Subject: Setup logging in tests Signed-off-by: Matthias Beyer --- Cargo.toml | 1 + src/lib.rs | 2 ++ src/resolver.rs | 31 +++++++++++++++++++++++++++++++ 3 files changed, 34 insertions(+) diff --git a/Cargo.toml b/Cargo.toml index 561042d..20e41d8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -30,6 +30,7 @@ toml = "0.5" serde_json = "1" quickcheck = "0.8" serde_derive = "1" +env_logger = "0.7" [features] default = ["backend_toml", "backend_serde_json"] diff --git a/src/lib.rs b/src/lib.rs index bfe3909..48b4fe6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -8,6 +8,8 @@ #[macro_use] extern crate quickcheck; #[cfg(test)] #[macro_use] extern crate serde_derive; +#[cfg(test)] +#[macro_use] extern crate env_logger; pub mod error; pub mod object; diff --git a/src/resolver.rs b/src/resolver.rs index 270e745..ea7fbd3 100644 --- a/src/resolver.rs +++ b/src/resolver.rs @@ -63,6 +63,10 @@ mod test { use toml::from_str as toml_from_str; use toml::Value; + fn setup_logging() { + let _ = env_logger::try_init(); + } + macro_rules! do_resolve { ( $toml:ident => $query:expr ) => { resolve( @@ -75,6 +79,7 @@ mod test { #[test] fn test_resolve_empty_toml_simple_query() { + setup_logging(); let toml : toml::Value = toml_from_str("").unwrap(); let result = do_resolve!(toml => "example"); @@ -86,6 +91,7 @@ mod test { #[test] fn test_resolve_present_bool() { + setup_logging(); let toml: toml::Value = toml_from_str("example = true").unwrap(); let result = do_resolve!(toml => "example"); @@ -100,6 +106,7 @@ mod test { #[test] fn test_resolve_present_integer() { + setup_logging(); let toml: toml::Value = toml_from_str("example = 1").unwrap(); let result = do_resolve!(toml => "example"); @@ -114,6 +121,7 @@ mod test { #[test] fn test_resolve_present_float() { + setup_logging(); let toml: toml::Value = toml_from_str("example = 1.0").unwrap(); let result = do_resolve!(toml => "example"); @@ -129,6 +137,7 @@ mod test { #[test] fn test_resolve_present_string() { + setup_logging(); let toml: toml::Value = toml_from_str("example = 'string'").unwrap(); let result = do_resolve!(toml => "example"); @@ -147,6 +156,7 @@ mod test { #[test] fn test_resolve_present_array_bools() { + setup_logging(); let toml: toml::Value = toml_from_str("example = [ true, false ]").unwrap(); let result = do_resolve!(toml => "example"); @@ -168,6 +178,7 @@ mod test { #[test] fn test_resolve_present_array_integers() { + setup_logging(); let toml: toml::Value = toml_from_str("example = [ 1, 1337 ]").unwrap(); let result = do_resolve!(toml => "example"); @@ -189,6 +200,7 @@ mod test { #[test] fn test_resolve_present_array_floats() { + setup_logging(); let toml: toml::Value = toml_from_str("example = [ 1.0, 133.25 ]").unwrap(); let result = do_resolve!(toml => "example"); @@ -212,6 +224,7 @@ mod test { #[test] fn test_resolve_array_index_query_1() { + setup_logging(); let toml: toml::Value = toml_from_str("example = [ 1 ]").unwrap(); let result = do_resolve!(toml => "example.[0]"); @@ -226,6 +239,7 @@ mod test { #[test] fn test_resolve_array_index_query_2() { + setup_logging(); let toml: toml::Value = toml_from_str("example = [ 1, 2, 3, 4, 5 ]").unwrap(); let result = do_resolve!(toml => "example.[4]"); @@ -240,6 +254,7 @@ mod test { #[test] fn test_resolve_table_element_query() { + setup_logging(); let toml: toml::Value = toml_from_str( r#" [table] @@ -260,6 +275,7 @@ mod test { #[test] fn test_resolve_table_with_many_elements_element_query() { + setup_logging(); let toml: toml::Value = toml_from_str( r#" [table] @@ -284,6 +300,7 @@ mod test { #[test] fn test_resolve_table_array_query() { + setup_logging(); let toml: toml::Value = toml_from_str( r#" [table] @@ -313,6 +330,7 @@ mod test { #[test] fn test_resolve_table_array_element_query() { + setup_logging(); let toml: toml::Value = toml_from_str( r#" [table] @@ -333,6 +351,7 @@ mod test { #[test] fn test_resolve_multi_table_query() { + setup_logging(); let toml: toml::Value = toml_from_str( r#" [table0] @@ -379,6 +398,7 @@ mod test { #[test] fn test_resolve_array_table_query_1() { + setup_logging(); let toml: toml::Value = toml_from_str(FRUIT_TABLE).unwrap(); let result = do_resolve!(toml => "fruit.blah.[0].name"); @@ -397,6 +417,7 @@ mod test { #[test] fn test_resolve_array_table_query_2() { + setup_logging(); let toml: toml::Value = toml_from_str(FRUIT_TABLE).unwrap(); let result = do_resolve!(toml => "fruit.blah.[0].physical"); @@ -424,6 +445,7 @@ mod test { #[test] fn test_resolve_query_on_result() { + setup_logging(); let toml: toml::Value = toml_from_str(FRUIT_TABLE).unwrap(); let result = do_resolve!(toml => "fruit.blah.[1].physical"); @@ -451,6 +473,7 @@ mod test { #[test] fn test_resolve_query_empty_table() { + setup_logging(); let toml: toml::Value = toml_from_str( r#" [example] @@ -474,6 +497,7 @@ mod test { #[test] fn test_resolve_query_member_of_empty_table() { + setup_logging(); let toml: toml::Value = toml_from_str( r#" [example] @@ -490,6 +514,7 @@ mod test { #[test] fn test_resolve_query_index_in_table() { + setup_logging(); let toml: toml::Value = toml_from_str( r#" [example] @@ -506,6 +531,7 @@ mod test { #[test] fn test_resolve_query_identifier_in_array() { + setup_logging(); let toml: toml::Value = toml_from_str( r#" [example] @@ -523,6 +549,7 @@ mod test { #[test] fn test_resolve_query_value_as_table() { + setup_logging(); let toml: toml::Value = toml_from_str( r#" [example] @@ -540,6 +567,7 @@ mod test { #[test] fn test_resolve_query_value_as_array() { + setup_logging(); let toml: toml::Value = toml_from_str( r#" [example] @@ -557,6 +585,7 @@ mod test { #[test] fn test_indexing_out_of_bounds() { + setup_logging(); let toml: toml::Value = toml_from_str( r#" [example] @@ -574,6 +603,7 @@ mod test { #[test] fn test_indexing_out_of_bounds_edgecase_1() { + setup_logging(); let toml: toml::Value = toml_from_str( r#" [example] @@ -591,6 +621,7 @@ mod test { #[test] fn test_indexing_out_of_bounds_edgecase_2() { + setup_logging(); let toml: toml::Value = toml_from_str( r#" [example] -- cgit v1.2.3