tests: Improve testing infrastructure

- Cleanup .travis.yml
  - Loops over std/no_std targets
  - Remove deprecated/useless keys
  - No more `cd`, we just use `--package`.
- Improve tests
  - Main `getrandom` tests are now unit test modules instead of
    integration tests, making the code cleaner.
  - The custom RNG crates now use this common module as part of their
    integration tests.
  - No more weird test-only features needed to get the crate to build.

Signed-off-by: Joe Richey <joerichey@google.com>
This commit is contained in:
Joe Richey 2020-02-18 22:36:58 -08:00 committed by Joseph Richey
parent ff6299dd77
commit 1375181832
9 changed files with 69 additions and 97 deletions

View File

@ -1,11 +1,16 @@
language: rust
sudo: false
os: linux
matrix:
# Targets that we just build (rather than run and test)
env:
global:
- STD_TARGETS="x86_64-sun-solaris x86_64-unknown-cloudabi x86_64-unknown-freebsd x86_64-fuchsia x86_64-unknown-netbsd x86_64-unknown-redox x86_64-fortanix-unknown-sgx"
- NO_STD_TARGETS="x86_64-unknown-uefi x86_64-unknown-hermit x86_64-unknown-l4re-uclibc x86_64-uwp-windows-gnu x86_64-wrs-vxworks"
jobs:
include:
- name: "Linux, 1.32.0"
rust: 1.32.0
os: linux
- name: "OSX, 1.32.0"
rust: 1.32.0
@ -68,41 +73,40 @@ matrix:
# This is actually useful as it finds stuff such as rust-random/rand#669
- cargo web test --target wasm32-unknown-emscripten --no-run
- cargo web test --target asmjs-unknown-emscripten --no-run
# wasi tests
- cargo test --target wasm32-wasi
# stdweb tests (Node, Chrome)
- cd custom/stdweb
- cargo web test --nodejs --target=wasm32-unknown-unknown
- cargo web test --target=wasm32-unknown-unknown
# wasm-bindgen tests (Node, Firefox, Chrome)
- 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
# stdweb (wasm32-unknown-unknown) tests (Node, Chrome)
- cargo web test --package stdweb-getrandom
- cargo web test --package stdweb-getrandom --nodejs
# wasm-bindgen (wasm32-unknown-unknown) tests (Node, Firefox, Chrome)
- cargo test --package wasm-bindgen-getrandom
--target wasm32-unknown-unknown --test node
- GECKODRIVER=$HOME/geckodriver
cargo test --package wasm-bindgen-getrandom
--target wasm32-unknown-unknown --test web
- CHROMEDRIVER=$HOME/chromedriver
cargo test --package wasm-bindgen-getrandom
--target wasm32-unknown-unknown --test web
- &nightly_and_docs
name: "Linux, nightly, docs"
rust: nightly
os: linux
install:
- rustup target add wasm32-unknown-unknown
- cargo --list | egrep "^\s*deadlinks$" -q || cargo install cargo-deadlinks
- cargo deadlinks -V
script:
# Check that our tests pass in the default configuration
- cargo test
- cargo test --benches
# Check that setting various features does not break the build
- cargo build --features=std
- cargo build --features=custom
# remove cached documentation, otherwise files from previous PRs can get included
- rm -rf target/doc
- cargo doc --no-deps --features=std,custom
- cargo doc --no-deps --manifest-path=custom/wasm-bindgen/Cargo.toml --target=wasm32-unknown-unknown
- cargo doc --no-deps --package wasm-bindgen-getrandom --target=wasm32-unknown-unknown
- cargo deadlinks --dir target/doc
# also test minimum dependency versions are usable
# Check that our tests pass in the default/minimal configuration
- cargo test --tests --benches
- cargo generate-lockfile -Z minimal-versions
- cargo test --features=std,custom
- cargo test --tests --benches
- <<: *nightly_and_docs
name: "OSX, nightly, docs"
@ -111,49 +115,23 @@ matrix:
- name: "cross-platform build only"
rust: nightly
install:
- rustup target add x86_64-sun-solaris
- rustup target add x86_64-unknown-cloudabi
- rustup target add x86_64-unknown-freebsd
- rustup target add x86_64-fuchsia
- rustup target add x86_64-unknown-netbsd
- rustup target add x86_64-unknown-redox
- rustup target add x86_64-fortanix-unknown-sgx
- echo $STD_TARGETS | xargs -n1 rustup target add
# For no_std targets
- rustup component add rust-src
- cargo install cargo-xbuild || true
- cargo --list | egrep "^\s*xbuild$" -q || cargo install cargo-xbuild
script:
- cargo build --target=x86_64-sun-solaris
- cargo build --target=x86_64-unknown-cloudabi
- cargo build --target=x86_64-unknown-freebsd
- cargo build --target=x86_64-fuchsia
- cargo build --target=x86_64-unknown-netbsd
- cargo build --target=x86_64-unknown-redox
- cargo build --target=x86_64-fortanix-unknown-sgx
- cargo xbuild --target=x86_64-unknown-uefi
- cargo xbuild --target=x86_64-unknown-hermit
- cargo xbuild --target=x86_64-unknown-l4re-uclibc
- cargo xbuild --target=x86_64-uwp-windows-gnu
- cargo xbuild --target=x86_64-wrs-vxworks
# We test that getrandom builds for all targets
- echo $STD_TARGETS | xargs -t -n1 cargo build --target
- echo $NO_STD_TARGETS | xargs -t -n1 cargo xbuild --target
# also test minimum dependency versions are usable
- cargo generate-lockfile -Z minimal-versions
- cargo build --target=x86_64-sun-solaris
- cargo build --target=x86_64-unknown-cloudabi
- cargo build --target=x86_64-unknown-freebsd
- cargo build --target=x86_64-fuchsia
- cargo build --target=x86_64-unknown-netbsd
- cargo build --target=x86_64-unknown-redox
- cargo build --target=x86_64-fortanix-unknown-sgx
- cargo xbuild --target=x86_64-unknown-uefi
- cargo xbuild --target=x86_64-unknown-hermit
- cargo xbuild --target=x86_64-unknown-l4re-uclibc
- cargo xbuild --target=x86_64-uwp-windows-gnu
- cargo xbuild --target=x86_64-wrs-vxworks
- echo $STD_TARGETS | xargs -t -n1 cargo build --target
- echo $NO_STD_TARGETS | xargs -t -n1 cargo xbuild --target
# Trust cross-built/emulated targets. We must repeat all non-default values.
- name: "Linux (MIPS, big-endian)"
env: TARGET=mips-unknown-linux-gnu
rust: stable
sudo: required
dist: trusty
services: docker
install:
@ -165,7 +143,6 @@ matrix:
- name: "Android (ARMv7)"
env: TARGET=armv7-linux-androideabi
rust: stable
sudo: required
dist: trusty
services: docker
install:

