-
Notifications
You must be signed in to change notification settings - Fork 823
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3164 from wasmerio/sync-js-sys-tests
Synchronize between -sys and -js tests
- Loading branch information
Showing
14 changed files
with
995 additions
and
2,572 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
[package] | ||
name = "macro-wasmer-universal-test" | ||
version = "0.1.0" | ||
edition = "2021" | ||
license = "MIT" | ||
description = "Universal test macro for wasmer-test" | ||
|
||
[lib] | ||
proc-macro = true | ||
|
||
[dependencies] | ||
proc-quote = "0.4.0" | ||
proc-macro2 = "1.0.43" | ||
syn = { version = "1.0.99", features = ["full"] } | ||
quote = "*" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
extern crate proc_macro; | ||
|
||
use proc_macro::TokenStream; | ||
use proc_macro2::{Ident, Span}; | ||
|
||
#[proc_macro_attribute] | ||
pub fn universal_test(_attr: TokenStream, item: TokenStream) -> TokenStream { | ||
let item_clone = item.clone(); | ||
let mut iter = item_clone.into_iter(); | ||
let _ = iter.next().unwrap(); // fn | ||
let item_tree: proc_macro::TokenTree = iter.next().unwrap(); // fn ... | ||
let n = match &item_tree { | ||
proc_macro::TokenTree::Ident(i) => i.to_string(), | ||
_ => panic!("expected fn ...() -> Result<(), String>"), | ||
}; | ||
|
||
let function_name_normal = Ident::new(&n, Span::call_site()); | ||
let function_name_js = Ident::new(&format!("{}_js", n), Span::call_site()); | ||
let parsed = match syn::parse::<syn::ItemFn>(item) { | ||
Ok(o) => o, | ||
Err(e) => { | ||
return proc_macro::TokenStream::from(e.to_compile_error()); | ||
} | ||
}; | ||
|
||
let tokens = quote::quote! { | ||
#[cfg(feature = "js")] | ||
#[cfg_attr(feature = "js", wasm_bindgen_test)] | ||
fn #function_name_js() { #function_name_normal().unwrap(); } | ||
|
||
#[cfg_attr(feature = "sys", test)] | ||
#parsed | ||
}; | ||
|
||
proc_macro::TokenStream::from(tokens) | ||
} |
Oops, something went wrong.