-
Notifications
You must be signed in to change notification settings - Fork 404
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
config-schema: validate default configs in tests with taplo
Set up tests using `taplo check --schema` to validate the default configs. Install taplo in GitHub CI and in the Nix flake. Fixes #5670.
- Loading branch information
Showing
4 changed files
with
76 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
use std::process::Command; | ||
use std::process::Stdio; | ||
|
||
fn taplo_check_config(file: &str) { | ||
if Command::new("taplo") | ||
.arg("--version") | ||
.stdout(Stdio::null()) | ||
.status() | ||
.is_err() | ||
{ | ||
eprintln!("Skipping test because taplo is not installed on the system"); | ||
return; | ||
} | ||
|
||
// Taplo requires an absolute URL to the schema :/ | ||
let root = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR")); | ||
let taplo_res = Command::new("taplo") | ||
.args(&[ | ||
"check", | ||
"--schema", | ||
&format!("file://{}/src/config-schema.json", root.display()), | ||
file, | ||
]) | ||
.stdout(Stdio::piped()) | ||
.stderr(Stdio::piped()) | ||
.spawn() | ||
.unwrap() | ||
.wait_with_output() | ||
.unwrap(); | ||
|
||
if !taplo_res.status.success() { | ||
eprintln!("Failed to validate {}:", file); | ||
eprintln!("{}", String::from_utf8_lossy(&taplo_res.stderr)); | ||
panic!("Validation failed"); | ||
} | ||
} | ||
|
||
#[test] | ||
fn test_taplo_check_colors_config() { | ||
taplo_check_config("src/config/colors.toml"); | ||
} | ||
|
||
#[test] | ||
fn test_taplo_check_merge_tools_config() { | ||
taplo_check_config("src/config/merge_tools.toml"); | ||
} | ||
|
||
#[test] | ||
fn test_taplo_check_misc_config() { | ||
taplo_check_config("src/config/misc.toml"); | ||
} | ||
|
||
#[test] | ||
fn test_taplo_check_revsets_config() { | ||
taplo_check_config("src/config/revsets.toml"); | ||
} | ||
|
||
#[test] | ||
fn test_taplo_check_templates_config() { | ||
taplo_check_config("src/config/templates.toml"); | ||
} | ||
|
||
#[test] | ||
fn test_taplo_check_unix_config() { | ||
taplo_check_config("src/config/unix.toml"); | ||
} | ||
|
||
#[test] | ||
fn test_taplo_check_windows_config() { | ||
taplo_check_config("src/config/windows.toml"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -92,6 +92,9 @@ | |
|
||
# for git subprocess test | ||
git | ||
|
||
# for schema tests | ||
taplo | ||
]; | ||
|
||
env = { | ||
|