Skip to content

Commit

Permalink
config-schema: validate default configs in tests with taplo
Browse files Browse the repository at this point in the history
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
steadmon committed Feb 13, 2025
1 parent e83b328 commit 174f6e3
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ jobs:
target: ${{ matrix.target }}
- uses: taiki-e/install-action@995f97569c4a8ae84dcd7e1a0107f65ca6ebf139
with:
tool: nextest
tool: nextest,taplo-cli
- name: Build
run: cargo build --target ${{ matrix.target }} --workspace --all-targets --verbose ${{ matrix.cargo_flags }}
- name: Test
Expand Down
1 change: 1 addition & 0 deletions cli/tests/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ mod test_commit_template;
mod test_completion;
mod test_concurrent_operations;
mod test_config_command;
mod test_config_schema;
mod test_copy_detection;
mod test_debug_command;
mod test_describe_command;
Expand Down
71 changes: 71 additions & 0 deletions cli/tests/test_config_schema.rs
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");
}
3 changes: 3 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@

# for git subprocess test
git

# for schema tests
taplo
];

env = {
Expand Down

0 comments on commit 174f6e3

Please sign in to comment.