Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed handling of filter regexps. #69

Merged
merged 2 commits into from
Jan 28, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions env/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,7 @@ path = ".."

[dependencies]
regex = "0.1"

[[test]]
name = "regexp_filter"
harness = false
2 changes: 1 addition & 1 deletion env/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ impl Log for Logger {
}

if let Some(filter) = self.filter.as_ref() {
if filter.is_match(&*record.args().to_string()) {
if !filter.is_match(&*record.args().to_string()) {
return;
}
}
Expand Down
51 changes: 51 additions & 0 deletions env/tests/regexp_filter.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#[macro_use] extern crate log;
extern crate env_logger;

use std::process;
use std::env;
use std::str;

fn main() {
if env::var("LOG_REGEXP_TEST").ok() == Some(String::from("1")) {
child_main();
} else {
parent_main()
}
}

fn child_main() {
env_logger::init().unwrap();
info!("XYZ Message");
}

fn run_child(rust_log: String) -> bool {
let exe = env::current_exe().unwrap();
let out = process::Command::new(exe)
.env("LOG_REGEXP_TEST", "1")
.env("RUST_LOG", rust_log)
.output()
.unwrap_or_else(|e| panic!("Unable to start child process: {}", e));
str::from_utf8(out.stderr.as_ref()).unwrap().contains("XYZ Message")
}

fn assert_message_printed(rust_log: &str) {
if !run_child(rust_log.to_string()) {
panic!("RUST_LOG={} should allow the test log message", rust_log)
}
}

fn assert_message_not_printed(rust_log: &str) {
if run_child(rust_log.to_string()) {
panic!("RUST_LOG={} should not allow the test log message", rust_log)
}
}

fn parent_main() {
// test normal log severity levels
assert_message_printed("info");
assert_message_not_printed("warn");

// test of regular expression filters
assert_message_printed("info/XYZ");
assert_message_not_printed("info/XXX");
}