diff --git a/test_cfgs/malformed_appender.yml b/test_cfgs/malformed_appender.yml new file mode 100755 index 00000000..f9db7d57 --- /dev/null +++ b/test_cfgs/malformed_appender.yml @@ -0,0 +1,13 @@ +refresh_rate: 5 seconds + +appenders: + file: + kind: file + pah: "log/file.log" + encoder: + pattern: "[{d(%Y-%m-%dT%H:%M:%S%.6f)} {h({l}):<5.5} {M}] {m}{n}" + +root: + level: info + appenders: + - file diff --git a/test_cfgs/test.json b/test_cfgs/test.json new file mode 100644 index 00000000..b93f08c9 --- /dev/null +++ b/test_cfgs/test.json @@ -0,0 +1,51 @@ +{ + "refresh_rate": "5 seconds", + "appenders": { + "stdout": { + "kind": "console", + "encoder": { + "pattern": "{d(%+)(utc)} [{f}:{L}] {h({l})} {M}:{m}{n}" + }, + "filters": [ + { + "kind": "threshold", + "level": "info" + } + ] + }, + "file": { + "kind": "file", + "path": "log/file.log", + "encoder": { + "pattern": "[{d(%Y-%m-%dT%H:%M:%S%.6f)} {h({l}):<5.5} {M}] {m}{n}" + } + }, + "rollingfile": { + "kind": "rolling_file", + "path": "log/rolling_file.log", + "encoder": { + "pattern": "[{d(%Y-%m-%dT%H:%M:%S%.6f)} {h({l}):<5.5} {M}] {m}{n}" + }, + "policy": { + "trigger": { + "kind": "time", + "interval": "1 minute" + }, + "roller": { + "kind": "fixed_window", + "pattern": "log/old-rolling_file-{}.log", + "base": 0, + "count": 2 + } + } + } + }, + "root": { + "level": "info", + "appenders": [ + "stdout", + "file", + "rollingfile" + ] + } +} diff --git a/test_cfgs/test.toml b/test_cfgs/test.toml new file mode 100644 index 00000000..dc1f10da --- /dev/null +++ b/test_cfgs/test.toml @@ -0,0 +1,39 @@ +refresh_rate = "5 seconds" + +[appenders.stdout] +kind = "console" + + [appenders.stdout.encoder] + pattern = "{d(%+)(utc)} [{f}:{L}] {h({l})} {M}:{m}{n}" + + [[appenders.stdout.filters]] + kind = "threshold" + level = "info" + +[appenders.file] +kind = "file" +path = "log/file.log" + + [appenders.file.encoder] + pattern = "[{d(%Y-%m-%dT%H:%M:%S%.6f)} {h({l}):<5.5} {M}] {m}{n}" + +[appenders.rollingfile] +kind = "rolling_file" +path = "log/rolling_file.log" + + [appenders.rollingfile.encoder] + pattern = "[{d(%Y-%m-%dT%H:%M:%S%.6f)} {h({l}):<5.5} {M}] {m}{n}" + +[appenders.rollingfile.policy.trigger] +kind = "time" +interval = "1 minute" + +[appenders.rollingfile.policy.roller] +kind = "fixed_window" +pattern = "log/old-rolling_file-{}.log" +base = 0 +count = 2 + +[root] +level = "info" +appenders = [ "stdout", "file", "rollingfile" ] diff --git a/test_cfgs/test.yml b/test_cfgs/test.yml new file mode 100644 index 00000000..47d18ccd --- /dev/null +++ b/test_cfgs/test.yml @@ -0,0 +1,36 @@ +refresh_rate: 5 seconds + +appenders: + stdout: + kind: console + encoder: + pattern: "{d(%+)(utc)} [{f}:{L}] {h({l})} {M}:{m}{n}" + filters: + - kind: threshold + level: info + file: + kind: file + path: "log/file.log" + encoder: + pattern: "[{d(%Y-%m-%dT%H:%M:%S%.6f)} {h({l}):<5.5} {M}] {m}{n}" + rollingfile: + kind: rolling_file + path: "log/rolling_file.log" + encoder: + pattern: "[{d(%Y-%m-%dT%H:%M:%S%.6f)} {h({l}):<5.5} {M}] {m}{n}" + policy: + trigger: + kind: time + interval: 1 minute + roller: + kind: fixed_window + pattern: "log/old-rolling_file-{}.log" + base: 0 + count: 2 + +root: + level: info + appenders: + - stdout + - file + - rollingfile diff --git a/tests/color_control.rs b/tests/color_control.rs deleted file mode 100644 index 344f032f..00000000 --- a/tests/color_control.rs +++ /dev/null @@ -1,24 +0,0 @@ -use std::process::Command; - -fn execute_test(env_key: &str, env_val: &str) { - let mut child_proc = Command::new("cargo") - .args(&["run", "--example", "compile_time_config"]) - .env(env_key, env_val) - .spawn() - .expect("Cargo command failed to start"); - - let ecode = child_proc.wait().expect("failed to wait on child"); - - assert!(ecode.success()); -} - -// Maintaining as a single test to avoid blocking calls to the package cache -#[test] -fn test_no_color() { - let keys = vec!["NO_COLOR", "CLICOLOR_FORCE", "CLICOLOR"]; - - for key in keys { - execute_test(key, "1"); - execute_test(key, "0"); - } -} diff --git a/tests/init_json_config.rs b/tests/init_json_config.rs new file mode 100755 index 00000000..7e6287c5 --- /dev/null +++ b/tests/init_json_config.rs @@ -0,0 +1,12 @@ +#[test] +#[cfg(all(feature = "config_parsing", feature = "json_format"))] +fn test_init_json_cfg() { + use log4rs; + use std::path::Path; + + assert!(log4rs::init_file( + Path::new("./test_cfgs/test.json"), + log4rs::config::Deserializers::default() + ) + .is_ok()); +} diff --git a/tests/init_malformed_appenders.rs b/tests/init_malformed_appenders.rs new file mode 100755 index 00000000..c6b9e36d --- /dev/null +++ b/tests/init_malformed_appenders.rs @@ -0,0 +1,14 @@ +#[test] +#[cfg(all(feature = "config_parsing", feature = "yaml_format"))] +fn test_malformed_appenders() { + use std::fs; + + let config_str = fs::read_to_string("test_cfgs/malformed_appender.yml").unwrap(); + let cfg = ::serde_yaml::from_str::(&config_str); + + assert!(cfg.is_ok()); + let cfg = cfg.unwrap(); + + let res = log4rs::config::create_raw_config(cfg); + assert!(res.is_err()); +} diff --git a/tests/init_toml_config.rs b/tests/init_toml_config.rs new file mode 100755 index 00000000..f5b576ca --- /dev/null +++ b/tests/init_toml_config.rs @@ -0,0 +1,12 @@ +#[test] +#[cfg(all(feature = "config_parsing", feature = "toml_format"))] +fn test_init_toml_cfg() { + use log4rs; + use std::path::Path; + + assert!(log4rs::init_file( + Path::new("./test_cfgs/test.toml"), + log4rs::config::Deserializers::default() + ) + .is_ok()); +} diff --git a/tests/init_yaml_config.rs b/tests/init_yaml_config.rs new file mode 100755 index 00000000..b2a5f4da --- /dev/null +++ b/tests/init_yaml_config.rs @@ -0,0 +1,12 @@ +#[test] +#[cfg(all(feature = "config_parsing", feature = "yaml_format"))] +fn test_init_yaml_cfg() { + use log4rs; + use std::path::Path; + + assert!(log4rs::init_file( + Path::new("./test_cfgs/test.yml"), + log4rs::config::Deserializers::default() + ) + .is_ok()); +}