Skip to main content

test_r_macro/
lib.rs

1mod deps;
2mod dynamic;
3mod helpers;
4mod hosted_rpc;
5mod suite;
6mod test;
7
8use proc_macro::TokenStream;
9
10#[proc_macro]
11pub fn uses_test_r(_item: TokenStream) -> TokenStream {
12    r#"
13        #[cfg(test)]
14        pub fn main() -> std::process::ExitCode {
15            test_r::core::test_runner()
16        }
17    "#
18    .parse()
19    .unwrap()
20}
21
22#[proc_macro_attribute]
23pub fn test(attr: TokenStream, item: TokenStream) -> TokenStream {
24    test::test_impl(attr, item, false)
25}
26
27#[proc_macro_attribute]
28pub fn bench(attr: TokenStream, item: TokenStream) -> TokenStream {
29    test::test_impl(attr, item, true)
30}
31
32#[proc_macro]
33pub fn inherit_test_dep(item: TokenStream) -> TokenStream {
34    deps::inherit_test_dep(item)
35}
36
37#[proc_macro]
38pub fn define_matrix_dimension(item: TokenStream) -> TokenStream {
39    deps::define_matrix_dimension(item)
40}
41
42#[proc_macro_attribute]
43pub fn test_dep(attr: TokenStream, item: TokenStream) -> TokenStream {
44    deps::test_dep(attr, item)
45}
46
47#[proc_macro_attribute]
48pub fn test_gen(_attr: TokenStream, item: TokenStream) -> TokenStream {
49    dynamic::test_gen(item)
50}
51
52#[proc_macro]
53pub fn add_test(input: TokenStream) -> TokenStream {
54    dynamic::add_test(input)
55}
56
57#[proc_macro_attribute]
58pub fn timeout(attr: TokenStream, item: TokenStream) -> TokenStream {
59    suite::timeout(attr, item)
60}
61
62#[proc_macro]
63pub fn timeout_suite(input: TokenStream) -> TokenStream {
64    suite::timeout_suite(input)
65}
66
67#[proc_macro_attribute]
68pub fn flaky(_attr: TokenStream, item: TokenStream) -> TokenStream {
69    item
70}
71
72#[proc_macro_attribute]
73pub fn non_flaky(_attr: TokenStream, item: TokenStream) -> TokenStream {
74    item
75}
76
77#[proc_macro_attribute]
78pub fn always_capture(_attr: TokenStream, item: TokenStream) -> TokenStream {
79    item
80}
81
82#[proc_macro_attribute]
83pub fn never_capture(_attr: TokenStream, item: TokenStream) -> TokenStream {
84    item
85}
86
87#[proc_macro_attribute]
88pub fn always_report_time(_attr: TokenStream, item: TokenStream) -> TokenStream {
89    item
90}
91
92#[proc_macro_attribute]
93pub fn never_report_time(_attr: TokenStream, item: TokenStream) -> TokenStream {
94    item
95}
96
97#[proc_macro_attribute]
98pub fn always_ensure_time(_attr: TokenStream, item: TokenStream) -> TokenStream {
99    item
100}
101
102#[proc_macro_attribute]
103pub fn never_ensure_time(_attr: TokenStream, item: TokenStream) -> TokenStream {
104    item
105}
106
107#[proc_macro_attribute]
108pub fn ignore_detached_panics(_attr: TokenStream, item: TokenStream) -> TokenStream {
109    item
110}
111
112#[proc_macro_attribute]
113pub fn tag(attr: TokenStream, item: TokenStream) -> TokenStream {
114    suite::tag(attr, item)
115}
116
117#[proc_macro]
118pub fn tag_suite(input: TokenStream) -> TokenStream {
119    suite::tag_suite(input)
120}
121
122#[proc_macro_attribute]
123pub fn sequential(_attr: TokenStream, item: TokenStream) -> TokenStream {
124    suite::sequential(item)
125}
126
127#[proc_macro]
128pub fn sequential_suite(input: TokenStream) -> TokenStream {
129    suite::sequential_suite(input)
130}
131
132/// HR1.1: trait-driven boilerplate eliminator for `HostedRpcDep` /
133/// `AsyncHostedRpcDep`.
134///
135/// Apply to a user trait declaration to emit a `<Trait>Stub` worker-side
136/// struct that implements the trait by routing each call through a
137/// [`test_r::core::HostedRpcChannel`], plus a `<Trait>Dispatch` helper
138/// trait blanket-implemented for every `T: Trait` so the owner-side
139/// dispatch impl can delegate to a generated method-table dispatcher
140/// instead of writing the per-method match arms by hand.
141///
142/// Async-mode is auto-detected: if every method in the trait is declared
143/// `async fn`, the macro generates async stub methods and an async
144/// dispatch helper, and the owner is expected to implement
145/// [`test_r::core::AsyncHostedRpcDep`] instead of
146/// [`test_r::core::HostedRpcDep`]. Mixing sync and `async fn` methods in
147/// the same `#[hosted_rpc]` trait is a compile error. There is no
148/// `#[hosted_rpc(async)]` flag.
149///
150/// See the rustdoc on the macro module for the precise wire format and
151/// the remaining restrictions (no generics, no associated types).
152#[proc_macro_attribute]
153pub fn hosted_rpc(attr: TokenStream, item: TokenStream) -> TokenStream {
154    hosted_rpc::hosted_rpc(attr, item)
155}