mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-04-07 20:58:07 +00:00
Move non-wasm test to an actual non-wasm test
This commit is contained in:
parent
8513858973
commit
c83e498f52
@ -11,5 +11,4 @@ mod imports;
|
|||||||
mod simple;
|
mod simple;
|
||||||
mod node;
|
mod node;
|
||||||
mod non_debug;
|
mod non_debug;
|
||||||
mod non_wasm;
|
|
||||||
mod typescript;
|
mod typescript;
|
||||||
|
@ -1,101 +0,0 @@
|
|||||||
use super::{project, run};
|
|
||||||
use std::process::Command;
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn works() {
|
|
||||||
let mut p = project();
|
|
||||||
let name = p.crate_name();
|
|
||||||
p.rlib(true)
|
|
||||||
.file(
|
|
||||||
"src/lib.rs",
|
|
||||||
r#"
|
|
||||||
#![feature(use_extern_macros)]
|
|
||||||
|
|
||||||
extern crate wasm_bindgen;
|
|
||||||
|
|
||||||
use wasm_bindgen::prelude::*;
|
|
||||||
|
|
||||||
#[wasm_bindgen]
|
|
||||||
pub struct A {
|
|
||||||
x: u32,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[wasm_bindgen]
|
|
||||||
impl A {
|
|
||||||
pub fn new() -> A {
|
|
||||||
A { x: 3 }
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn foo(&self) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[wasm_bindgen]
|
|
||||||
pub fn foo(x: bool) {
|
|
||||||
A::new().foo();
|
|
||||||
|
|
||||||
if x {
|
|
||||||
bar("test");
|
|
||||||
baz(JsValue::from(3));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[wasm_bindgen]
|
|
||||||
extern {
|
|
||||||
fn some_import();
|
|
||||||
static A: JsValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
#[wasm_bindgen]
|
|
||||||
pub fn bar(_: &str) -> JsValue {
|
|
||||||
some_import();
|
|
||||||
A.clone()
|
|
||||||
}
|
|
||||||
|
|
||||||
#[wasm_bindgen]
|
|
||||||
pub fn baz(_: JsValue) {
|
|
||||||
}
|
|
||||||
"#,
|
|
||||||
)
|
|
||||||
.file(
|
|
||||||
"tests/foo.rs",
|
|
||||||
&format!(
|
|
||||||
"
|
|
||||||
extern crate {} as mytest;
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn foo() {{
|
|
||||||
mytest::foo(false);
|
|
||||||
mytest::A::new().foo();
|
|
||||||
}}
|
|
||||||
",
|
|
||||||
name
|
|
||||||
),
|
|
||||||
)
|
|
||||||
.file(
|
|
||||||
"benches/foo.rs",
|
|
||||||
&format!(
|
|
||||||
"
|
|
||||||
#![feature(test)]
|
|
||||||
extern crate test;
|
|
||||||
extern crate {} as mytest;
|
|
||||||
|
|
||||||
#[bench]
|
|
||||||
fn foo(b: &mut test::Bencher) {{
|
|
||||||
b.iter(|| mytest::foo(false));
|
|
||||||
}}
|
|
||||||
",
|
|
||||||
name
|
|
||||||
),
|
|
||||||
);
|
|
||||||
let (root, target_dir) = p.build();
|
|
||||||
let mut cmd = Command::new("cargo");
|
|
||||||
cmd.arg("test")
|
|
||||||
.arg("--test")
|
|
||||||
.arg("foo")
|
|
||||||
.arg("--bench")
|
|
||||||
.arg("foo")
|
|
||||||
.current_dir(&root)
|
|
||||||
.env("CARGO_TARGET_DIR", &target_dir);
|
|
||||||
run(&mut cmd, "cargo");
|
|
||||||
}
|
|
53
tests/non_wasm.rs
Normal file
53
tests/non_wasm.rs
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
#![feature(use_extern_macros)]
|
||||||
|
|
||||||
|
extern crate wasm_bindgen;
|
||||||
|
|
||||||
|
use wasm_bindgen::prelude::*;
|
||||||
|
|
||||||
|
#[wasm_bindgen]
|
||||||
|
pub struct A {
|
||||||
|
x: u32,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[wasm_bindgen]
|
||||||
|
impl A {
|
||||||
|
pub fn new() -> A {
|
||||||
|
A { x: 3 }
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn foo(&self) {
|
||||||
|
drop(self.x);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[wasm_bindgen]
|
||||||
|
pub fn foo(x: bool) {
|
||||||
|
A::new().foo();
|
||||||
|
|
||||||
|
if x {
|
||||||
|
bar("test");
|
||||||
|
baz(JsValue::from(3));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[wasm_bindgen]
|
||||||
|
extern {
|
||||||
|
fn some_import();
|
||||||
|
static A: JsValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
#[wasm_bindgen]
|
||||||
|
pub fn bar(_: &str) -> JsValue {
|
||||||
|
some_import();
|
||||||
|
A.clone()
|
||||||
|
}
|
||||||
|
|
||||||
|
#[wasm_bindgen]
|
||||||
|
pub fn baz(_: JsValue) {
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_foo() {
|
||||||
|
foo(false);
|
||||||
|
A::new().foo();
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user