##// END OF EJS Templates
tests: conditionalize return code on chg in test-config.t...
Pulkit Goyal -
r46604:60523483 default
parent child Browse files
Show More
@@ -1,390 +1,414 b''
1 1 hide outer repo
2 2 $ hg init
3 3
4 4 Invalid syntax: no value
5 5
6 6 $ cat > .hg/hgrc << EOF
7 7 > novaluekey
8 8 > EOF
9 #if chg
10 $ hg showconfig
11 config error at $TESTTMP/.hg/hgrc:1: novaluekey
12 [255]
13 #else
9 14 $ hg showconfig
10 15 config error at $TESTTMP/.hg/hgrc:1: novaluekey
11 16 [30]
17 #endif
12 18
13 19 Invalid syntax: no key
14 20
15 21 $ cat > .hg/hgrc << EOF
16 22 > =nokeyvalue
17 23 > EOF
24 #if chg
25 $ hg showconfig
26 config error at $TESTTMP/.hg/hgrc:1: =nokeyvalue
27 [255]
28 #else
18 29 $ hg showconfig
19 30 config error at $TESTTMP/.hg/hgrc:1: =nokeyvalue
20 31 [30]
32 #endif
21 33
22 34 Test hint about invalid syntax from leading white space
23 35
24 36 $ cat > .hg/hgrc << EOF
25 37 > key=value
26 38 > EOF
39 #if chg
40 $ hg showconfig
41 config error at $TESTTMP/.hg/hgrc:1: unexpected leading whitespace: key=value
42 [255]
43 #else
27 44 $ hg showconfig
28 45 config error at $TESTTMP/.hg/hgrc:1: unexpected leading whitespace: key=value
29 46 [30]
47 #endif
30 48
31 49 $ cat > .hg/hgrc << EOF
32 50 > [section]
33 51 > key=value
34 52 > EOF
53 #if chg
54 $ hg showconfig
55 config error at $TESTTMP/.hg/hgrc:1: unexpected leading whitespace: [section]
56 [255]
57 #else
35 58 $ hg showconfig
36 59 config error at $TESTTMP/.hg/hgrc:1: unexpected leading whitespace: [section]
37 60 [30]
61 #endif
38 62
39 63 Reset hgrc
40 64
41 65 $ echo > .hg/hgrc
42 66
43 67 Test case sensitive configuration
44 68
45 69 $ cat <<EOF >> $HGRCPATH
46 70 > [Section]
47 71 > KeY = Case Sensitive
48 72 > key = lower case
49 73 > EOF
50 74
51 75 $ hg showconfig Section
52 76 Section.KeY=Case Sensitive
53 77 Section.key=lower case
54 78
55 79 $ hg showconfig Section -Tjson
56 80 [
57 81 {
58 82 "defaultvalue": null,
59 83 "name": "Section.KeY",
60 84 "source": "*.hgrc:*", (glob)
61 85 "value": "Case Sensitive"
62 86 },
63 87 {
64 88 "defaultvalue": null,
65 89 "name": "Section.key",
66 90 "source": "*.hgrc:*", (glob)
67 91 "value": "lower case"
68 92 }
69 93 ]
70 94 $ hg showconfig Section.KeY -Tjson
71 95 [
72 96 {
73 97 "defaultvalue": null,
74 98 "name": "Section.KeY",
75 99 "source": "*.hgrc:*", (glob)
76 100 "value": "Case Sensitive"
77 101 }
78 102 ]
79 103 $ hg showconfig -Tjson | tail -7
80 104 {
81 105 "defaultvalue": null,
82 106 "name": "*", (glob)
83 107 "source": "*", (glob)
84 108 "value": "*" (glob)
85 109 }
86 110 ]
87 111
88 112 Test config default of various types:
89 113
90 114 {"defaultvalue": ""} for -T'json(defaultvalue)' looks weird, but that's
91 115 how the templater works. Unknown keywords are evaluated to "".
92 116
93 117 dynamicdefault
94 118
95 119 $ hg config --config alias.foo= alias -Tjson
96 120 [
97 121 {
98 122 "name": "alias.foo",
99 123 "source": "--config",
100 124 "value": ""
101 125 }
102 126 ]
103 127 $ hg config --config alias.foo= alias -T'json(defaultvalue)'
104 128 [
105 129 {"defaultvalue": ""}
106 130 ]
107 131 $ hg config --config alias.foo= alias -T'{defaultvalue}\n'
108 132
109 133
110 134 null
111 135
112 136 $ hg config --config auth.cookiefile= auth -Tjson
113 137 [
114 138 {
115 139 "defaultvalue": null,
116 140 "name": "auth.cookiefile",
117 141 "source": "--config",
118 142 "value": ""
119 143 }
120 144 ]
121 145 $ hg config --config auth.cookiefile= auth -T'json(defaultvalue)'
122 146 [
123 147 {"defaultvalue": null}
124 148 ]
125 149 $ hg config --config auth.cookiefile= auth -T'{defaultvalue}\n'
126 150
127 151
128 152 false
129 153
130 154 $ hg config --config commands.commit.post-status= commands -Tjson
131 155 [
132 156 {
133 157 "defaultvalue": false,
134 158 "name": "commands.commit.post-status",
135 159 "source": "--config",
136 160 "value": ""
137 161 }
138 162 ]
139 163 $ hg config --config commands.commit.post-status= commands -T'json(defaultvalue)'
140 164 [
141 165 {"defaultvalue": false}
142 166 ]
143 167 $ hg config --config commands.commit.post-status= commands -T'{defaultvalue}\n'
144 168 False
145 169
146 170 true
147 171
148 172 $ hg config --config format.dotencode= format -Tjson
149 173 [
150 174 {
151 175 "defaultvalue": true,
152 176 "name": "format.dotencode",
153 177 "source": "--config",
154 178 "value": ""
155 179 }
156 180 ]
157 181 $ hg config --config format.dotencode= format -T'json(defaultvalue)'
158 182 [
159 183 {"defaultvalue": true}
160 184 ]
161 185 $ hg config --config format.dotencode= format -T'{defaultvalue}\n'
162 186 True
163 187
164 188 bytes
165 189
166 190 $ hg config --config commands.resolve.mark-check= commands -Tjson
167 191 [
168 192 {
169 193 "defaultvalue": "none",
170 194 "name": "commands.resolve.mark-check",
171 195 "source": "--config",
172 196 "value": ""
173 197 }
174 198 ]
175 199 $ hg config --config commands.resolve.mark-check= commands -T'json(defaultvalue)'
176 200 [
177 201 {"defaultvalue": "none"}
178 202 ]
179 203 $ hg config --config commands.resolve.mark-check= commands -T'{defaultvalue}\n'
180 204 none
181 205
182 206 empty list
183 207
184 208 $ hg config --config commands.show.aliasprefix= commands -Tjson
185 209 [
186 210 {
187 211 "defaultvalue": [],
188 212 "name": "commands.show.aliasprefix",
189 213 "source": "--config",
190 214 "value": ""
191 215 }
192 216 ]
193 217 $ hg config --config commands.show.aliasprefix= commands -T'json(defaultvalue)'
194 218 [
195 219 {"defaultvalue": []}
196 220 ]
197 221 $ hg config --config commands.show.aliasprefix= commands -T'{defaultvalue}\n'
198 222
199 223
200 224 nonempty list
201 225
202 226 $ hg config --config progress.format= progress -Tjson
203 227 [
204 228 {
205 229 "defaultvalue": ["topic", "bar", "number", "estimate"],
206 230 "name": "progress.format",
207 231 "source": "--config",
208 232 "value": ""
209 233 }
210 234 ]
211 235 $ hg config --config progress.format= progress -T'json(defaultvalue)'
212 236 [
213 237 {"defaultvalue": ["topic", "bar", "number", "estimate"]}
214 238 ]
215 239 $ hg config --config progress.format= progress -T'{defaultvalue}\n'
216 240 topic bar number estimate
217 241
218 242 int
219 243
220 244 $ hg config --config profiling.freq= profiling -Tjson
221 245 [
222 246 {
223 247 "defaultvalue": 1000,
224 248 "name": "profiling.freq",
225 249 "source": "--config",
226 250 "value": ""
227 251 }
228 252 ]
229 253 $ hg config --config profiling.freq= profiling -T'json(defaultvalue)'
230 254 [
231 255 {"defaultvalue": 1000}
232 256 ]
233 257 $ hg config --config profiling.freq= profiling -T'{defaultvalue}\n'
234 258 1000
235 259
236 260 float
237 261
238 262 $ hg config --config profiling.showmax= profiling -Tjson
239 263 [
240 264 {
241 265 "defaultvalue": 0.999,
242 266 "name": "profiling.showmax",
243 267 "source": "--config",
244 268 "value": ""
245 269 }
246 270 ]
247 271 $ hg config --config profiling.showmax= profiling -T'json(defaultvalue)'
248 272 [
249 273 {"defaultvalue": 0.999}
250 274 ]
251 275 $ hg config --config profiling.showmax= profiling -T'{defaultvalue}\n'
252 276 0.999
253 277
254 278 Test empty config source:
255 279
256 280 $ cat <<EOF > emptysource.py
257 281 > def reposetup(ui, repo):
258 282 > ui.setconfig(b'empty', b'source', b'value')
259 283 > EOF
260 284 $ cp .hg/hgrc .hg/hgrc.orig
261 285 $ cat <<EOF >> .hg/hgrc
262 286 > [extensions]
263 287 > emptysource = `pwd`/emptysource.py
264 288 > EOF
265 289
266 290 $ hg config --debug empty.source
267 291 read config from: * (glob)
268 292 none: value
269 293 $ hg config empty.source -Tjson
270 294 [
271 295 {
272 296 "defaultvalue": null,
273 297 "name": "empty.source",
274 298 "source": "",
275 299 "value": "value"
276 300 }
277 301 ]
278 302
279 303 $ cp .hg/hgrc.orig .hg/hgrc
280 304
281 305 Test "%unset"
282 306
283 307 $ cat >> $HGRCPATH <<EOF
284 308 > [unsettest]
285 309 > local-hgrcpath = should be unset (HGRCPATH)
286 310 > %unset local-hgrcpath
287 311 >
288 312 > global = should be unset (HGRCPATH)
289 313 >
290 314 > both = should be unset (HGRCPATH)
291 315 >
292 316 > set-after-unset = should be unset (HGRCPATH)
293 317 > EOF
294 318
295 319 $ cat >> .hg/hgrc <<EOF
296 320 > [unsettest]
297 321 > local-hgrc = should be unset (.hg/hgrc)
298 322 > %unset local-hgrc
299 323 >
300 324 > %unset global
301 325 >
302 326 > both = should be unset (.hg/hgrc)
303 327 > %unset both
304 328 >
305 329 > set-after-unset = should be unset (.hg/hgrc)
306 330 > %unset set-after-unset
307 331 > set-after-unset = should be set (.hg/hgrc)
308 332 > EOF
309 333
310 334 $ hg showconfig unsettest
311 335 unsettest.set-after-unset=should be set (.hg/hgrc)
312 336
313 337 Test exit code when no config matches
314 338
315 339 $ hg config Section.idontexist
316 340 [1]
317 341
318 342 sub-options in [paths] aren't expanded
319 343
320 344 $ cat > .hg/hgrc << EOF
321 345 > [paths]
322 346 > foo = ~/foo
323 347 > foo:suboption = ~/foo
324 348 > EOF
325 349
326 350 $ hg showconfig paths
327 351 paths.foo:suboption=~/foo
328 352 paths.foo=$TESTTMP/foo
329 353
330 354 edit failure
331 355
332 356 $ HGEDITOR=false hg config --edit
333 357 abort: edit failed: false exited with status 1
334 358 [10]
335 359
336 360 config affected by environment variables
337 361
338 362 $ EDITOR=e1 VISUAL=e2 hg config --debug | grep 'ui\.editor'
339 363 $VISUAL: ui.editor=e2
340 364
341 365 $ VISUAL=e2 hg config --debug --config ui.editor=e3 | grep 'ui\.editor'
342 366 --config: ui.editor=e3
343 367
344 368 $ PAGER=p1 hg config --debug | grep 'pager\.pager'
345 369 $PAGER: pager.pager=p1
346 370
347 371 $ PAGER=p1 hg config --debug --config pager.pager=p2 | grep 'pager\.pager'
348 372 --config: pager.pager=p2
349 373
350 374 verify that aliases are evaluated as well
351 375
352 376 $ hg init aliastest
353 377 $ cd aliastest
354 378 $ cat > .hg/hgrc << EOF
355 379 > [ui]
356 380 > user = repo user
357 381 > EOF
358 382 $ touch index
359 383 $ unset HGUSER
360 384 $ hg ci -Am test
361 385 adding index
362 386 $ hg log --template '{author}\n'
363 387 repo user
364 388 $ cd ..
365 389
366 390 alias has lower priority
367 391
368 392 $ hg init aliaspriority
369 393 $ cd aliaspriority
370 394 $ cat > .hg/hgrc << EOF
371 395 > [ui]
372 396 > user = alias user
373 397 > username = repo user
374 398 > EOF
375 399 $ touch index
376 400 $ unset HGUSER
377 401 $ hg ci -Am test
378 402 adding index
379 403 $ hg log --template '{author}\n'
380 404 repo user
381 405 $ cd ..
382 406
383 407 configs should be read in lexicographical order
384 408
385 409 $ mkdir configs
386 410 $ for i in `$TESTDIR/seq.py 10 99`; do
387 411 > printf "[section]\nkey=$i" > configs/$i.rc
388 412 > done
389 413 $ HGRCPATH=configs hg config section.key
390 414 99
General Comments 0
You need to be logged in to leave comments. Login now