@@ -16,8 +16,10 @@ use std::env::join_paths;
1616use std:: path:: PathBuf ;
1717
1818use indoc:: indoc;
19+ use itertools:: Itertools as _;
1920use regex:: Regex ;
2021
22+ use crate :: common:: default_toml_from_schema;
2123use crate :: common:: fake_editor_path;
2224use crate :: common:: force_interactive;
2325use crate :: common:: to_toml_value;
@@ -1256,6 +1258,82 @@ fn test_config_get() {
12561258 " ) ;
12571259}
12581260
1261+ #[ test]
1262+ fn test_config_get_yields_values_consistent_with_schema_defaults ( ) {
1263+ let test_env = TestEnvironment :: default ( ) ;
1264+ let get_true_default = move |key : & str | {
1265+ let output = test_env. run_jj_in ( "." , [ "config" , "get" , key] ) . success ( ) ;
1266+ let output_doc =
1267+ toml_edit:: ImDocument :: parse ( format ! ( "test={}" , output. stdout. normalized( ) ) )
1268+ . unwrap_or_else ( |_| {
1269+ // Unfortunately for this test, `config get` is "lossy" and does not print
1270+ // quoted strings. This means that e.g. `false` and `"false"` are not
1271+ // distinguishable. If value couldn't be parsed, it's probably a string, so
1272+ // let's parse its Debug string instead.
1273+ toml_edit:: ImDocument :: parse ( format ! (
1274+ "test={:?}" ,
1275+ output. stdout. normalized( ) . trim( )
1276+ ) )
1277+ . unwrap ( )
1278+ } ) ;
1279+ output_doc. get ( "test" ) . unwrap ( ) . as_value ( ) . unwrap ( ) . clone ( )
1280+ } ;
1281+
1282+ let Some ( schema_defaults) = default_toml_from_schema ( ) else {
1283+ testutils:: ensure_running_outside_ci ( "`jq` must be in the PATH" ) ;
1284+ eprintln ! ( "Skipping test because jq is not installed on the system" ) ;
1285+ return ;
1286+ } ;
1287+
1288+ for ( key, schema_default) in schema_defaults. as_table ( ) . get_values ( ) {
1289+ let key = key. iter ( ) . join ( "." ) ;
1290+ match key. as_str ( ) {
1291+ // These keys technically don't have a default value, but they exhibit a default
1292+ // behavior consistent with the value claimed by the schema. When these defaults are
1293+ // used, a hint is printed to stdout.
1294+ "ui.default-command" => insta:: assert_snapshot!( schema_default, @r#""log""# ) ,
1295+ "ui.diff-editor" => insta:: assert_snapshot!( schema_default, @r#"":builtin""# ) ,
1296+ "ui.merge-editor" => insta:: assert_snapshot!( schema_default, @r#"":builtin""# ) ,
1297+ "git.fetch" => insta:: assert_snapshot!( schema_default, @r#""origin""# ) ,
1298+ "git.push" => insta:: assert_snapshot!( schema_default, @r#""origin""# ) ,
1299+
1300+ // When no `short-prefixes` revset is explicitly configured, the revset for `log` is
1301+ // used instead, even if that has a value different from the default. The schema
1302+ // represents this behavior with a symbolic default value.
1303+ "revsets.short-prefixes" => {
1304+ insta:: assert_snapshot!( schema_default, @r#""<revsets.log>""# ) ;
1305+ }
1306+
1307+ // The default for `ui.pager` is a table; `ui.pager.command` is an array and `jj config
1308+ // get` currently cannot print that. The schema default omits the env variable
1309+ // `LESSCHARSET` and gives the default as a plain string.
1310+ "ui.pager" => insta:: assert_snapshot!( schema_default, @r#""less -FRX""# ) ,
1311+
1312+ // The `immutable_heads()` revset actually defaults to `builtin_immutable_heads()` but
1313+ // this would be a poor starting point for a custom revset, so the schema "inlines"
1314+ // `builtin_immutable_heads()`.
1315+ "revset-aliases.'immutable_heads()'" => {
1316+ let builtin_default =
1317+ get_true_default ( "revset-aliases.'builtin_immutable_heads()'" ) ;
1318+ assert ! (
1319+ builtin_default. to_string( ) == schema_default. to_string( ) ,
1320+ "{key}: the schema claims a default ({schema_default}) which is different \
1321+ from what builtin_immutable_heads() resolves to ({builtin_default})"
1322+ ) ;
1323+ }
1324+
1325+ _ => {
1326+ let true_default = get_true_default ( & key) ;
1327+ assert ! (
1328+ true_default. to_string( ) == schema_default. to_string( ) ,
1329+ "{key}: true default value ({true_default}) is not consistent with default \
1330+ claimed by schema ({schema_default})"
1331+ ) ;
1332+ }
1333+ }
1334+ }
1335+ }
1336+
12591337#[ test]
12601338fn test_config_path_syntax ( ) {
12611339 let test_env = TestEnvironment :: default ( ) ;
0 commit comments