Skip to content

Commit

Permalink
Move tests to tests/ directory (#195)
Browse files Browse the repository at this point in the history
Signed-off-by: Joe Richey <[email protected]>
  • Loading branch information
josephlr authored Jan 4, 2021
1 parent 1c6749e commit e29ed04
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 20 deletions.
5 changes: 0 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,3 @@ pub fn getrandom(dest: &mut [u8]) -> Result<(), Error> {
}
imp::getrandom_inner(dest)
}

#[cfg(test)]
mod test_common;
#[cfg(test)]
mod test_rdrand;
8 changes: 0 additions & 8 deletions src/test_rdrand.rs

This file was deleted.

13 changes: 6 additions & 7 deletions src/test_common.rs → tests/common/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// Allow getrandom to be renamed by the parent module.
use super::getrandom;
use super::getrandom_impl;

#[cfg(all(target_arch = "wasm32", target_os = "unknown", not(cargo_web)))]
use wasm_bindgen_test::wasm_bindgen_test as test;
Expand All @@ -10,16 +9,16 @@ wasm_bindgen_test::wasm_bindgen_test_configure!(run_in_browser);
#[test]
fn test_zero() {
// Test that APIs are happy with zero-length requests
getrandom(&mut [0u8; 0]).unwrap();
getrandom_impl(&mut [0u8; 0]).unwrap();
}

#[test]
fn test_diff() {
let mut v1 = [0u8; 1000];
getrandom(&mut v1).unwrap();
getrandom_impl(&mut v1).unwrap();

let mut v2 = [0u8; 1000];
getrandom(&mut v2).unwrap();
getrandom_impl(&mut v2).unwrap();

let mut n_diff_bits = 0;
for i in 0..v1.len() {
Expand All @@ -33,7 +32,7 @@ fn test_diff() {
#[test]
fn test_huge() {
let mut huge = [0u8; 100_000];
getrandom(&mut huge).unwrap();
getrandom_impl(&mut huge).unwrap();
}

// On WASM, the thread API always fails/panics
Expand All @@ -54,7 +53,7 @@ fn test_multithreading() {
let mut v = [0u8; 1000];

for _ in 0..100 {
getrandom(&mut v).unwrap();
getrandom_impl(&mut v).unwrap();
thread::yield_now();
}
});
Expand Down
3 changes: 3 additions & 0 deletions tests/normal.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Use the normal getrandom implementation on this architecture.
use getrandom::getrandom as getrandom_impl;
mod common;
15 changes: 15 additions & 0 deletions tests/rdrand.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// We only test the RDRAND-based RNG source on supported architectures.
#![cfg(any(target_arch = "x86_64", target_arch = "x86"))]

// rdrand.rs expects to be part of the getrandom main crate, so we need these
// additional imports to get rdrand.rs to compile.
use getrandom::Error;
#[macro_use]
extern crate cfg_if;
#[path = "../src/rdrand.rs"]
mod rdrand;
#[path = "../src/util.rs"]
mod util;

use rdrand::getrandom_inner as getrandom_impl;
mod common;

0 comments on commit e29ed04

Please sign in to comment.