From 1a28c50223668856c26e152955c516457d46960e Mon Sep 17 00:00:00 2001 From: Sean Cribbs Date: Sun, 21 Jan 2024 15:55:22 -0600 Subject: [PATCH] Add test for cfg attributes --- tests/wasm/attributes.js | 9 +++++++++ tests/wasm/attributes.rs | 36 ++++++++++++++++++++++++++++++++++++ tests/wasm/main.rs | 1 + 3 files changed, 46 insertions(+) create mode 100644 tests/wasm/attributes.js create mode 100644 tests/wasm/attributes.rs diff --git a/tests/wasm/attributes.js b/tests/wasm/attributes.js new file mode 100644 index 00000000000..39a1dd01988 --- /dev/null +++ b/tests/wasm/attributes.js @@ -0,0 +1,9 @@ +const wasm = require("wasm-bindgen-test.js"); +const assert = require("assert"); + +exports.js_works = () => { + assert.strictEqual(wasm.valid_export(), true); + assert.strictEqual(wasm.invalid_export, undefined); + assert.strictEqual(wasm.valid_attr_export(), true); + assert.strictEqual(wasm.invalid_attr_export, undefined); +}; diff --git a/tests/wasm/attributes.rs b/tests/wasm/attributes.rs new file mode 100644 index 00000000000..bfc695c04d5 --- /dev/null +++ b/tests/wasm/attributes.rs @@ -0,0 +1,36 @@ +use wasm_bindgen::prelude::*; +use wasm_bindgen_test::*; + +#[wasm_bindgen(module = "tests/wasm/attributes.js")] +extern "C" { + fn js_works(); +} + +#[wasm_bindgen_test] +fn works() { + js_works(); +} + +#[wasm_bindgen] +#[cfg(target_arch = "wasm32")] +pub fn valid_export() -> bool { + true +} + +#[wasm_bindgen] +#[cfg(not(target_arch = "wasm32"))] +pub fn invalid_export() -> bool { + false +} + +#[wasm_bindgen] +#[cfg_attr(not(target_arch = "wasm32"), cfg(feature = "missing-feature"))] +pub fn valid_attr_export() -> bool { + true +} + +#[wasm_bindgen] +#[cfg_attr(target_arch = "wasm32", cfg(feature = "missing-feature"))] +pub fn invalid_attr_export() -> bool { + false +} diff --git a/tests/wasm/main.rs b/tests/wasm/main.rs index 72bb5c414f4..22ed2dfd48f 100644 --- a/tests/wasm/main.rs +++ b/tests/wasm/main.rs @@ -16,6 +16,7 @@ use wasm_bindgen::prelude::*; pub mod api; pub mod arg_names; +pub mod attributes; pub mod bigint; pub mod char; pub mod classes;