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:
Alex Crichton 2018-08-06 11:08:35 -07:00
parent 005f7eb9fa
commit 0a2399a7f1
9 changed files with 70 additions and 110 deletions

View File

@ -54,6 +54,7 @@ matrix:
- 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 -p no-std
# Check JS output from all tests against eslint
- npm run run-lint-generated-tests
# Check Examples against eslint

View File

@ -66,6 +66,7 @@ members = [
"examples/performance",
"examples/smorgasboard",
"examples/wasm-in-wasm",
"tests/no-std",
]
[patch.crates-io]

View File

@ -7,5 +7,4 @@ use project_builder::project;
mod comments;
mod js_objects;
mod imports;
mod simple;
mod typescript;

View File

@ -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
View 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
View File

28
tests/no-std/test.rs Normal file
View 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);
}

View File

View 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) {}
}