tests: do not shell out taplo to gather forgotten test files

It would be annoying if forgotten tests wouldn't be reported locally.
This commit is contained in:
Yuya Nishihara 2025-04-25 10:34:42 +09:00
parent 5a735182ac
commit 105c892ce4
3 changed files with 17 additions and 33 deletions

1
Cargo.lock generated
View File

@ -4006,6 +4006,7 @@ dependencies = [
"pollster",
"rand",
"tempfile",
"toml_edit",
]
[[package]]

View File

@ -29,6 +29,7 @@ jj-lib = { workspace = true, features = ["testing"] }
pollster = { workspace = true }
rand = { workspace = true }
tempfile = { workspace = true }
toml_edit = { workspace = true }
[lints]
workspace = true

View File

@ -26,7 +26,6 @@ use std::process::Command;
use std::process::Stdio;
use std::sync::Arc;
use bstr::ByteSlice as _;
use itertools::Itertools as _;
use jj_lib::backend;
use jj_lib::backend::Backend;
@ -635,38 +634,21 @@ pub fn assert_abandoned_with_parent(
}
pub fn assert_no_forgotten_test_files(test_dir: &Path) {
// We require `taplo` for this check; if it's not installed, that's ok unless
// we're running in CI.
if !is_external_tool_installed("taplo") {
ensure_running_outside_ci("`taplo` must be in the PATH");
eprintln!(
"Skipping check for forgotten test files because taplo is not installed on the system"
);
return;
}
// Use taplo to find all the test executable main modules listed in `[[test]]`.
let taplo_output = Command::new("taplo")
.args(["get", "test[*].name", "-f", "Cargo.toml"])
.current_dir(test_dir.parent().unwrap())
.stdout(Stdio::piped())
.stderr(Stdio::piped())
.output()
.unwrap();
assert!(
taplo_output.status.success(),
"taplo returned with status {}: {}",
taplo_output.status,
taplo_output.stderr.to_str_lossy(),
);
let test_bin_mods = taplo_output
.stdout
.to_str()
.unwrap()
.trim()
.lines()
.map(ToString::to_string)
.collect_vec();
// Parse the integration tests' main modules from the Cargo manifest.
let manifest = {
let file_path = test_dir.parent().unwrap().join("Cargo.toml");
let text = fs::read_to_string(&file_path).unwrap();
toml_edit::ImDocument::parse(text).unwrap()
};
let test_bin_mods = if let Some(item) = manifest.get("test") {
let tables = item.as_array_of_tables().unwrap();
tables
.iter()
.map(|test| test.get("name").unwrap().as_str().unwrap().to_owned())
.collect()
} else {
vec![]
};
// Add to that all submodules which are declared in the main test modules via
// `mod`.