File: test_parse_errors.rs

package info (click to toggle)
rust-flexi-logger 0.29.8-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,084 kB
  • sloc: makefile: 2
file content (79 lines) | stat: -rw-r--r-- 2,347 bytes parent folder | download
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
use flexi_logger::{FlexiLoggerError, LogSpecification, Logger};
use log::*;

#[test]
fn parse_errors_logspec() {
    match LogSpecification::parse("info, foo=bar, fuzz=debug")
        .err()
        .unwrap()
    {
        FlexiLoggerError::Parse(_, logspec) => {
            assert_eq!(
                logspec.module_filters(),
                LogSpecification::parse("info, fuzz=debug")
                    .unwrap()
                    .module_filters()
            );
            #[cfg(feature = "textfilter")]
            assert!(logspec.text_filter().is_none());
        }
        _ => panic!("Wrong error from parsing (1)"),
    }

    match LogSpecification::parse("info, ene mene dubbedene")
        .err()
        .unwrap()
    {
        FlexiLoggerError::Parse(_, logspec) => {
            assert_eq!(
                logspec.module_filters(),
                LogSpecification::parse("info").unwrap().module_filters()
            );
            #[cfg(feature = "textfilter")]
            assert!(logspec.text_filter().is_none());
        }
        _ => panic!("Wrong error from parsing (2)"),
    }

    match LogSpecification::parse("ene mene dubbedene").err().unwrap() {
        FlexiLoggerError::Parse(_, logspec) => {
            assert_eq!(
                logspec.module_filters(),
                LogSpecification::off().module_filters()
            );
            #[cfg(feature = "textfilter")]
            assert!(logspec.text_filter().is_none());
        }
        _ => panic!("Wrong error from parsing (3)"),
    }

    match LogSpecification::parse("INFO, ene / mene / dubbedene")
        .err()
        .unwrap()
    {
        FlexiLoggerError::Parse(_, logspec) => {
            assert_eq!(
                logspec.module_filters(),
                LogSpecification::off().module_filters()
            );
            #[cfg(feature = "textfilter")]
            assert!(logspec.text_filter().is_none());
        }
        _ => panic!("Wrong error from parsing (4)"),
    }
}

#[test]
fn parse_errors_logger() {
    let result = Logger::try_with_str("info, foo=baz");
    assert!(result.is_err());
    let error = result.err().unwrap();
    println!("err: {error}");

    Logger::try_with_str("info, foo=debug")
        .unwrap()
        .start()
        .unwrap();
    info!("logging works");
    info!("logging works");
}