1use tracing::subscriber::with_default;
2use tracing::Level;
3use tracing_attributes::instrument;
4use tracing_mock::*;
5
6#[test]
7fn named_levels() {
8 #[instrument(level = "trace")]
9 fn trace() {}
10
11 #[instrument(level = "Debug")]
12 fn debug() {}
13
14 #[instrument(level = "INFO")]
15 fn info() {}
16
17 #[instrument(level = "WARn")]
18 fn warn() {}
19
20 #[instrument(level = "eRrOr")]
21 fn error() {}
22 let (subscriber, handle) = subscriber::mock()
23 .new_span(expect::span().named("trace").at_level(Level::TRACE))
24 .enter(expect::span().named("trace").at_level(Level::TRACE))
25 .exit(expect::span().named("trace").at_level(Level::TRACE))
26 .new_span(expect::span().named("debug").at_level(Level::DEBUG))
27 .enter(expect::span().named("debug").at_level(Level::DEBUG))
28 .exit(expect::span().named("debug").at_level(Level::DEBUG))
29 .new_span(expect::span().named("info").at_level(Level::INFO))
30 .enter(expect::span().named("info").at_level(Level::INFO))
31 .exit(expect::span().named("info").at_level(Level::INFO))
32 .new_span(expect::span().named("warn").at_level(Level::WARN))
33 .enter(expect::span().named("warn").at_level(Level::WARN))
34 .exit(expect::span().named("warn").at_level(Level::WARN))
35 .new_span(expect::span().named("error").at_level(Level::ERROR))
36 .enter(expect::span().named("error").at_level(Level::ERROR))
37 .exit(expect::span().named("error").at_level(Level::ERROR))
38 .only()
39 .run_with_handle();
40
41 with_default(subscriber, || {
42 trace();
43 debug();
44 info();
45 warn();
46 error();
47 });
48
49 handle.assert_finished();
50}
51
52#[test]
53fn numeric_levels() {
54 #[instrument(level = 1)]
55 fn trace() {}
56
57 #[instrument(level = 2)]
58 fn debug() {}
59
60 #[instrument(level = 3)]
61 fn info() {}
62
63 #[instrument(level = 4)]
64 fn warn() {}
65
66 #[instrument(level = 5)]
67 fn error() {}
68 let (subscriber, handle) = subscriber::mock()
69 .new_span(expect::span().named("trace").at_level(Level::TRACE))
70 .enter(expect::span().named("trace").at_level(Level::TRACE))
71 .exit(expect::span().named("trace").at_level(Level::TRACE))
72 .new_span(expect::span().named("debug").at_level(Level::DEBUG))
73 .enter(expect::span().named("debug").at_level(Level::DEBUG))
74 .exit(expect::span().named("debug").at_level(Level::DEBUG))
75 .new_span(expect::span().named("info").at_level(Level::INFO))
76 .enter(expect::span().named("info").at_level(Level::INFO))
77 .exit(expect::span().named("info").at_level(Level::INFO))
78 .new_span(expect::span().named("warn").at_level(Level::WARN))
79 .enter(expect::span().named("warn").at_level(Level::WARN))
80 .exit(expect::span().named("warn").at_level(Level::WARN))
81 .new_span(expect::span().named("error").at_level(Level::ERROR))
82 .enter(expect::span().named("error").at_level(Level::ERROR))
83 .exit(expect::span().named("error").at_level(Level::ERROR))
84 .only()
85 .run_with_handle();
86
87 with_default(subscriber, || {
88 trace();
89 debug();
90 info();
91 warn();
92 error();
93 });
94
95 handle.assert_finished();
96}
97
98#[test]
99fn enum_levels() {
100 #[instrument(level = Level::TRACE)]
101 fn trace() {}
102
103 #[instrument(level = Level::DEBUG)]
104 fn debug() {}
105
106 #[instrument(level = tracing::Level::INFO)]
107 fn info() {}
108
109 #[instrument(level = Level::WARN)]
110 fn warn() {}
111
112 #[instrument(level = Level::ERROR)]
113 fn error() {}
114 let (subscriber, handle) = subscriber::mock()
115 .new_span(expect::span().named("trace").at_level(Level::TRACE))
116 .enter(expect::span().named("trace").at_level(Level::TRACE))
117 .exit(expect::span().named("trace").at_level(Level::TRACE))
118 .new_span(expect::span().named("debug").at_level(Level::DEBUG))
119 .enter(expect::span().named("debug").at_level(Level::DEBUG))
120 .exit(expect::span().named("debug").at_level(Level::DEBUG))
121 .new_span(expect::span().named("info").at_level(Level::INFO))
122 .enter(expect::span().named("info").at_level(Level::INFO))
123 .exit(expect::span().named("info").at_level(Level::INFO))
124 .new_span(expect::span().named("warn").at_level(Level::WARN))
125 .enter(expect::span().named("warn").at_level(Level::WARN))
126 .exit(expect::span().named("warn").at_level(Level::WARN))
127 .new_span(expect::span().named("error").at_level(Level::ERROR))
128 .enter(expect::span().named("error").at_level(Level::ERROR))
129 .exit(expect::span().named("error").at_level(Level::ERROR))
130 .only()
131 .run_with_handle();
132
133 with_default(subscriber, || {
134 trace();
135 debug();
136 info();
137 warn();
138 error();
139 });
140
141 handle.assert_finished();
142}
143