rebase: use correct base for --keep-base when a branch is given
[alt-git.git] / t / t0017-env-helper.sh
blob2e42fba9567d5b35bf72eda214d336a7c3564566
1 #!/bin/sh
3 test_description='test env--helper'
5 TEST_PASSES_SANITIZE_LEAK=true
6 . ./test-lib.sh
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
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
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 &&
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 &&
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
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 &&
66 echo 0 >expected &&
67 test_must_fail git env--helper --type=ulong --default=0 MISSING >actual &&
68 test_cmp expected actual &&
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 &&
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 &&
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
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 &&
89 test_must_fail \
90 env HOME="$(pwd)/home" \
91 git config -l 2>err &&
92 grep "exceeded maximum include depth" err &&
94 test_must_fail \
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
100 test_done