Skip to content

Commit d31c42f

Browse files
jgreitemannthoughtpolice
authored andcommitted
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.
1 parent e587851 commit d31c42f

File tree

2 files changed

+70
-0
lines changed

2 files changed

+70
-0
lines changed

cli/tests/runner.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ mod test_commit_template;
2121
mod test_completion;
2222
mod test_concurrent_operations;
2323
mod test_config_command;
24+
mod test_config_schema;
2425
mod test_copy_detection;
2526
mod test_debug_command;
2627
mod test_debug_init_simple_command;

cli/tests/test_config_schema.rs

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
// Copyright 2025 The Jujutsu Authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// https://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
use std::io::Write as _;
16+
use std::process::Command;
17+
use std::process::Output;
18+
use std::process::Stdio;
19+
20+
use testutils::ensure_running_outside_ci;
21+
use testutils::is_external_tool_installed;
22+
23+
use crate::common::default_toml_from_schema;
24+
25+
#[test]
26+
fn test_config_schema_default_values_are_consistent_with_schema() {
27+
if !is_external_tool_installed("taplo") {
28+
ensure_running_outside_ci("`taplo` must be in the PATH");
29+
eprintln!("Skipping test because taplo is not installed on the system");
30+
return;
31+
}
32+
33+
let Some(schema_defaults) = default_toml_from_schema() else {
34+
ensure_running_outside_ci("`jq` must be in the PATH");
35+
eprintln!("Skipping test because jq is not installed on the system");
36+
return;
37+
};
38+
39+
// Taplo requires an absolute URL to the schema :/
40+
let root = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR"));
41+
let mut taplo_child = Command::new("taplo")
42+
.args([
43+
"check",
44+
"--schema",
45+
&format!("file://{}/src/config-schema.json", root.display()),
46+
"-", // read from stdin
47+
])
48+
.stdin(Stdio::piped())
49+
.stdout(Stdio::piped())
50+
.stderr(Stdio::piped())
51+
.spawn()
52+
.unwrap();
53+
54+
{
55+
let mut stdin = taplo_child.stdin.take().unwrap();
56+
write!(stdin, "{schema_defaults}").unwrap();
57+
// pipe is closed here by dropping it
58+
}
59+
60+
let Output { status, stderr, .. } = taplo_child.wait_with_output().unwrap();
61+
if !status.success() {
62+
eprintln!(
63+
"taplo exited with status {status}:\n{}",
64+
String::from_utf8_lossy(&stderr)
65+
);
66+
eprintln!("while validating synthetic defaults TOML:\n{schema_defaults}");
67+
panic!("Schema defaults are not valid according to schema");
68+
}
69+
}

0 commit comments

Comments
 (0)