1use tracing::subscriber::with_default;
2use tracing_attributes::instrument;
3use tracing_mock::*;
4
5#[instrument]
6fn default_name() {}
7
8#[instrument(name = "my_name")]
9fn custom_name() {}
10
11// XXX: it's weird that we support both of these forms, but apparently we
12// managed to release a version that accepts both syntax, so now we have to
13// support it! yay!
14#[instrument("my_other_name")]
15fn custom_name_no_equals() {}
16
17#[test]
18fn default_name_test() {
19 let (subscriber, handle) = subscriber::mock()
20 .new_span(expect::span().named("default_name"))
21 .enter(expect::span().named("default_name"))
22 .exit(expect::span().named("default_name"))
23 .only()
24 .run_with_handle();
25
26 with_default(subscriber, || {
27 default_name();
28 });
29
30 handle.assert_finished();
31}
32
33#[test]
34fn custom_name_test() {
35 let (subscriber, handle) = subscriber::mock()
36 .new_span(expect::span().named("my_name"))
37 .enter(expect::span().named("my_name"))
38 .exit(expect::span().named("my_name"))
39 .only()
40 .run_with_handle();
41
42 with_default(subscriber, || {
43 custom_name();
44 });
45
46 handle.assert_finished();
47}
48
49#[test]
50fn custom_name_no_equals_test() {
51 let (subscriber, handle) = subscriber::mock()
52 .new_span(expect::span().named("my_other_name"))
53 .enter(expect::span().named("my_other_name"))
54 .exit(expect::span().named("my_other_name"))
55 .only()
56 .run_with_handle();
57
58 with_default(subscriber, || {
59 custom_name_no_equals();
60 });
61
62 handle.assert_finished();
63}
64