Skip to content

Commit

Permalink
Fix tests for custom RNGs
Browse files Browse the repository at this point in the history
  • Loading branch information
josephlr committed Sep 20, 2019
1 parent 99eb3e3 commit 75a5b58
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 7 deletions.
8 changes: 5 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,12 @@ matrix:
# wasi tests
- cargo test --target wasm32-wasi
# stdweb tests (Node, Chrome)
- cargo web test --nodejs --target=wasm32-unknown-unknown --features=stdweb
- cargo web test --target=wasm32-unknown-unknown --features=stdweb
- cd custom/stdweb
- cargo web test --nodejs --target=wasm32-unknown-unknown
- cargo web test --target=wasm32-unknown-unknown
# wasm-bindgen tests (Node, Firefox, Chrome)
- cargo test --target wasm32-unknown-unknown --features=wasm-bindgen
- cd ../wasm-bindgen
- cargo test --target wasm32-unknown-unknown
- GECKODRIVER=$PWD/geckodriver cargo test --target wasm32-unknown-unknown --features=test-in-browser
- CHROMEDRIVER=$PWD/chromedriver cargo test --target wasm32-unknown-unknown --features=test-in-browser

Expand Down
5 changes: 5 additions & 0 deletions custom/stdweb/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ getrandom = { path = "../..", features = ["custom"] }
stdweb = "0.4.18"
log = "0.4"

# Unstable features used to build tests correctly
[features]
default = ["test-stdweb"]
test-stdweb = []

[[test]]
name = "common"
path = "../../tests/common.rs"
9 changes: 9 additions & 0 deletions custom/wasm-bindgen/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@ categories = ["wasm"]
getrandom = { path = "../..", features = ["custom"] }
wasm-bindgen = "0.2.29"

[dev-dependencies]
wasm-bindgen-test = "0.2"

# Unstable features used to build tests correctly
[features]
default = ["test-bindgen"]
test-bindgen = []
test-in-browser = ["test-bindgen"]

[[test]]
name = "common"
path = "../../tests/common.rs"
14 changes: 10 additions & 4 deletions tests/common.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
#[cfg(feature = "wasm-bindgen")]
// Extern crate declarations needed to prevent linking issues
#[cfg(feature = "test-stdweb")]
extern crate getrandom_stdweb;
#[cfg(feature = "test-bindgen")]
extern crate getrandom_wasm_bindgen;

#[cfg(feature = "test-bindgen")]
use wasm_bindgen_test::*;

use getrandom::getrandom;

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

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

#[cfg_attr(feature = "wasm-bindgen", wasm_bindgen_test)]
#[cfg_attr(feature = "test-bindgen", wasm_bindgen_test)]
#[test]
fn test_diff() {
let mut v1 = [0u8; 1000];
Expand All @@ -31,7 +37,7 @@ fn test_diff() {
assert!(n_diff_bits >= v1.len() as u32);
}

#[cfg_attr(feature = "wasm-bindgen", wasm_bindgen_test)]
#[cfg_attr(feature = "test-bindgen", wasm_bindgen_test)]
#[test]
fn test_huge() {
let mut huge = [0u8; 100_000];
Expand Down

0 comments on commit 75a5b58

Please sign in to comment.