Skip to content

Commit 976fafc

Browse files
committed
Fix wasm tests
1 parent 8d5702e commit 976fafc

File tree

7 files changed

+100
-19
lines changed

7 files changed

+100
-19
lines changed

crates/core_simd/src/macros.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ macro_rules! impl_vector {
143143

144144
impl <const LANES: usize> From<$name<LANES>> for [$type; LANES] {
145145
fn from(vector: $name<LANES>) -> Self {
146-
vector.0
146+
vector.to_array()
147147
}
148148
}
149149

crates/core_simd/tests/float.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
#[cfg(target_arch = "wasm32")]
2-
wasm_bindgen_test_configure!(run_in_browser);
3-
41
macro_rules! impl_op_test {
52
{ unary, $vector:ty, $scalar:ty, $trait:ident :: $fn:ident } => {
63
test_helpers::test_lanes! {

crates/core_simd/tests/integer.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
#[cfg(target_arch = "wasm32")]
2-
wasm_bindgen_test_configure!(run_in_browser);
3-
41
macro_rules! impl_unary_op_test {
52
{ $vector:ty, $scalar:ty, $trait:ident :: $fn:ident, $scalar_fn:expr } => {
63
test_helpers::test_lanes! {

crates/test_helpers/Cargo.toml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,7 @@ authors = ["Caleb Zulawski <[email protected]>"]
55
edition = "2018"
66
publish = false
77

8-
[dependencies]
9-
proptest = "0.10"
8+
[dependencies.proptest]
9+
version = "0.10"
10+
default-features = false
11+
features = ["alloc"]

crates/test_helpers/src/array.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ pub struct UniformArrayStrategy<S, T> {
1818
}
1919

2020
impl<S, T> UniformArrayStrategy<S, T> {
21-
pub fn new(strategy: S) -> Self {
21+
pub const fn new(strategy: S) -> Self {
2222
Self {
2323
strategy,
2424
_marker: PhantomData,

crates/test_helpers/src/lib.rs

Lines changed: 45 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
pub mod array;
22

3+
#[cfg(target_arch = "wasm32")]
4+
pub mod wasm;
5+
36
#[macro_use]
47
pub mod biteq;
58

@@ -23,17 +26,47 @@ impl_num! { i8 }
2326
impl_num! { i16 }
2427
impl_num! { i32 }
2528
impl_num! { i64 }
26-
impl_num! { i128 }
2729
impl_num! { isize }
2830
impl_num! { u8 }
2931
impl_num! { u16 }
3032
impl_num! { u32 }
3133
impl_num! { u64 }
32-
impl_num! { u128 }
3334
impl_num! { usize }
3435
impl_num! { f32 }
3536
impl_num! { f64 }
3637

38+
#[cfg(not(target_arch = "wasm32"))]
39+
impl DefaultStrategy for u128 {
40+
type Strategy = proptest::num::u128::Any;
41+
fn default_strategy() -> Self::Strategy {
42+
proptest::num::u128::ANY
43+
}
44+
}
45+
46+
#[cfg(not(target_arch = "wasm32"))]
47+
impl DefaultStrategy for i128 {
48+
type Strategy = proptest::num::i128::Any;
49+
fn default_strategy() -> Self::Strategy {
50+
proptest::num::i128::ANY
51+
}
52+
}
53+
54+
#[cfg(target_arch = "wasm32")]
55+
impl DefaultStrategy for u128 {
56+
type Strategy = crate::wasm::u128::Any;
57+
fn default_strategy() -> Self::Strategy {
58+
crate::wasm::u128::ANY
59+
}
60+
}
61+
62+
#[cfg(target_arch = "wasm32")]
63+
impl DefaultStrategy for i128 {
64+
type Strategy = crate::wasm::i128::Any;
65+
fn default_strategy() -> Self::Strategy {
66+
crate::wasm::i128::ANY
67+
}
68+
}
69+
3770
impl<T: core::fmt::Debug + DefaultStrategy, const LANES: usize> DefaultStrategy for [T; LANES] {
3871
type Strategy = crate::array::UniformArrayStrategy<T::Strategy, Self>;
3972
fn default_strategy() -> Self::Strategy {
@@ -200,44 +233,47 @@ macro_rules! test_lanes {
200233

201234
fn implementation<const $lanes: usize>() $body
202235

236+
#[cfg(target_arch = "wasm32")]
237+
wasm_bindgen_test::wasm_bindgen_test_configure!(run_in_browser);
238+
203239
#[test]
204-
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
240+
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)]
205241
fn lanes_1() {
206242
implementation::<1>();
207243
}
208244

209245
#[test]
210-
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
246+
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)]
211247
fn lanes_2() {
212248
implementation::<2>();
213249
}
214250

215251
#[test]
216-
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
252+
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)]
217253
fn lanes_4() {
218254
implementation::<4>();
219255
}
220256

221257
#[test]
222-
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
258+
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)]
223259
fn lanes_8() {
224260
implementation::<8>();
225261
}
226262

227263
#[test]
228-
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
264+
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)]
229265
fn lanes_16() {
230266
implementation::<16>();
231267
}
232268

233269
#[test]
234-
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
270+
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)]
235271
fn lanes_32() {
236272
implementation::<32>();
237273
}
238274

239275
#[test]
240-
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
276+
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)]
241277
fn lanes_64() {
242278
implementation::<64>();
243279
}

crates/test_helpers/src/wasm.rs

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
macro_rules! impl_num {
2+
{ $name:ident } => {
3+
pub(crate) mod $name {
4+
type InnerStrategy = crate::array::UniformArrayStrategy<proptest::num::u64::Any, [u64; 2]>;
5+
use proptest::strategy::{Strategy, ValueTree, NewTree};
6+
7+
8+
#[must_use = "strategies do nothing unless used"]
9+
#[derive(Clone, Copy, Debug)]
10+
pub struct Any {
11+
strategy: InnerStrategy,
12+
}
13+
14+
pub struct BinarySearch {
15+
inner: <InnerStrategy as Strategy>::Tree,
16+
}
17+
18+
impl ValueTree for BinarySearch {
19+
type Value = $name;
20+
21+
fn current(&self) -> $name {
22+
unsafe { core::mem::transmute(self.inner.current()) }
23+
}
24+
25+
fn simplify(&mut self) -> bool {
26+
self.inner.simplify()
27+
}
28+
29+
fn complicate(&mut self) -> bool {
30+
self.inner.complicate()
31+
}
32+
}
33+
34+
impl Strategy for Any {
35+
type Tree = BinarySearch;
36+
type Value = $name;
37+
38+
fn new_tree(&self, runner: &mut proptest::test_runner::TestRunner) -> NewTree<Self> {
39+
Ok(BinarySearch { inner: self.strategy.new_tree(runner)? })
40+
}
41+
}
42+
43+
pub const ANY: Any = Any { strategy: InnerStrategy::new(proptest::num::u64::ANY) };
44+
}
45+
}
46+
}
47+
48+
impl_num! { u128 }
49+
impl_num! { i128 }

0 commit comments

Comments
 (0)