traced_test/
lib.rs

1// ---------------- [ File: src/lib.rs ]
2#![allow(dead_code)]
3#![allow(unreachable_code)]
4#![allow(unused_imports)]
5#![feature(proc_macro_diagnostic)]
6#![allow(unused_variables)]
7extern crate proc_macro;
8
9#[macro_use] mod imports; use imports::*;
10#[macro_use] mod syn_imports; use syn_imports::*;
11
12xp!{async_should_fail}
13xp!{should_fail_attr}
14xp!{async_should_pass}
15xp!{attribute_kind}
16xp!{check_is_function_async}
17xp!{check_panic_message}
18xp!{ensure_item_has_no_test_attribute}
19xp!{errors}
20xp!{extract_all_attributes_except_test_attribute}
21xp!{generate_new_block}
22xp!{check_returns_result}
23xp!{return_type_tokens}
24xp!{write_token_stream}
25xp!{get_should_fail_attr}
26xp!{is_should_panic_attr}
27xp!{should_trace}
28xp!{is_test_attribute}
29xp!{original}
30xp!{panic_handler}
31xp!{parse_or_compile_error}
32xp!{result_handling}
33xp!{should_panic_attr}
34xp!{traced_test_attr}
35xp!{sync_should_fail}
36xp!{sync_should_pass}
37xp!{test_builder}
38xp!{traced_test}
39xp!{tracing_setup_tokens}
40xp!{use_statements}
41xp!{wrap_async_test}
42xp!{wrap_sync_test}
43xp!{wrap_the_original_block}
44xp!{backtrace_guard}
45xp!{flush_logs_if_needed}
46xp!{tracing_guard}
47xp!{end_of_test_guard}
48
49#[proc_macro_attribute]
50pub fn traced_test(attr: TokenStream, item: TokenStream) -> TokenStream {
51
52    let traced_test_attr = parse_macro_input!(attr as TracedTestAttr);
53    let item_fn          = parse_macro_input!(item as ItemFn);
54
55    let generator = match TracedTestGenerator::from_item_fn(item_fn, traced_test_attr) {
56        Ok(test) => test,
57        Err(e) => panic!("traced_test generator error: {:#?}", e),
58    };
59
60    let output = match generator.write_token_stream() {
61        Ok(output_fn) => output_fn,
62        Err(e) => panic!("traced_test generator error: {:#?}", e),
63    };
64
65    output.into()
66}