Skip to content

Commit 48f43d3

Browse files
committed
Fix tests for custom wasm RNGs
1 parent 272f44a commit 48f43d3

File tree

3 files changed

+32
-4
lines changed

3 files changed

+32
-4
lines changed

custom/stdweb/Cargo.toml

+9
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,12 @@ crate-type = ["dylib"]
1616
getrandom = { path = "../..", features = ["custom"] }
1717
stdweb = "0.4.18"
1818
log = "0.4"
19+
20+
# Unstable features used to build tests correctly
21+
[features]
22+
default = ["test-stdweb"]
23+
test-stdweb = []
24+
25+
[[test]]
26+
name = "common"
27+
path = "../../tests/common.rs"

custom/wasm-bindgen/Cargo.toml

+13
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,16 @@ crate-type = ["dylib"]
1515
[dependencies]
1616
getrandom = { path = "../..", features = ["custom"] }
1717
wasm-bindgen = "0.2.29"
18+
19+
[dev-dependencies]
20+
wasm-bindgen-test = "0.2"
21+
22+
# Unstable features used to build tests correctly
23+
[features]
24+
default = ["test-bindgen"]
25+
test-bindgen = []
26+
test-in-browser = ["test-bindgen"]
27+
28+
[[test]]
29+
name = "common"
30+
path = "../../tests/common.rs"

tests/common.rs

+10-4
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,25 @@
1-
#[cfg(feature = "wasm-bindgen")]
1+
// Extern crate declarations needed to prevent linking issues
2+
#[cfg(feature = "test-stdweb")]
3+
extern crate getrandom_stdweb;
4+
#[cfg(feature = "test-bindgen")]
5+
extern crate getrandom_wasm_bindgen;
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)