View File

@ -1,5 +1,4 @@
#![feature(test)]
extern crate getrandom;
extern crate test;
#[bench]

View File

@ -13,14 +13,5 @@ categories = ["wasm"]
getrandom = { path = "../..", version = "0.2", features = ["custom"] }
stdweb = "0.4.18"
# Test-only features allowing us to reuse most of the code in common.rs
[features]
default = ["test-stdweb"]
test-stdweb = []
[[test]]
name = "common"
path = "../../tests/common.rs"
[package.metadata.docs.rs]
default-target = "wasm32-unknown-unknown"

View File

@ -0,0 +1,7 @@
// Explicitly use the Custom RNG crate to link it in.
use stdweb_getrandom as _;
use getrandom::getrandom;
use test;
#[path = "../../../src/test_common.rs"]
mod test_common;

View File

@ -11,20 +11,10 @@ categories = ["wasm"]
[dependencies]
getrandom = { path = "../..", version = "0.2", features = ["custom"] }
wasm-bindgen = "0.2.29"
wasm-bindgen = "0.2.46"
[dev-dependencies]
wasm-bindgen-test = "0.2"
# Test-only features allowing us to reuse most of the code in common.rs
[features]
default = ["test-bindgen"]
test-bindgen = []
test-in-browser = ["test-bindgen"]
[[test]]
name = "common"
path = "../../tests/common.rs"
wasm-bindgen-test = "0.2.46"
[package.metadata.docs.rs]
default-target = "wasm32-unknown-unknown"

View File

@ -0,0 +1,7 @@
// Explicitly use the Custom RNG crate to link it in.
use wasm_bindgen_getrandom as _;
use getrandom::getrandom;
use wasm_bindgen_test::wasm_bindgen_test as test;
#[path = "../../../src/test_common.rs"]
mod test_common;

View File

@ -0,0 +1,9 @@
// Explicitly use the Custom RNG crate to link it in.
use wasm_bindgen_getrandom as _;
wasm_bindgen_test::wasm_bindgen_test_configure!(run_in_browser);
use getrandom::getrandom;
use wasm_bindgen_test::wasm_bindgen_test as test;
#[path = "../../../src/test_common.rs"]
mod test_common;

View File

@ -214,3 +214,6 @@ pub fn getrandom(dest: &mut [u8]) -> Result<(), Error> {
}
imp::getrandom_inner(dest)
}
#[cfg(test)]
mod test_common;

View File

@ -1,25 +1,14 @@
// Explicitly use the Custom RNG crates to link them in.
#[cfg(feature = "test-stdweb")]
use stdweb_getrandom as _;
#[cfg(feature = "test-bindgen")]
use wasm_bindgen_getrandom as _;
// Both getrandom and test can be renamed by the parent module.
use super::getrandom;
#[cfg(all(target_arch = "wasm32", target_os = "unknown"))]
use super::test;
#[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 = "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 = "test-bindgen", wasm_bindgen_test)]
#[test]
fn test_diff() {
let mut v1 = [0u8; 1000];
@ -37,18 +26,18 @@ fn test_diff() {
assert!(n_diff_bits >= v1.len() as u32);
}
#[cfg_attr(feature = "test-bindgen", wasm_bindgen_test)]
#[test]
fn test_huge() {
let mut huge = [0u8; 100_000];
getrandom(&mut huge).unwrap();
}
#[cfg(any(unix, windows, target_os = "redox", target_os = "fuchsia"))]
// On WASM, the thread API always fails/panics
#[cfg(not(target_arch = "wasm32"))]
#[test]
fn test_multithreading() {
use std::sync::mpsc::channel;
use std::thread;
extern crate std;
use std::{sync::mpsc::channel, thread, vec};
let mut txs = vec![];
for _ in 0..20 {