mirror of
https://github.com/martinvonz/jj.git
synced 2025-05-05 15:32:49 +00:00
config-schema: validate schema defaults according to schema
While the existing test checks that the schema defaults are consistent with the output of `jj config get` (with default config), it would not find type errors like the ones fixed in e9da94e. This add another test case which validates the synthetic TOML containing the default values according to the schema against the schema itself.
This commit is contained in:
parent
b420d1af98
commit
991704f4c2
@ -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_debug_init_simple_command;
|
||||
|
69
cli/tests/test_config_schema.rs
Normal file
69
cli/tests/test_config_schema.rs
Normal file
@ -0,0 +1,69 @@
|
||||
// Copyright 2025 The Jujutsu Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
use std::io::Write as _;
|
||||
use std::process::Command;
|
||||
use std::process::Output;
|
||||
use std::process::Stdio;
|
||||
|
||||
use testutils::ensure_running_outside_ci;
|
||||
use testutils::is_external_tool_installed;
|
||||
|
||||
use crate::common::default_toml_from_schema;
|
||||
|
||||
#[test]
|
||||
fn test_config_schema_default_values_are_consistent_with_schema() {
|
||||
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;
|
||||
}
|
||||
|
||||
let Some(schema_defaults) = default_toml_from_schema() else {
|
||||
ensure_running_outside_ci("`jq` must be in the PATH");
|
||||
eprintln!("Skipping test because jq 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 mut taplo_child = Command::new("taplo")
|
||||
.args([
|
||||
"check",
|
||||
"--schema",
|
||||
&format!("file://{}/src/config-schema.json", root.display()),
|
||||
"-", // read from stdin
|
||||
])
|
||||
.stdin(Stdio::piped())
|
||||
.stdout(Stdio::piped())
|
||||
.stderr(Stdio::piped())
|
||||
.spawn()
|
||||
.unwrap();
|
||||
|
||||
{
|
||||
let mut stdin = taplo_child.stdin.take().unwrap();
|
||||
write!(stdin, "{schema_defaults}").unwrap();
|
||||
// pipe is closed here by dropping it
|
||||
}
|
||||
|
||||
let Output { status, stderr, .. } = taplo_child.wait_with_output().unwrap();
|
||||
if !status.success() {
|
||||
eprintln!(
|
||||
"taplo exited with status {status}:\n{}",
|
||||
String::from_utf8_lossy(&stderr)
|
||||
);
|
||||
eprintln!("while validating synthetic defaults TOML:\n{schema_defaults}");
|
||||
panic!("Schema defaults are not valid according to schema");
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user