Skip to content

Commit

Permalink
Merge branch 'main' into harness
Browse files Browse the repository at this point in the history
  • Loading branch information
wenyuzhao committed Jun 27, 2024
2 parents a903579 + 09a6daa commit cbc6bab
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 75 deletions.
6 changes: 4 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

69 changes: 0 additions & 69 deletions mallockit/build.rs

This file was deleted.

2 changes: 2 additions & 0 deletions mallockit/macros/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,5 @@ proc-macro = true
[dependencies]
quote = { workspace = true }
syn = { workspace = true }
cargo_metadata = { workspace = true }
proc-macro2 = "1.0.86"
37 changes: 33 additions & 4 deletions mallockit/macros/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,42 @@
use std::collections::HashMap;

use proc_macro::TokenStream;
use quote::quote;

fn construct_tests_from_config() -> Vec<proc_macro2::TokenStream> {
let meta = cargo_metadata::MetadataCommand::new().exec().unwrap();
let mut tests = HashMap::new();
let ws_meta = meta.workspace_metadata.as_object();
if let Some(v) = ws_meta.and_then(|v| v.get("malloc-tests")) {
for (name, cmd) in v.as_object().unwrap() {
let cmd = cmd.as_str().unwrap();
tests.insert(name.to_owned(), cmd.to_owned());
}
}
tests
.iter()
.map(|(k, v)| {
let s = format!(
r#"
#[test]
fn {}() {{
::mallockit::util::testing::malloc::test(env!("CARGO_CRATE_NAME"), {:?});
}}
"#,
k, v,
);
s.parse().unwrap()
})
.collect()
}

#[proc_macro_attribute]
pub fn plan(_attr: TokenStream, item: TokenStream) -> TokenStream {
let input = syn::parse_macro_input!(item as syn::DeriveInput);
let name = &input.ident;

let tests = construct_tests_from_config();

let result = quote! {
#input

Expand Down Expand Up @@ -40,10 +72,7 @@ pub fn plan(_attr: TokenStream, item: TokenStream) -> TokenStream {

#[cfg(test)]
mod tests {
include!(concat!(
env!("CARGO_MANIFEST_DIR"),
"/../target/generated_tests.rs"
));
#(#tests)*
::mallockit::rust_allocator_tests!(crate::Global);
}
};
Expand Down

0 comments on commit cbc6bab

Please sign in to comment.