fix: test suite proc macro

This commit is contained in:
Oleksandr Pravdyvyi 2025-10-22 13:55:35 +03:00
parent 37360e6d8c
commit 31783d9b78
No known key found for this signature in database
GPG Key ID: 9F8955C63C443871
6 changed files with 1653 additions and 1693 deletions

View File

@ -10,7 +10,8 @@ members = [
"wallet",
"sequencer_core",
"common",
"nssa",
"nssa",
"proc_macro_test_attribute",
]
[workspace.dependencies]

View File

@ -17,6 +17,8 @@ borsh.workspace = true
nssa-core = { path = "../nssa/core", features = ["host"] }
proc_macro_test_attribute = { path = "../proc_macro_test_attribute" }
[dependencies.clap]
features = ["derive", "env"]
workspace = true

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,9 @@
[package]
name = "proc_macro_test_attribute"
version = "0.1.0"
edition = "2024"
[dependencies]
[lib]
proc-macro = true

View File

@ -0,0 +1,49 @@
extern crate proc_macro;
use proc_macro::*;
#[proc_macro_attribute]
pub fn test_suite_fn(_attr: TokenStream, item: TokenStream) -> TokenStream {
let input = item.to_string();
let fn_keyword = "fn ";
let fn_keyword_alternative = "fn\n";
let mut start_opt = None;
let mut fn_name = String::new();
if let Some(start) = input.find(fn_keyword) {
start_opt = Some(start);
} else if let Some(start) = input.find(fn_keyword_alternative) {
start_opt = Some(start);
}
if let Some(start) = start_opt {
let rest = &input[start + fn_keyword.len()..];
if let Some(end) = rest.find(|c: char| c == '(' || c.is_whitespace()) {
let name = &rest[..end];
fn_name = name.to_string();
}
} else {
println!("ERROR: keyword fn not found");
}
let extension = format!(
r#"
{input}
function_map.insert("{fn_name}".to_string(), |home_dir: PathBuf| Box::pin(async {{
let res = pre_test(home_dir).await.unwrap();
info!("Waiting for first block creation");
tokio::time::sleep(Duration::from_secs(TIME_TO_WAIT_FOR_BLOCK_SECONDS)).await;
{fn_name}().await;
post_test(res).await;
}}));
"#
);
extension.parse().unwrap()
}