Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #117 from KodrAus/fix/retain-previously-set-max-level
Don't clobber a previously set level filter
- Loading branch information
Showing
3 changed files
with
52 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
extern crate log; | ||
extern crate env_logger; | ||
|
||
use std::process; | ||
use std::env; | ||
use std::str; | ||
|
||
fn main() { | ||
if env::var("YOU_ARE_TESTING_NOW").is_ok() { | ||
// Init from the env (which should set the max level to `Debug`) | ||
env_logger::init(); | ||
|
||
assert_eq!(log::LevelFilter::Debug, log::max_level()); | ||
|
||
// Init again using a different max level | ||
// This shouldn't clobber the level that was previously set | ||
env_logger::Builder::new() | ||
.parse("info") | ||
.try_init() | ||
.unwrap_err(); | ||
|
||
assert_eq!(log::LevelFilter::Debug, log::max_level()); | ||
return | ||
} | ||
|
||
let exe = env::current_exe().unwrap(); | ||
let out = process::Command::new(exe) | ||
.env("YOU_ARE_TESTING_NOW", "1") | ||
.env("RUST_LOG", "debug") | ||
.output() | ||
.unwrap_or_else(|e| panic!("Unable to start child process: {}", e)); | ||
if out.status.success() { | ||
return | ||
} | ||
|
||
println!("test failed: {}", out.status); | ||
println!("--- stdout\n{}", str::from_utf8(&out.stdout).unwrap()); | ||
println!("--- stderr\n{}", str::from_utf8(&out.stderr).unwrap()); | ||
process::exit(1); | ||
} |