diff options
| author | Jack O'Connor <[email protected]> | 2025-03-18 09:55:09 -0700 |
|---|---|---|
| committer | Jack O'Connor <[email protected]> | 2025-03-18 10:16:42 -0700 |
| commit | 5ebc441dc93ea39b9ba875b3d459056d11207c79 (patch) | |
| tree | 5513be97f9be57a8fd0055e82025aaead671fdb6 /test_vectors | |
| parent | 4011d240cb026a5e1f282438ef50aef701721c28 (diff) | |
make the test_vectors tests WASM-compatible
Diffstat (limited to 'test_vectors')
| -rw-r--r-- | test_vectors/src/lib.rs | 14 |
1 files changed, 6 insertions, 8 deletions
diff --git a/test_vectors/src/lib.rs b/test_vectors/src/lib.rs index 6a4c798..543a31d 100644 --- a/test_vectors/src/lib.rs +++ b/test_vectors/src/lib.rs @@ -1,6 +1,10 @@ use blake3::guts::{BLOCK_LEN, CHUNK_LEN}; use serde::{Deserialize, Serialize}; +// Reading files at runtime requires special configuration under WASM/WASI, so including this at +// compile time is simpler. +const TEST_VECTORS_JSON: &str = include_str!("../test_vectors.json"); + // A non-multiple of 4 is important, since one possible bug is to fail to emit // partial words. pub const OUTPUT_LEN: usize = 2 * BLOCK_LEN + 3; @@ -129,14 +133,8 @@ pub fn generate_json() -> String { json } -pub fn read_test_vectors_file() -> String { - let test_vectors_file_path = "./test_vectors.json"; - std::fs::read_to_string(test_vectors_file_path).expect("failed to read test_vectors.json") -} - pub fn parse_test_cases() -> Cases { - let json = read_test_vectors_file(); - serde_json::from_str(&json).expect("failed to parse test_vectors.json") + serde_json::from_str(TEST_VECTORS_JSON).expect("failed to parse test_vectors.json") } #[cfg(test)] @@ -344,7 +342,7 @@ mod tests { fn test_checked_in_vectors_up_to_date() { // Replace Windows newlines, in case Git is configured to alter // newlines when files are checked out. - let json = read_test_vectors_file().replace("\r\n", "\n"); + let json = TEST_VECTORS_JSON.replace("\r\n", "\n"); if generate_json() != json { panic!("Checked-in test_vectors.json is not up to date. Regenerate with `cargo run --bin generate > ./test_vectors.json`."); } |
