Skip to content

Commit 7f8d510

Browse files
committed
Move unused_imports_not_generated test to wasm
1 parent 0fbdc76 commit 7f8d510

File tree

3 files changed

+15
-36
lines changed

3 files changed

+15
-36
lines changed

tests/all/imports.rs

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,5 @@
11
use super::project;
22

3-
#[test]
4-
fn unused_imports_not_generated() {
5-
let mut project = project();
6-
7-
project
8-
.debug(false)
9-
.file("src/lib.rs", r#"
10-
#![feature(use_extern_macros)]
11-
12-
extern crate wasm_bindgen;
13-
14-
use wasm_bindgen::prelude::*;
15-
16-
#[wasm_bindgen]
17-
extern {
18-
pub fn foo();
19-
}
20-
21-
#[wasm_bindgen]
22-
pub fn run() {
23-
}
24-
"#)
25-
.file("test.js", r#"
26-
import { run } from "./out";
27-
28-
export function test() {
29-
run();
30-
}
31-
"#)
32-
.test();
33-
34-
let contents = project.read_js();
35-
assert!(contents.contains("run"), "didn't find `run` in {}", contents);
36-
assert!(!contents.contains("foo"), "found `foo` in {}", contents);
37-
}
38-
393
#[test]
404
fn versions() {
415
project()

tests/wasm/imports.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
const assert = require('assert');
22
const wasm = require('wasm-bindgen-test');
3+
const fs = require('fs');
34

45
let ARG = null;
56
let ANOTHER_ARG = null;
@@ -93,3 +94,9 @@ exports.interpret_2_as_custom_type = function() {
9394

9495
exports.baz$ = function() {};
9596
exports.$foo = 1.0;
97+
98+
exports.assert_dead_import_not_generated = function() {
99+
const filename = require.resolve("wasm-bindgen-test");
100+
const bindings = fs.readFileSync(filename);
101+
assert.ok(!bindings.includes("unused_import"));
102+
};

tests/wasm/imports.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ extern {
4747
fn renamed_with_dollar_sign();
4848
#[wasm_bindgen(js_name = "$foo")]
4949
static RENAMED: JsValue;
50+
51+
fn unused_import();
52+
fn assert_dead_import_not_generated();
5053
}
5154

5255
#[wasm_bindgen]
@@ -168,3 +171,8 @@ fn rename_with_string() {
168171
fn rename_static_with_string() {
169172
assert_eq!(RENAMED.as_f64(), Some(1.0));
170173
}
174+
175+
#[wasm_bindgen_test]
176+
fn dead_imports_not_generated() {
177+
assert_dead_import_not_generated();
178+
}

0 commit comments

Comments
 (0)