Skip to content

Commit e29ed04

Browse files
authored
Move tests to tests/ directory (#195)
Signed-off-by: Joe Richey <[email protected]>
1 parent 1c6749e commit e29ed04

File tree

5 files changed

+24
-20
lines changed

5 files changed

+24
-20
lines changed

src/lib.rs

-5
Original file line numberDiff line numberDiff line change
@@ -233,8 +233,3 @@ pub fn getrandom(dest: &mut [u8]) -> Result<(), Error> {
233233
}
234234
imp::getrandom_inner(dest)
235235
}
236-
237-
#[cfg(test)]
238-
mod test_common;
239-
#[cfg(test)]
240-
mod test_rdrand;

src/test_rdrand.rs

-8
This file was deleted.

src/test_common.rs renamed to tests/common/mod.rs

+6-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
// Allow getrandom to be renamed by the parent module.
2-
use super::getrandom;
1+
use super::getrandom_impl;
32

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

1615
#[test]
1716
fn test_diff() {
1817
let mut v1 = [0u8; 1000];
19-
getrandom(&mut v1).unwrap();
18+
getrandom_impl(&mut v1).unwrap();
2019

2120
let mut v2 = [0u8; 1000];
22-
getrandom(&mut v2).unwrap();
21+
getrandom_impl(&mut v2).unwrap();
2322

2423
let mut n_diff_bits = 0;
2524
for i in 0..v1.len() {
@@ -33,7 +32,7 @@ fn test_diff() {
3332
#[test]
3433
fn test_huge() {
3534
let mut huge = [0u8; 100_000];
36-
getrandom(&mut huge).unwrap();
35+
getrandom_impl(&mut huge).unwrap();
3736
}
3837

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

5655
for _ in 0..100 {
57-
getrandom(&mut v).unwrap();
56+
getrandom_impl(&mut v).unwrap();
5857
thread::yield_now();
5958
}
6059
});

tests/normal.rs

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// Use the normal getrandom implementation on this architecture.
2+
use getrandom::getrandom as getrandom_impl;
3+
mod common;

tests/rdrand.rs

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// We only test the RDRAND-based RNG source on supported architectures.
2+
#![cfg(any(target_arch = "x86_64", target_arch = "x86"))]
3+
4+
// rdrand.rs expects to be part of the getrandom main crate, so we need these
5+
// additional imports to get rdrand.rs to compile.
6+
use getrandom::Error;
7+
#[macro_use]
8+
extern crate cfg_if;
9+
#[path = "../src/rdrand.rs"]
10+
mod rdrand;
11+
#[path = "../src/util.rs"]
12+
mod util;
13+
14+
use rdrand::getrandom_inner as getrandom_impl;
15+
mod common;

0 commit comments

Comments
 (0)