use strpbrk(3) to search for characters from a given set
[git/debian.git] / t / t0017-env-helper.sh
blobc1ecf6aeac672056613c558fd27daaf6337ac1a6
1 #!/bin/sh
3 test_description='test env--helper'
5 . ./test-lib.sh
8 test_expect_success 'env--helper usage' '
9 test_must_fail git env--helper &&
10 test_must_fail git env--helper --type=bool &&
11 test_must_fail git env--helper --type=ulong &&
12 test_must_fail git env--helper --type=bool &&
13 test_must_fail git env--helper --type=bool --default &&
14 test_must_fail git env--helper --type=bool --default= &&
15 test_must_fail git env--helper --defaultxyz
18 test_expect_success 'env--helper bad default values' '
19 test_must_fail git env--helper --type=bool --default=1xyz MISSING &&
20 test_must_fail git env--helper --type=ulong --default=1xyz MISSING
23 test_expect_success 'env--helper --type=bool' '
24 # Test various --default bool values
25 echo true >expected &&
26 git env--helper --type=bool --default=1 MISSING >actual &&
27 test_cmp expected actual &&
28 git env--helper --type=bool --default=yes MISSING >actual &&
29 test_cmp expected actual &&
30 git env--helper --type=bool --default=true MISSING >actual &&
31 test_cmp expected actual &&
32 echo false >expected &&
33 test_must_fail git env--helper --type=bool --default=0 MISSING >actual &&
34 test_cmp expected actual &&
35 test_must_fail git env--helper --type=bool --default=no MISSING >actual &&
36 test_cmp expected actual &&
37 test_must_fail git env--helper --type=bool --default=false MISSING >actual &&
38 test_cmp expected actual &&
40 # No output with --exit-code
41 git env--helper --type=bool --default=true --exit-code MISSING >actual.out 2>actual.err &&
42 test_must_be_empty actual.out &&
43 test_must_be_empty actual.err &&
44 test_must_fail git env--helper --type=bool --default=false --exit-code MISSING >actual.out 2>actual.err &&
45 test_must_be_empty actual.out &&
46 test_must_be_empty actual.err &&
48 # Existing variable
49 EXISTS=true git env--helper --type=bool --default=false --exit-code EXISTS >actual.out 2>actual.err &&
50 test_must_be_empty actual.out &&
51 test_must_be_empty actual.err &&
52 test_must_fail \
53 env EXISTS=false \
54 git env--helper --type=bool --default=true --exit-code EXISTS >actual.out 2>actual.err &&
55 test_must_be_empty actual.out &&
56 test_must_be_empty actual.err
59 test_expect_success 'env--helper --type=ulong' '
60 echo 1234567890 >expected &&
61 git env--helper --type=ulong --default=1234567890 MISSING >actual.out 2>actual.err &&
62 test_cmp expected actual.out &&
63 test_must_be_empty actual.err &&
65 echo 0 >expected &&
66 test_must_fail git env--helper --type=ulong --default=0 MISSING >actual &&
67 test_cmp expected actual &&
69 git env--helper --type=ulong --default=1234567890 --exit-code MISSING >actual.out 2>actual.err &&
70 test_must_be_empty actual.out &&
71 test_must_be_empty actual.err &&
73 EXISTS=1234567890 git env--helper --type=ulong --default=0 EXISTS --exit-code >actual.out 2>actual.err &&
74 test_must_be_empty actual.out &&
75 test_must_be_empty actual.err &&
77 echo 1234567890 >expected &&
78 EXISTS=1234567890 git env--helper --type=ulong --default=0 EXISTS >actual.out 2>actual.err &&
79 test_cmp expected actual.out &&
80 test_must_be_empty actual.err
83 test_expect_success 'env--helper reads config thanks to trace2' '
84 mkdir home &&
85 git config -f home/.gitconfig include.path cycle &&
86 git config -f home/cycle include.path .gitconfig &&
88 test_must_fail \
89 env HOME="$(pwd)/home" GIT_TEST_GETTEXT_POISON=false \
90 git config -l 2>err &&
91 grep "exceeded maximum include depth" err &&
93 test_must_fail \
94 env HOME="$(pwd)/home" GIT_TEST_GETTEXT_POISON=true \
95 git -C cycle env--helper --type=bool --default=0 --exit-code GIT_TEST_GETTEXT_POISON 2>err &&
96 grep "# GETTEXT POISON #" err
99 test_done