Merge branch 'jc/apply-ws-prefix' into jch
[git/jrn.git] / t / t1308-config-set.sh
blob7fdf840b0020fb626118d056693b0e6be92bc1ac
1 #!/bin/sh
3 test_description='Test git config-set API in different settings'
5 . ./test-lib.sh
7 # 'check_config get_* section.key value' verifies that the entry for
8 # section.key is 'value'
9 check_config () {
10 if test "$1" = expect_code
11 then
12 expect_code="$2" && shift && shift
13 else
14 expect_code=0
15 fi &&
16 op=$1 key=$2 && shift && shift &&
17 if test $# != 0
18 then
19 printf "%s\n" "$@"
20 fi >expect &&
21 test_expect_code $expect_code test-config "$op" "$key" >actual &&
22 test_cmp expect actual
25 test_expect_success 'setup default config' '
26 cat >.git/config <<\EOF
27 [case]
28 penguin = very blue
29 Movie = BadPhysics
30 UPPERCASE = true
31 MixedCase = true
32 my =
33 foo
34 baz = sam
35 [Cores]
36 WhatEver = Second
37 baz = bar
38 [cores]
39 baz = bat
40 [CORES]
41 baz = ball
42 [my "Foo bAr"]
43 hi = mixed-case
44 [my "FOO BAR"]
45 hi = upper-case
46 [my "foo bar"]
47 hi = lower-case
48 [case]
49 baz = bat
50 baz = hask
51 [lamb]
52 chop = 65
53 head = none
54 [goat]
55 legs = 4
56 head = true
57 skin = false
58 nose = 1
59 horns
60 EOF
63 test_expect_success 'get value for a simple key' '
64 check_config get_value case.penguin "very blue"
67 test_expect_success 'get value for a key with value as an empty string' '
68 check_config get_value case.my ""
71 test_expect_success 'get value for a key with value as NULL' '
72 check_config get_value case.foo "(NULL)"
75 test_expect_success 'upper case key' '
76 check_config get_value case.UPPERCASE "true" &&
77 check_config get_value case.uppercase "true"
80 test_expect_success 'mixed case key' '
81 check_config get_value case.MixedCase "true" &&
82 check_config get_value case.MIXEDCASE "true" &&
83 check_config get_value case.mixedcase "true"
86 test_expect_success 'key and value with mixed case' '
87 check_config get_value case.Movie "BadPhysics"
90 test_expect_success 'key with case sensitive subsection' '
91 check_config get_value "my.Foo bAr.hi" "mixed-case" &&
92 check_config get_value "my.FOO BAR.hi" "upper-case" &&
93 check_config get_value "my.foo bar.hi" "lower-case"
96 test_expect_success 'key with case insensitive section header' '
97 check_config get_value cores.baz "ball" &&
98 check_config get_value Cores.baz "ball" &&
99 check_config get_value CORES.baz "ball" &&
100 check_config get_value coreS.baz "ball"
103 test_expect_success 'key with case insensitive section header & variable' '
104 check_config get_value CORES.BAZ "ball" &&
105 check_config get_value cores.baz "ball" &&
106 check_config get_value cores.BaZ "ball" &&
107 check_config get_value cOreS.bAz "ball"
110 test_expect_success 'find value with misspelled key' '
111 check_config expect_code 1 get_value "my.fOo Bar.hi" "Value not found for \"my.fOo Bar.hi\""
114 test_expect_success 'find value with the highest priority' '
115 check_config get_value case.baz "hask"
118 test_expect_success 'find integer value for a key' '
119 check_config get_int lamb.chop 65
122 test_expect_success 'find integer if value is non parse-able' '
123 check_config expect_code 128 get_int lamb.head
126 test_expect_success 'find bool value for the entered key' '
127 check_config get_bool goat.head 1 &&
128 check_config get_bool goat.skin 0 &&
129 check_config get_bool goat.nose 1 &&
130 check_config get_bool goat.horns 1 &&
131 check_config get_bool goat.legs 1
134 test_expect_success 'find multiple values' '
135 check_config get_value_multi case.baz sam bat hask
138 test_expect_success 'find value from a configset' '
139 cat >config2 <<-\EOF &&
140 [case]
141 baz = lama
142 [my]
143 new = silk
144 [case]
145 baz = ball
147 echo silk >expect &&
148 test-config configset_get_value my.new config2 .git/config >actual &&
149 test_cmp expect actual
152 test_expect_success 'find value with highest priority from a configset' '
153 echo hask >expect &&
154 test-config configset_get_value case.baz config2 .git/config >actual &&
155 test_cmp expect actual
158 test_expect_success 'find value_list for a key from a configset' '
159 cat >except <<-\EOF &&
162 hask
163 lama
164 ball
166 test-config configset_get_value case.baz config2 .git/config >actual &&
167 test_cmp expect actual
170 test_expect_success 'proper error on non-existent files' '
171 echo "Error (-1) reading configuration file non-existent-file." >expect &&
172 test_expect_code 2 test-config configset_get_value foo.bar non-existent-file 2>actual &&
173 test_cmp expect actual
176 test_expect_success POSIXPERM,SANITY 'proper error on non-accessible files' '
177 chmod -r .git/config &&
178 test_when_finished "chmod +r .git/config" &&
179 echo "Error (-1) reading configuration file .git/config." >expect &&
180 test_expect_code 2 test-config configset_get_value foo.bar .git/config 2>actual &&
181 test_cmp expect actual
184 test_expect_success 'proper error on error in default config files' '
185 cp .git/config .git/config.old &&
186 test_when_finished "mv .git/config.old .git/config" &&
187 echo "[" >>.git/config &&
188 echo "fatal: bad config file line 35 in .git/config" >expect &&
189 test_expect_code 128 test-config get_value foo.bar 2>actual &&
190 test_cmp expect actual
193 test_expect_success 'proper error on error in custom config files' '
194 echo "[" >>syntax-error &&
195 echo "fatal: bad config file line 1 in syntax-error" >expect &&
196 test_expect_code 128 test-config configset_get_value foo.bar syntax-error 2>actual &&
197 test_cmp expect actual
200 test_done