mirror of
https://github.com/martinvonz/jj.git
synced 2025-05-05 23:42:50 +00:00
A pattern has emerged where a integration tests check for the availability of an external tool (`git`, `taplo`, `gpg`, ...) and skip the test (by simply passing it) when it is not available. To check this, the program is run with the `--version` flag. Some tests require that the program be available at least when running in CI, by calling `ensure_running_outside_ci` conditionally on the outcome. The decision is up to each test, though, the utility merely returns a `bool`.
52 lines
1.6 KiB
Rust
52 lines
1.6 KiB
Rust
use std::path::Path;
|
|
use std::process::Command;
|
|
use std::process::Output;
|
|
use std::process::Stdio;
|
|
|
|
use testutils::ensure_running_outside_ci;
|
|
use testutils::is_external_tool_installed;
|
|
|
|
fn taplo_check_config(file: &Path) -> datatest_stable::Result<Option<Output>> {
|
|
if !is_external_tool_installed("taplo") {
|
|
ensure_running_outside_ci("`taplo` must be in the PATH");
|
|
eprintln!("Skipping test because taplo is not installed on the system");
|
|
return Ok(None);
|
|
}
|
|
|
|
// Taplo requires an absolute URL to the schema :/
|
|
let root = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR"));
|
|
Ok(Some(
|
|
Command::new("taplo")
|
|
.args([
|
|
"check",
|
|
"--schema",
|
|
&format!("file://{}/src/config-schema.json", root.display()),
|
|
])
|
|
.arg(file.as_os_str())
|
|
.stdout(Stdio::piped())
|
|
.stderr(Stdio::piped())
|
|
.spawn()?
|
|
.wait_with_output()?,
|
|
))
|
|
}
|
|
|
|
pub(crate) fn taplo_check_config_valid(file: &Path) -> datatest_stable::Result<()> {
|
|
if let Some(taplo_res) = taplo_check_config(file)? {
|
|
if !taplo_res.status.success() {
|
|
eprintln!("Failed to validate {}:", file.display());
|
|
eprintln!("{}", String::from_utf8_lossy(&taplo_res.stderr));
|
|
return Err("Validation failed".into());
|
|
}
|
|
}
|
|
Ok(())
|
|
}
|
|
|
|
pub(crate) fn taplo_check_config_invalid(file: &Path) -> datatest_stable::Result<()> {
|
|
if let Some(taplo_res) = taplo_check_config(file)? {
|
|
if taplo_res.status.success() {
|
|
return Err("Validation unexpectedly passed".into());
|
|
}
|
|
}
|
|
Ok(())
|
|
}
|