Skip to content

Commit be439d1

Browse files
committed
Fix tests for custom wasm RNGs
1 parent 592dd33 commit be439d1

File tree

3 files changed

+32
-4
lines changed

3 files changed

+32
-4
lines changed

custom/stdweb/Cargo.toml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,12 @@ categories = ["wasm"]
1313
getrandom = { path = "../..", features = ["custom"] }
1414
stdweb = "0.4.18"
1515
log = "0.4"
16+
17+
# Unstable features used to build tests correctly
18+
[features]
19+
default = ["test-stdweb"]
20+
test-stdweb = []
21+
22+
[[test]]
23+
name = "common"
24+
path = "../../tests/common.rs"

custom/wasm-bindgen/Cargo.toml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,16 @@ categories = ["wasm"]
1212
[dependencies]
1313
getrandom = { path = "../..", features = ["custom"] }
1414
wasm-bindgen = "0.2.29"
15+
16+
[dev-dependencies]
17+
wasm-bindgen-test = "0.2"
18+
19+
# Unstable features used to build tests correctly
20+
[features]
21+
default = ["test-bindgen"]
22+
test-bindgen = []
23+
test-in-browser = ["test-bindgen"]
24+
25+
[[test]]
26+
name = "common"
27+
path = "../../tests/common.rs"

tests/common.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,25 @@
1-
#[cfg(feature = "wasm-bindgen")]
1+
// Explictly use the Custom RNG crates to link them in.
2+
#[cfg(feature = "test-stdweb")]
3+
use getrandom_stdweb as _;
4+
#[cfg(feature = "test-bindgen")]
5+
use getrandom_wasm_bindgen as _;
6+
7+
#[cfg(feature = "test-bindgen")]
28
use wasm_bindgen_test::*;
39

410
use getrandom::getrandom;
511

612
#[cfg(feature = "test-in-browser")]
713
wasm_bindgen_test_configure!(run_in_browser);
814

9-
#[cfg_attr(feature = "wasm-bindgen", wasm_bindgen_test)]
15+
#[cfg_attr(feature = "test-bindgen", wasm_bindgen_test)]
1016
#[test]
1117
fn test_zero() {
1218
// Test that APIs are happy with zero-length requests
1319
getrandom(&mut [0u8; 0]).unwrap();
1420
}
1521

16-
#[cfg_attr(feature = "wasm-bindgen", wasm_bindgen_test)]
22+
#[cfg_attr(feature = "test-bindgen", wasm_bindgen_test)]
1723
#[test]
1824
fn test_diff() {
1925
let mut v1 = [0u8; 1000];
@@ -31,7 +37,7 @@ fn test_diff() {
3137
assert!(n_diff_bits >= v1.len() as u32);
3238
}
3339

34-
#[cfg_attr(feature = "wasm-bindgen", wasm_bindgen_test)]
40+
#[cfg_attr(feature = "test-bindgen", wasm_bindgen_test)]
3541
#[test]
3642
fn test_huge() {
3743
let mut huge = [0u8; 100_000];

0 commit comments

Comments
 (0)