use alloc::string::{String, ToString};
use alloc::vec::Vec;
use std::fs;
use std::path::Path;
pub fn load_spec_tests() -> Vec<(String, Vec<u8>)> {
let mut tests = Vec::new();
if Path::new("tests/fixtures").exists() {
if let Ok(entries) = fs::read_dir("tests/fixtures") {
for entry in entries.flatten() {
let path = entry.path();
if path.extension().and_then(|s| s.to_str()) == Some("wasm") {
if let Ok(bytes) = fs::read(&path) {
let name = path
.file_stem()
.and_then(|s| s.to_str())
.unwrap_or("unknown")
.to_string();
tests.push((name, bytes));
}
}
}
}
}
if Path::new("tests/fixtures/spec").exists() {
if let Ok(entries) = fs::read_dir("tests/fixtures/spec") {
for entry in entries.flatten() {
let path = entry.path();
if path.extension().and_then(|s| s.to_str()) == Some("wasm") {
if let Ok(bytes) = fs::read(&path) {
let name = path
.file_stem()
.and_then(|s| s.to_str())
.unwrap_or("unknown")
.to_string();
tests.push((name, bytes));
}
}
}
}
}
if Path::new("tests/spec-tests").exists() {
if let Ok(entries) = fs::read_dir("tests/spec-tests/test/core") {
for entry in entries.flatten() {
let path = entry.path();
if path.extension().and_then(|s| s.to_str()) == Some("wasm") {
if let Ok(bytes) = fs::read(&path) {
let name = path
.file_stem()
.and_then(|s| s.to_str())
.unwrap_or("unknown")
.to_string();
tests.push(("spec_".to_string() + &name, bytes));
}
}
}
}
}
tests
}
pub fn spec_tests_available() -> bool {
load_spec_tests().len() > 0
}
pub fn load_spec_test(name: &str) -> Option<Vec<u8>> {
load_spec_tests()
.into_iter()
.find(|(n, _)| n == name)
.map(|(_, bytes)| bytes)
}