Skip to content

Commit 75a5b58

Browse files
committed
Fix tests for custom RNGs
1 parent 99eb3e3 commit 75a5b58

File tree

4 files changed

+29
-7
lines changed

4 files changed

+29
-7
lines changed

.travis.yml

+5-3
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,12 @@ matrix:
6868
# wasi tests
6969
- cargo test --target wasm32-wasi
7070
# stdweb tests (Node, Chrome)
71-
- cargo web test --nodejs --target=wasm32-unknown-unknown --features=stdweb
72-
- cargo web test --target=wasm32-unknown-unknown --features=stdweb
71+
- cd custom/stdweb
72+
- cargo web test --nodejs --target=wasm32-unknown-unknown
73+
- cargo web test --target=wasm32-unknown-unknown
7374
# wasm-bindgen tests (Node, Firefox, Chrome)
74-
- cargo test --target wasm32-unknown-unknown --features=wasm-bindgen
75+
- cd ../wasm-bindgen
76+
- cargo test --target wasm32-unknown-unknown
7577
- GECKODRIVER=$PWD/geckodriver cargo test --target wasm32-unknown-unknown --features=test-in-browser
7678
- CHROMEDRIVER=$PWD/chromedriver cargo test --target wasm32-unknown-unknown --features=test-in-browser
7779

custom/stdweb/Cargo.toml

+5
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ getrandom = { path = "../..", features = ["custom"] }
1414
stdweb = "0.4.18"
1515
log = "0.4"
1616

17+
# Unstable features used to build tests correctly
18+
[features]
19+
default = ["test-stdweb"]
20+
test-stdweb = []
21+
1722
[[test]]
1823
name = "common"
1924
path = "../../tests/common.rs"

custom/wasm-bindgen/Cargo.toml

+9
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,15 @@ categories = ["wasm"]
1313
getrandom = { path = "../..", features = ["custom"] }
1414
wasm-bindgen = "0.2.29"
1515

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+
1625
[[test]]
1726
name = "common"
1827
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)