about summary refs log tree commit diff
diff options
context:
space:
mode:
authorCaleb Zulawski <caleb.zulawski@gmail.com>2021-02-13 11:40:10 -0500
committerCaleb Zulawski <caleb.zulawski@gmail.com>2021-02-15 18:22:56 -0500
commit976fafcf4fb8008255ce57bc62738a46f8a9152f (patch)
treeed8e609f4ff7fd3ae26a333bee8cf8e78509c502
parent8d5702e437e051333dcf1005fcce140c5c96f759 (diff)
downloadrust-976fafcf4fb8008255ce57bc62738a46f8a9152f.tar.gz
rust-976fafcf4fb8008255ce57bc62738a46f8a9152f.zip
Fix wasm tests
-rw-r--r--crates/core_simd/src/macros.rs2
-rw-r--r--crates/core_simd/tests/float.rs3
-rw-r--r--crates/core_simd/tests/integer.rs3
-rw-r--r--crates/test_helpers/Cargo.toml6
-rw-r--r--crates/test_helpers/src/array.rs2
-rw-r--r--crates/test_helpers/src/lib.rs54
-rw-r--r--crates/test_helpers/src/wasm.rs49
7 files changed, 100 insertions, 19 deletions
diff --git a/crates/core_simd/src/macros.rs b/crates/core_simd/src/macros.rs
index 3e428379b74..75104dc50e4 100644
--- a/crates/core_simd/src/macros.rs
+++ b/crates/core_simd/src/macros.rs
@@ -143,7 +143,7 @@ macro_rules! impl_vector {
 
         impl <const LANES: usize> From<$name<LANES>> for [$type; LANES] {
             fn from(vector: $name<LANES>) -> Self {
-                vector.0
+                vector.to_array()
             }
         }
 
diff --git a/crates/core_simd/tests/float.rs b/crates/core_simd/tests/float.rs
index 03d132ae046..618a75250bd 100644
--- a/crates/core_simd/tests/float.rs
+++ b/crates/core_simd/tests/float.rs
@@ -1,6 +1,3 @@
-#[cfg(target_arch = "wasm32")]
-wasm_bindgen_test_configure!(run_in_browser);
-
 macro_rules! impl_op_test {
     { unary, $vector:ty, $scalar:ty, $trait:ident :: $fn:ident } => {
         test_helpers::test_lanes! {
diff --git a/crates/core_simd/tests/integer.rs b/crates/core_simd/tests/integer.rs
index 878b3f0329a..33612628356 100644
--- a/crates/core_simd/tests/integer.rs
+++ b/crates/core_simd/tests/integer.rs
@@ -1,6 +1,3 @@
-#[cfg(target_arch = "wasm32")]
-wasm_bindgen_test_configure!(run_in_browser);
-
 macro_rules! impl_unary_op_test {
     { $vector:ty, $scalar:ty, $trait:ident :: $fn:ident, $scalar_fn:expr } => {
         test_helpers::test_lanes! {
diff --git a/crates/test_helpers/Cargo.toml b/crates/test_helpers/Cargo.toml
index 0a8c3344334..c9f6397b23b 100644
--- a/crates/test_helpers/Cargo.toml
+++ b/crates/test_helpers/Cargo.toml
@@ -5,5 +5,7 @@ authors = ["Caleb Zulawski <caleb.zulawski@gmail.com>"]
 edition = "2018"
 publish = false
 
-[dependencies]
-proptest = "0.10"
+[dependencies.proptest]
+version = "0.10"
+default-features = false
+features = ["alloc"]
diff --git a/crates/test_helpers/src/array.rs b/crates/test_helpers/src/array.rs
index d9cae96ca2f..3953d0bbea5 100644
--- a/crates/test_helpers/src/array.rs
+++ b/crates/test_helpers/src/array.rs
@@ -18,7 +18,7 @@ pub struct UniformArrayStrategy<S, T> {
 }
 
 impl<S, T> UniformArrayStrategy<S, T> {
-    pub fn new(strategy: S) -> Self {
+    pub const fn new(strategy: S) -> Self {
         Self {
             strategy,
             _marker: PhantomData,
diff --git a/crates/test_helpers/src/lib.rs b/crates/test_helpers/src/lib.rs
index 134b4073a4e..e1832bf6377 100644
--- a/crates/test_helpers/src/lib.rs
+++ b/crates/test_helpers/src/lib.rs
@@ -1,5 +1,8 @@
 pub mod array;
 
+#[cfg(target_arch = "wasm32")]
+pub mod wasm;
+
 #[macro_use]
 pub mod biteq;
 
@@ -23,17 +26,47 @@ impl_num! { i8 }
 impl_num! { i16 }
 impl_num! { i32 }
 impl_num! { i64 }
-impl_num! { i128 }
 impl_num! { isize }
 impl_num! { u8 }
 impl_num! { u16 }
 impl_num! { u32 }
 impl_num! { u64 }
-impl_num! { u128 }
 impl_num! { usize }
 impl_num! { f32 }
 impl_num! { f64 }
 
+#[cfg(not(target_arch = "wasm32"))]
+impl DefaultStrategy for u128 {
+    type Strategy = proptest::num::u128::Any;
+    fn default_strategy() -> Self::Strategy {
+        proptest::num::u128::ANY
+    }
+}
+
+#[cfg(not(target_arch = "wasm32"))]
+impl DefaultStrategy for i128 {
+    type Strategy = proptest::num::i128::Any;
+    fn default_strategy() -> Self::Strategy {
+        proptest::num::i128::ANY
+    }
+}
+
+#[cfg(target_arch = "wasm32")]
+impl DefaultStrategy for u128 {
+    type Strategy = crate::wasm::u128::Any;
+    fn default_strategy() -> Self::Strategy {
+        crate::wasm::u128::ANY
+    }
+}
+
+#[cfg(target_arch = "wasm32")]
+impl DefaultStrategy for i128 {
+    type Strategy = crate::wasm::i128::Any;
+    fn default_strategy() -> Self::Strategy {
+        crate::wasm::i128::ANY
+    }
+}
+
 impl<T: core::fmt::Debug + DefaultStrategy, const LANES: usize> DefaultStrategy for [T; LANES] {
     type Strategy = crate::array::UniformArrayStrategy<T::Strategy, Self>;
     fn default_strategy() -> Self::Strategy {
@@ -200,44 +233,47 @@ macro_rules! test_lanes {
 
                 fn implementation<const $lanes: usize>() $body
 
+                #[cfg(target_arch = "wasm32")]
+                wasm_bindgen_test::wasm_bindgen_test_configure!(run_in_browser);
+
                 #[test]
-                #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
+                #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)]
                 fn lanes_1() {
                     implementation::<1>();
                 }
 
                 #[test]
-                #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
+                #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)]
                 fn lanes_2() {
                     implementation::<2>();
                 }
 
                 #[test]
-                #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
+                #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)]
                 fn lanes_4() {
                     implementation::<4>();
                 }
 
                 #[test]
-                #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
+                #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)]
                 fn lanes_8() {
                     implementation::<8>();
                 }
 
                 #[test]
-                #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
+                #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)]
                 fn lanes_16() {
                     implementation::<16>();
                 }
 
                 #[test]
-                #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
+                #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)]
                 fn lanes_32() {
                     implementation::<32>();
                 }
 
                 #[test]
-                #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
+                #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)]
                 fn lanes_64() {
                     implementation::<64>();
                 }
diff --git a/crates/test_helpers/src/wasm.rs b/crates/test_helpers/src/wasm.rs
new file mode 100644
index 00000000000..02cb9264d7c
--- /dev/null
+++ b/crates/test_helpers/src/wasm.rs
@@ -0,0 +1,49 @@
+macro_rules! impl_num {
+    { $name:ident } => {
+        pub(crate) mod $name {
+            type InnerStrategy = crate::array::UniformArrayStrategy<proptest::num::u64::Any, [u64; 2]>;
+            use proptest::strategy::{Strategy, ValueTree, NewTree};
+
+
+            #[must_use = "strategies do nothing unless used"]
+            #[derive(Clone, Copy, Debug)]
+            pub struct Any {
+                strategy: InnerStrategy,
+            }
+
+            pub struct BinarySearch {
+                inner: <InnerStrategy as Strategy>::Tree,
+            }
+
+            impl ValueTree for BinarySearch {
+                type Value = $name;
+
+                fn current(&self) -> $name {
+                    unsafe { core::mem::transmute(self.inner.current()) }
+                }
+
+                fn simplify(&mut self) -> bool {
+                    self.inner.simplify()
+                }
+
+                fn complicate(&mut self) -> bool {
+                    self.inner.complicate()
+                }
+            }
+
+            impl Strategy for Any {
+                type Tree = BinarySearch;
+                type Value = $name;
+
+                fn new_tree(&self, runner: &mut proptest::test_runner::TestRunner) -> NewTree<Self> {
+                    Ok(BinarySearch { inner: self.strategy.new_tree(runner)? })
+                }
+            }
+
+            pub const ANY: Any = Any { strategy: InnerStrategy::new(proptest::num::u64::ANY) };
+        }
+    }
+}
+
+impl_num! { u128 }
+impl_num! { i128 }