• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 use tracing::subscriber::with_default;
2 use tracing_attributes::instrument;
3 use tracing_mock::*;
4 
5 #[instrument]
default_name()6 fn default_name() {}
7 
8 #[instrument(name = "my_name")]
custom_name()9 fn 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")]
custom_name_no_equals()15 fn custom_name_no_equals() {}
16 
17 #[test]
default_name_test()18 fn default_name_test() {
19     let (subscriber, handle) = subscriber::mock()
20         .new_span(span::mock().named("default_name"))
21         .enter(span::mock().named("default_name"))
22         .exit(span::mock().named("default_name"))
23         .done()
24         .run_with_handle();
25 
26     with_default(subscriber, || {
27         default_name();
28     });
29 
30     handle.assert_finished();
31 }
32 
33 #[test]
custom_name_test()34 fn custom_name_test() {
35     let (subscriber, handle) = subscriber::mock()
36         .new_span(span::mock().named("my_name"))
37         .enter(span::mock().named("my_name"))
38         .exit(span::mock().named("my_name"))
39         .done()
40         .run_with_handle();
41 
42     with_default(subscriber, || {
43         custom_name();
44     });
45 
46     handle.assert_finished();
47 }
48 
49 #[test]
custom_name_no_equals_test()50 fn custom_name_no_equals_test() {
51     let (subscriber, handle) = subscriber::mock()
52         .new_span(span::mock().named("my_other_name"))
53         .enter(span::mock().named("my_other_name"))
54         .exit(span::mock().named("my_other_name"))
55         .done()
56         .run_with_handle();
57 
58     with_default(subscriber, || {
59         custom_name_no_equals();
60     });
61 
62     handle.assert_finished();
63 }
64