summaryrefslogtreecommitdiffstats
path: root/vendor/env_logger/tests/init-twice-retains-filter.rs
blob: 673da3fd287995c1fe80593370c9b6d659d0d654 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
extern crate env_logger;
extern crate log;

use std::env;
use std::process;
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_filters("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);
}