mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-04-21 20:22:14 +00:00
Migrate #![no_std]
tests to wasm
This required getting a little creative in a few places, but otherwise these tests shouldn't need the test builder any more.
This commit is contained in:
parent
005f7eb9fa
commit
0a2399a7f1
@ -54,6 +54,7 @@ matrix:
|
|||||||
- cargo test --target wasm32-unknown-unknown
|
- cargo test --target wasm32-unknown-unknown
|
||||||
- WASM_BINDGEN_NO_DEBUG=1 cargo test --target wasm32-unknown-unknown
|
- WASM_BINDGEN_NO_DEBUG=1 cargo test --target wasm32-unknown-unknown
|
||||||
- cargo test --target wasm32-unknown-unknown --features serde-serialize
|
- cargo test --target wasm32-unknown-unknown --features serde-serialize
|
||||||
|
- cargo test --target wasm32-unknown-unknown -p no-std
|
||||||
# Check JS output from all tests against eslint
|
# Check JS output from all tests against eslint
|
||||||
- npm run run-lint-generated-tests
|
- npm run run-lint-generated-tests
|
||||||
# Check Examples against eslint
|
# Check Examples against eslint
|
||||||
|
@ -66,6 +66,7 @@ members = [
|
|||||||
"examples/performance",
|
"examples/performance",
|
||||||
"examples/smorgasboard",
|
"examples/smorgasboard",
|
||||||
"examples/wasm-in-wasm",
|
"examples/wasm-in-wasm",
|
||||||
|
"tests/no-std",
|
||||||
]
|
]
|
||||||
|
|
||||||
[patch.crates-io]
|
[patch.crates-io]
|
||||||
|
@ -7,5 +7,4 @@ use project_builder::project;
|
|||||||
mod comments;
|
mod comments;
|
||||||
mod js_objects;
|
mod js_objects;
|
||||||
mod imports;
|
mod imports;
|
||||||
mod simple;
|
|
||||||
mod typescript;
|
mod typescript;
|
||||||
|
@ -1,109 +0,0 @@
|
|||||||
use super::project;
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn no_std() {
|
|
||||||
project()
|
|
||||||
.no_std(true)
|
|
||||||
.file(
|
|
||||||
"src/lib.rs",
|
|
||||||
r#"
|
|
||||||
#![feature(use_extern_macros)]
|
|
||||||
#![no_std]
|
|
||||||
#![allow(dead_code)]
|
|
||||||
|
|
||||||
extern crate wasm_bindgen;
|
|
||||||
extern crate std as _some_other_name;
|
|
||||||
|
|
||||||
use wasm_bindgen::prelude::*;
|
|
||||||
|
|
||||||
#[wasm_bindgen(module = "./foo")]
|
|
||||||
extern {
|
|
||||||
fn test(a: &str);
|
|
||||||
|
|
||||||
type Js;
|
|
||||||
#[wasm_bindgen(constructor)]
|
|
||||||
fn new() -> Js;
|
|
||||||
#[wasm_bindgen(method)]
|
|
||||||
fn init(this: &Js);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[wasm_bindgen]
|
|
||||||
pub fn foo(_a: u32) {}
|
|
||||||
"#,
|
|
||||||
)
|
|
||||||
.file(
|
|
||||||
"test.js",
|
|
||||||
r#"
|
|
||||||
import * as wasm from "./out_bg";
|
|
||||||
|
|
||||||
export function test() {
|
|
||||||
// mostly just testing the project compiles here
|
|
||||||
wasm.foo(1);
|
|
||||||
}
|
|
||||||
"#,
|
|
||||||
)
|
|
||||||
.file(
|
|
||||||
"foo.js",
|
|
||||||
r#"
|
|
||||||
export class Js {
|
|
||||||
init() {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
"#,
|
|
||||||
)
|
|
||||||
.test();
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn no_std_class() {
|
|
||||||
project()
|
|
||||||
.file(
|
|
||||||
"src/lib.rs",
|
|
||||||
r#"
|
|
||||||
#![feature(use_extern_macros)]
|
|
||||||
#![no_std]
|
|
||||||
#![allow(dead_code)]
|
|
||||||
|
|
||||||
extern crate wasm_bindgen;
|
|
||||||
extern crate std as _some_other_name;
|
|
||||||
|
|
||||||
use wasm_bindgen::prelude::*;
|
|
||||||
|
|
||||||
#[wasm_bindgen]
|
|
||||||
extern {
|
|
||||||
fn test(a: &str);
|
|
||||||
|
|
||||||
type Js;
|
|
||||||
#[wasm_bindgen(constructor)]
|
|
||||||
fn new() -> Js;
|
|
||||||
#[wasm_bindgen(method, structural)]
|
|
||||||
fn init(this: &Js);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[wasm_bindgen]
|
|
||||||
pub fn foo(_a: u32) {}
|
|
||||||
|
|
||||||
#[wasm_bindgen]
|
|
||||||
pub struct A {}
|
|
||||||
|
|
||||||
#[wasm_bindgen]
|
|
||||||
impl A {
|
|
||||||
pub fn foo(&self) {}
|
|
||||||
pub fn bar(&mut self) {}
|
|
||||||
}
|
|
||||||
"#,
|
|
||||||
)
|
|
||||||
.file(
|
|
||||||
"test.js",
|
|
||||||
r#"
|
|
||||||
import * as wasm from "./out_bg";
|
|
||||||
|
|
||||||
export function test() {
|
|
||||||
// mostly just testing the project compiles here
|
|
||||||
wasm.foo(1);
|
|
||||||
}
|
|
||||||
"#,
|
|
||||||
)
|
|
||||||
.test();
|
|
||||||
}
|
|
||||||
|
|
10
tests/no-std/Cargo.toml
Normal file
10
tests/no-std/Cargo.toml
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
[package]
|
||||||
|
name = "no-std"
|
||||||
|
version = "0.1.0"
|
||||||
|
authors = ["The wasm-bindgen Developers"]
|
||||||
|
|
||||||
|
[lib]
|
||||||
|
path = "test.rs"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
wasm-bindgen = { path = '../..', default-features = false }
|
0
tests/no-std/lib.rs
Normal file
0
tests/no-std/lib.rs
Normal file
28
tests/no-std/test.rs
Normal file
28
tests/no-std/test.rs
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
//! This is a test that we compile `wasm-bindgen` itself in `no_std` mode and we
|
||||||
|
//! can export/import various items.
|
||||||
|
//!
|
||||||
|
//! This doesn't actually run any tests, it's mostly a compile-time verification
|
||||||
|
//! that things work.
|
||||||
|
|
||||||
|
#![feature(use_extern_macros)]
|
||||||
|
#![no_std]
|
||||||
|
#![allow(dead_code)]
|
||||||
|
|
||||||
|
extern crate wasm_bindgen;
|
||||||
|
extern crate std as _some_other_name;
|
||||||
|
|
||||||
|
use wasm_bindgen::prelude::*;
|
||||||
|
|
||||||
|
#[wasm_bindgen]
|
||||||
|
pub fn foo(_a: u32) {}
|
||||||
|
|
||||||
|
#[wasm_bindgen]
|
||||||
|
extern {
|
||||||
|
fn test(a: &str);
|
||||||
|
|
||||||
|
type Js;
|
||||||
|
#[wasm_bindgen(constructor)]
|
||||||
|
fn new() -> Js;
|
||||||
|
#[wasm_bindgen(method, structural)]
|
||||||
|
fn init(this: &Js);
|
||||||
|
}
|
0
tests/std-crate-no-std-dep
Normal file
0
tests/std-crate-no-std-dep
Normal file
30
tests/std-crate-no-std-dep.rs
Normal file
30
tests/std-crate-no-std-dep.rs
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
//! This is a test that we can define items in a `#![no_std]` crate when
|
||||||
|
//! `wasm-bindgen` is compiled itself with the `std` feature and everything
|
||||||
|
//! works out just fine.
|
||||||
|
|
||||||
|
#![feature(use_extern_macros)]
|
||||||
|
#![no_std]
|
||||||
|
|
||||||
|
extern crate wasm_bindgen;
|
||||||
|
|
||||||
|
use wasm_bindgen::prelude::*;
|
||||||
|
|
||||||
|
#[wasm_bindgen]
|
||||||
|
extern {
|
||||||
|
fn test(a: &str);
|
||||||
|
|
||||||
|
type Js;
|
||||||
|
#[wasm_bindgen(constructor)]
|
||||||
|
fn new() -> Js;
|
||||||
|
#[wasm_bindgen(method, structural)]
|
||||||
|
fn init(this: &Js);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[wasm_bindgen]
|
||||||
|
pub struct A {}
|
||||||
|
|
||||||
|
#[wasm_bindgen]
|
||||||
|
impl A {
|
||||||
|
pub fn foo(&self) {}
|
||||||
|
pub fn bar(&mut self) {}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user