t1300: add tests for missing keys
There are several tests in t1300-config.sh that validate failing invocations of "git config". However, there are no tests that check what happens when "git config" is asked to retrieve a value for a missing key. Add tests that check this for various combinations of "<section>.<key>" and "<section>.<subsection>.<key>". Signed-off-by: Andrei Rybak <rybak.a.v@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Andrei Rybak committed
Apr 23, 2023 at 15:46 UTC
3d77fbb664acab5157617cdb368a0c657bf20919
1 file changed
+17
t/t1300-config.sh
+17
@@ -98,6 +98,23 @@ test_expect_success 'subsections are not canonicalized by git-config' '
98
test_cmp_config two section.SubSection.key
99
'
100
101
+test_missing_key () {
102
+ local key="$1" &&
103
+ local title="$2" &&
104
+ test_expect_success "value for $title is not printed" '
105
+ test_must_fail git config "$key" >out 2>err &&
106
+ test_must_be_empty out &&
107
+ test_must_be_empty err
108
+ '
109
+}
110
+
111
+test_missing_key 'missingsection.missingkey' 'missing section and missing key'
112
+test_missing_key 'missingsection.penguin' 'missing section and existing key'
113
+test_missing_key 'section.missingkey' 'existing section and missing key'
114
+test_missing_key 'section.MissingSubSection.missingkey' 'missing subsection and missing key'
115
+test_missing_key 'section.SubSection.missingkey' 'existing subsection and missing key'
116
+test_missing_key 'section.MissingSubSection.key' 'missing subsection and existing key'
117
+
118
cat > .git/config <<\EOF
119
[alpha]
120
bar = foo