File: panic_logging.rs

package info (click to toggle)
rust-fern 0.7.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 652 kB
  • sloc: makefile: 2
file content (43 lines) | stat: -rw-r--r-- 1,064 bytes parent folder | download | duplicates (3)
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
41
42
43
//! Test the functionality of panicking on error+ log messages.
use log::Level::*;

mod support;

use support::manual_log;

#[test]
#[should_panic(expected = "special panic message here")]
fn test_panic_panics() {
    let (_max_level, logger) = fern::Dispatch::new().chain(fern::Panic).into_log();

    let l = &*logger;

    manual_log(l, Info, "special panic message here");
}

fn warn_and_higher_panics_config() -> Box<dyn log::Log> {
    let (_max_level, logger) = fern::Dispatch::new()
        .chain(
            fern::Dispatch::new()
                .level(log::LevelFilter::Warn)
                .chain(fern::Panic),
        )
        .chain(std::io::stdout())
        .into_log();
    logger
}

#[test]
fn double_chained_with_panics_no_info_panic() {
    let l = &*warn_and_higher_panics_config();

    manual_log(l, Info, "this should not panic");
}

#[test]
#[should_panic(expected = "this should panic")]
fn double_chained_with_panics_yes_error_panic() {
    let l = &*warn_and_higher_panics_config();

    manual_log(l, Error, "this should panic");
}