config tests: cover blind spots in git_die_config() tests

There were no tests checking for the output of the git_die_config() function in the config API, added in 5a80e97c827 (config: add `git_die_config()` to the config-set API, 2014-08-07). We only tested "test_must_fail", but didn't assert the output. We need tests for this because a subsequent commit will alter the return value of git_config_get_value_multi(), which is used to get the config values in the git_die_config() function. This test coverage helps to build confidence in that subsequent change. These tests cover different interactions with git_die_config(): - The "notes.mergeStrategy" test in "t/t3309-notes-merge-auto-resolve.sh" is a case where a function outside of config.c (git_config_get_notes_strategy()) calls git_die_config(). - The "gc.pruneExpire" test in "t5304-prune.sh" is a case where git_config_get_expiry() calls git_die_config(), covering a different "type" than the "string" test for "notes.mergeStrategy". - The "fetch.negotiationAlgorithm" test in "t/t5552-skipping-fetch-negotiator.sh" is a case where git_config_get_string*() calls git_die_config(). We also cover both the "from command-line config" and "in file..at line" cases here. The clobbering of existing ".git/config" files here is so that we're not implicitly testing the line count of the default config. Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Ævar Arnfjörð Bjarmason committed Mar 28, 2023 at 16:04 UTC 258902ce07779a6ca532d092279c1554a199ba2a
3 files changed +32 -3
t/t3309-notes-merge-auto-resolve.sh
+6 -1
@@ -360,7 +360,12 @@ test_expect_success 'merge z into y with invalid strategy => Fail/No changes' '
360
361 test_expect_success 'merge z into y with invalid configuration option => Fail/No changes' '
362 git config core.notesRef refs/notes/y &&
363 - test_must_fail git -c notes.mergeStrategy="foo" notes merge z &&
363 + cat >expect <<-\EOF &&
364 + error: unknown notes merge strategy foo
365 + fatal: unable to parse '\''notes.mergeStrategy'\'' from command-line config
366 + EOF
367 + test_must_fail git -c notes.mergeStrategy="foo" notes merge z 2>actual &&
368 + test_cmp expect actual &&
369 # Verify no changes (y)
370 verify_notes y y
371 '
t/t5304-prune.sh
+10 -2
@@ -64,8 +64,16 @@ test_expect_success 'gc: implicit prune --expire' '
64 '
65
66 test_expect_success 'gc: refuse to start with invalid gc.pruneExpire' '
67 - git config gc.pruneExpire invalid &&
68 - test_must_fail git gc
67 + test_when_finished "rm -rf repo" &&
68 + git init repo &&
69 + >repo/.git/config &&
70 + git -C repo config gc.pruneExpire invalid &&
71 + cat >expect <<-\EOF &&
72 + error: Invalid gc.pruneexpire: '\''invalid'\''
73 + fatal: bad config variable '\''gc.pruneexpire'\'' in file '\''.git/config'\'' at line 2
74 + EOF
75 + test_must_fail git -C repo gc 2>actual &&
76 + test_cmp expect actual
77 '
78
79 test_expect_success 'gc: start with ok gc.pruneExpire' '
t/t5552-skipping-fetch-negotiator.sh
+16
@@ -3,6 +3,22 @@
3 test_description='test skipping fetch negotiator'
4 . ./test-lib.sh
5
6 +test_expect_success 'fetch.negotiationalgorithm config' '
7 + test_when_finished "rm -rf repo" &&
8 + git init repo &&
9 + cat >repo/.git/config <<-\EOF &&
10 + [fetch]
11 + negotiationAlgorithm
12 + EOF
13 + cat >expect <<-\EOF &&
14 + error: missing value for '\''fetch.negotiationalgorithm'\''
15 + fatal: bad config variable '\''fetch.negotiationalgorithm'\'' in file '\''.git/config'\'' at line 2
16 + EOF
17 + test_expect_code 128 git -C repo fetch >out 2>actual &&
18 + test_must_be_empty out &&
19 + test_cmp expect actual
20 +'
21 +
22 have_sent () {
23 while test "$#" -ne 0
24 do