Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Synchronize between -sys and -js tests #3164

Merged
merged 17 commits into from
Sep 9, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
121 changes: 87 additions & 34 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions lib/api/Cargo.toml
Original file line number Diff line number Diff line change
@@ -55,6 +55,7 @@ winapi = "0.3"
wat = "1.0"
tempfile = "3.1"
anyhow = "1.0"
macro-wasmer-universal-test = { version = "0.1.0", path = "./macro-wasmer-universal-test" }

# Dependencies and Develoment Dependencies for `js`.
[target.'cfg(target_arch = "wasm32")'.dependencies]
@@ -72,6 +73,7 @@ hashbrown = { version = "0.11", optional = true }
wat = "1.0"
anyhow = "1.0"
wasm-bindgen-test = "0.3.0"
macro-wasmer-universal-test = { version = "0.1.0", path = "./macro-wasmer-universal-test" }

# Specific to `js`.
#
12 changes: 12 additions & 0 deletions lib/api/macro-wasmer-universal-test/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[package]
name = "macro-wasmer-universal-test"
version = "0.1.0"
edition = "2021"

[lib]
proc-macro = true

[dependencies]
proc-quote = "0.4.0"
proc-macro2 = "1.0.43"
syn = "1.0.99"
39 changes: 39 additions & 0 deletions lib/api/macro-wasmer-universal-test/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
extern crate proc_macro;
use proc_macro::TokenStream;
use syn::{parse_macro_input, Result};
use syn::parse::{Parse, ParseStream};
use proc_macro2::{Ident, Span};

struct MyMacroInput {
function_name: String
}

impl Parse for MyMacroInput {
fn parse(input: ParseStream) -> Result<Self> {
Ok(MyMacroInput { function_name: format!("hello") })
}
}

#[proc_macro_attribute]
pub fn universal_test(_: TokenStream, item: TokenStream) -> TokenStream {

let item_clone = item.clone();
let input = parse_macro_input!(item_clone as MyMacroInput);
let function_name_normal = Ident::new(&input.function_name, Span::call_site());
let function_name_js = Ident::new(&format!("{}_js", input.function_name), Span::call_site());
let item = proc_macro2::TokenStream::from(item);

let tokens = proc_quote::quote! {
#[cfg(feature = "js")]
#[cfg_attr(feature = "js", wasm_bindgen_test)]
fn #function_name_js() {
let e: Result<()> = #function_name_normal();
e.unwrap();
}

#[cfg_attr(feature = "sys", test)]
#item
};

proc_macro::TokenStream::from(tokens)
}
10 changes: 2 additions & 8 deletions lib/api/tests/reference_types.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use anyhow::Result;
#[cfg(feature = "js")]
use wasm_bindgen_test::*;

use macro_wasmer_universal_test::universal_test;
use wasmer::*;
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::Arc;
@@ -144,13 +144,7 @@ fn func_ref_passed_and_called() -> Result<()> {
}


#[cfg(feature = "js")]
#[cfg_attr(feature = "js", wasm_bindgen_test)]
fn extern_ref_passed_and_returned_js() {
extern_ref_passed_and_returned().unwrap();
}

#[cfg_attr(feature = "sys", test)]
#[macro_wasmer_universal_test::universal_test]
fn extern_ref_passed_and_returned() -> Result<()> {
use std::collections::HashMap;
let mut store = Store::default();