feat(test): test all queries

Fallback to default testing for all queries present in the parser's
queries directory.

For a given query <QUERY>.scm, the test files are searched in
test/<QUERY>/*

Also mimic the output of other test-running subcommands when testing
queries.

Co-authored-by: Thomas Vigouroux <thomas.vigouroux@protonmail.com>
This commit is contained in:
Amaan Qureshi 2024-09-24 11:43:13 -04:00
parent b695568516
commit cc4378e751
3 changed files with 85 additions and 18 deletions

View file

@ -735,6 +735,46 @@ fn run() -> Result<()> {
color,
)?;
}
// For the rest of the queries, find their tests and run them
for entry in walkdir::WalkDir::new(current_dir.join("queries"))
.into_iter()
.filter_map(|e| e.ok())
.filter(|e| e.file_type().is_file())
{
let stem = entry
.path()
.file_stem()
.map(|s| s.to_str().unwrap_or_default())
.unwrap_or_default();
if stem != "highlights" && stem != "tags" {
let paths = walkdir::WalkDir::new(test_dir.join(stem))
.into_iter()
.filter_map(|e| {
let entry = e.ok()?;
if entry.file_type().is_file() {
Some(String::from(entry.path().to_string_lossy()))
} else {
None
}
})
.collect::<Vec<String>>();
if !paths.is_empty() {
println!("{stem}:");
}
query::query_files_at_paths(
language,
paths,
entry.path(),
false,
None,
None,
true,
false,
false,
)?;
}
}
}
Commands::Fuzz(fuzz_options) => {