Move unused_imports_not_generated test to wasm

This commit is contained in:
Alex Crichton 2018-08-06 11:28:08 -07:00
parent 0fbdc7682c
commit 7f8d510f3d
3 changed files with 15 additions and 36 deletions

View File

@ -1,41 +1,5 @@
use super::project;
#[test]
fn unused_imports_not_generated() {
let mut project = project();
project
.debug(false)
.file("src/lib.rs", r#"
#![feature(use_extern_macros)]
extern crate wasm_bindgen;
use wasm_bindgen::prelude::*;
#[wasm_bindgen]
extern {
pub fn foo();
}
#[wasm_bindgen]
pub fn run() {
}
"#)
.file("test.js", r#"
import { run } from "./out";
export function test() {
run();
}
"#)
.test();
let contents = project.read_js();
assert!(contents.contains("run"), "didn't find `run` in {}", contents);
assert!(!contents.contains("foo"), "found `foo` in {}", contents);
}
#[test]
fn versions() {
project()

View File

@ -1,5 +1,6 @@
const assert = require('assert');
const wasm = require('wasm-bindgen-test');
const fs = require('fs');
let ARG = null;
let ANOTHER_ARG = null;
@ -93,3 +94,9 @@ exports.interpret_2_as_custom_type = function() {
exports.baz$ = function() {};
exports.$foo = 1.0;
exports.assert_dead_import_not_generated = function() {
const filename = require.resolve("wasm-bindgen-test");
const bindings = fs.readFileSync(filename);
assert.ok(!bindings.includes("unused_import"));
};

View File

@ -47,6 +47,9 @@ extern {
fn renamed_with_dollar_sign();
#[wasm_bindgen(js_name = "$foo")]
static RENAMED: JsValue;
fn unused_import();
fn assert_dead_import_not_generated();
}
#[wasm_bindgen]
@ -168,3 +171,8 @@ fn rename_with_string() {
fn rename_static_with_string() {
assert_eq!(RENAMED.as_f64(), Some(1.0));
}
#[wasm_bindgen_test]
fn dead_imports_not_generated() {
assert_dead_import_not_generated();
}