Speed up JSMoo tests by including them in the binary

old-bit-manip
Nick Krichevsky 2023-11-21 19:47:04 -05:00
parent 6eb5f42ea4
commit a5e838dda4
3 changed files with 33 additions and 3 deletions

20
Cargo.lock generated
View File

@ -12,6 +12,7 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
name = "ferris-boi"
version = "0.1.0"
dependencies = [
"include_dir",
"serde",
"serde_derive",
"serde_json",
@ -33,6 +34,25 @@ version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2540771e65fc8cb83cd6e8a237f70c319bd5c29f78ed1084ba5d50eeac86f7f9"
[[package]]
name = "include_dir"
version = "0.7.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "18762faeff7122e89e0857b02f7ce6fcc0d101d5e9ad2ad7846cc01d61b7f19e"
dependencies = [
"include_dir_macros",
]
[[package]]
name = "include_dir_macros"
version = "0.7.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b139284b5cf57ecfa712bcc66950bb635b31aff41c188e8a4cfc758eca374a3f"
dependencies = [
"proc-macro2 1.0.67",
"quote 1.0.33",
]
[[package]]
name = "itoa"
version = "1.0.6"

View File

@ -15,3 +15,7 @@ serde = "1.0"
serde_json = "1.0"
serde_derive = "1.0"
test-generator = "0.3.0"
include_dir = "0.7.3"
[profile.release]
debug = true

View File

@ -1,14 +1,20 @@
use std::fs::File;
use std::path::Path;
use ferris_boi::cpu::Processor;
use include_dir::{include_dir, Dir};
use test_generator::test_resources;
use super::TestCase;
const TESTDATA_DIR: Dir<'_> = include_dir!("$CARGO_MANIFEST_DIR/tests/cpu/jsmoo/testdata");
#[test_resources("tests/cpu/jsmoo/testdata/*.json")]
fn test_jsmoo_test(filename: &str) {
let testdata_file = File::open(filename).expect("failed to open test data file");
let test_cases = serde_json::from_reader::<_, Vec<TestCase>>(testdata_file)
let basename = Path::new(filename).file_name().unwrap();
let testdata_file = TESTDATA_DIR
.get_file(basename)
.expect("could not find data file");
let test_cases = serde_json::from_slice::<Vec<TestCase>>(testdata_file.contents())
.expect("failed to parse test data file");
for test_case in test_cases {