#[path = "support/front_end.rs"]
mod front_end;
use std::path::{Path, PathBuf};
#[test]
fn every_fuzzer_seed_survives_the_front_end() {
let seeds = root().join("fuzz/seeds/tokenize");
let files = files_in(&seeds);
assert!(
files.len() > 60,
"the seed corpus at {} has shrunk to {} files",
seeds.display(),
files.len()
);
for file in files {
let bytes = std::fs::read(&file)
.unwrap_or_else(|why| panic!("cannot read {}: {why}", file.display()));
let query =
String::from_utf8(bytes).unwrap_or_else(|_| panic!("{} is not UTF-8", file.display()));
front_end::exercise(&query);
}
}
#[test]
fn every_input_the_fuzzer_found_stays_fixed() {
for file in files_in(&root().join("crates/rudb-parse/tests/crashers")) {
let bytes = std::fs::read(&file)
.unwrap_or_else(|why| panic!("cannot read {}: {why}", file.display()));
if let Ok(query) = std::str::from_utf8(&bytes) {
front_end::exercise(query);
}
}
}
fn files_in(directory: &Path) -> Vec<PathBuf> {
let entries = std::fs::read_dir(directory)
.unwrap_or_else(|why| panic!("cannot read {}: {why}", directory.display()));
let mut files: Vec<PathBuf> = entries
.map(|entry| entry.expect("cannot read a directory entry").path())
.filter(|path| path.is_file() && path.file_name().is_some_and(|name| name != ".gitkeep"))
.collect();
files.sort();
files
}
fn root() -> PathBuf {
Path::new(env!("CARGO_MANIFEST_DIR")).join("../..")
}