]>
Commit | Line | Data |
---|---|---|
b4f207f3 ÆAB |
1 | #!/bin/sh |
2 | ||
3 | test_description='test env--helper' | |
4 | ||
956d2e46 | 5 | TEST_PASSES_SANITIZE_LEAK=true |
b4f207f3 ÆAB |
6 | . ./test-lib.sh |
7 | ||
8 | ||
9 | test_expect_success 'env--helper usage' ' | |
10 | test_must_fail git env--helper && | |
11 | test_must_fail git env--helper --type=bool && | |
12 | test_must_fail git env--helper --type=ulong && | |
13 | test_must_fail git env--helper --type=bool && | |
14 | test_must_fail git env--helper --type=bool --default && | |
15 | test_must_fail git env--helper --type=bool --default= && | |
16 | test_must_fail git env--helper --defaultxyz | |
17 | ' | |
18 | ||
19 | test_expect_success 'env--helper bad default values' ' | |
20 | test_must_fail git env--helper --type=bool --default=1xyz MISSING && | |
21 | test_must_fail git env--helper --type=ulong --default=1xyz MISSING | |
22 | ' | |
23 | ||
24 | test_expect_success 'env--helper --type=bool' ' | |
25 | # Test various --default bool values | |
26 | echo true >expected && | |
27 | git env--helper --type=bool --default=1 MISSING >actual && | |
28 | test_cmp expected actual && | |
29 | git env--helper --type=bool --default=yes MISSING >actual && | |
30 | test_cmp expected actual && | |
31 | git env--helper --type=bool --default=true MISSING >actual && | |
32 | test_cmp expected actual && | |
33 | echo false >expected && | |
34 | test_must_fail git env--helper --type=bool --default=0 MISSING >actual && | |
35 | test_cmp expected actual && | |
36 | test_must_fail git env--helper --type=bool --default=no MISSING >actual && | |
37 | test_cmp expected actual && | |
38 | test_must_fail git env--helper --type=bool --default=false MISSING >actual && | |
39 | test_cmp expected actual && | |
40 | ||
41 | # No output with --exit-code | |
42 | git env--helper --type=bool --default=true --exit-code MISSING >actual.out 2>actual.err && | |
43 | test_must_be_empty actual.out && | |
44 | test_must_be_empty actual.err && | |
45 | test_must_fail git env--helper --type=bool --default=false --exit-code MISSING >actual.out 2>actual.err && | |
46 | test_must_be_empty actual.out && | |
47 | test_must_be_empty actual.err && | |
48 | ||
49 | # Existing variable | |
50 | EXISTS=true git env--helper --type=bool --default=false --exit-code EXISTS >actual.out 2>actual.err && | |
51 | test_must_be_empty actual.out && | |
52 | test_must_be_empty actual.err && | |
53 | test_must_fail \ | |
54 | env EXISTS=false \ | |
55 | git env--helper --type=bool --default=true --exit-code EXISTS >actual.out 2>actual.err && | |
56 | test_must_be_empty actual.out && | |
57 | test_must_be_empty actual.err | |
58 | ' | |
59 | ||
60 | test_expect_success 'env--helper --type=ulong' ' | |
61 | echo 1234567890 >expected && | |
62 | git env--helper --type=ulong --default=1234567890 MISSING >actual.out 2>actual.err && | |
63 | test_cmp expected actual.out && | |
64 | test_must_be_empty actual.err && | |
65 | ||
66 | echo 0 >expected && | |
67 | test_must_fail git env--helper --type=ulong --default=0 MISSING >actual && | |
68 | test_cmp expected actual && | |
69 | ||
70 | git env--helper --type=ulong --default=1234567890 --exit-code MISSING >actual.out 2>actual.err && | |
71 | test_must_be_empty actual.out && | |
72 | test_must_be_empty actual.err && | |
73 | ||
74 | EXISTS=1234567890 git env--helper --type=ulong --default=0 EXISTS --exit-code >actual.out 2>actual.err && | |
75 | test_must_be_empty actual.out && | |
76 | test_must_be_empty actual.err && | |
77 | ||
78 | echo 1234567890 >expected && | |
79 | EXISTS=1234567890 git env--helper --type=ulong --default=0 EXISTS >actual.out 2>actual.err && | |
80 | test_cmp expected actual.out && | |
81 | test_must_be_empty actual.err | |
82 | ' | |
83 | ||
1ff750b1 ÆAB |
84 | test_expect_success 'env--helper reads config thanks to trace2' ' |
85 | mkdir home && | |
86 | git config -f home/.gitconfig include.path cycle && | |
87 | git config -f home/cycle include.path .gitconfig && | |
88 | ||
89 | test_must_fail \ | |
d162b25f | 90 | env HOME="$(pwd)/home" \ |
1ff750b1 ÆAB |
91 | git config -l 2>err && |
92 | grep "exceeded maximum include depth" err && | |
93 | ||
94 | test_must_fail \ | |
d162b25f ÆAB |
95 | env HOME="$(pwd)/home" GIT_TEST_ENV_HELPER=true \ |
96 | git -C cycle env--helper --type=bool --default=0 --exit-code GIT_TEST_ENV_HELPER 2>err && | |
97 | grep "exceeded maximum include depth" err | |
1ff750b1 ÆAB |
98 | ' |
99 | ||
b4f207f3 | 100 | test_done |