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 22, 2019
1 parent 9f300db commit f1df844
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 11 deletions.
16 changes: 9 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ matrix:
- rustup target add wasm32-wasi
# Get geckodriver
- wget -O geckodriver.tar.gz https://github.com/mozilla/geckodriver/releases/download/v0.25.0/geckodriver-v0.25.0-linux64.tar.gz
- tar -xzf geckodriver.tar.gz
- tar -xzf geckodriver.tar.gz -C $HOME
# Get chromedirver (we cannot pin chrome version, so don't pin chromedriver version)
- export VERSION=$(wget -q -O - https://chromedriver.storage.googleapis.com/LATEST_RELEASE)
- wget -O chromedriver.zip https://chromedriver.storage.googleapis.com/$VERSION/chromedriver_linux64.zip
- unzip chromedriver.zip
- unzip chromedriver.zip -d $HOME
# Get cargo-web
- wget -O cargo-web.gz https://github.com/koute/cargo-web/releases/download/0.6.26/cargo-web-x86_64-unknown-linux-gnu.gz
- gunzip cargo-web.gz
Expand All @@ -68,12 +68,14 @@ 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
- 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
- cd ../wasm-bindgen
- cargo test --target wasm32-unknown-unknown
- GECKODRIVER=$HOME/geckodriver cargo test --target wasm32-unknown-unknown --features=test-in-browser
- CHROMEDRIVER=$HOME/chromedriver cargo test --target wasm32-unknown-unknown --features=test-in-browser

- name: "Linux, nightly, docs"
rust: nightly
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 f1df844

Please sign in to comment.