Ævar Arnfjörð Bjarmason | b4f207f | 2019-06-21 12:18:06 +0200 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | |
| 3 | test_description='test env--helper' |
| 4 | |
| 5 | . ./test-lib.sh |
| 6 | |
| 7 | |
| 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 |
| 16 | ' |
| 17 | |
| 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 |
| 21 | ' |
| 22 | |
| 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 && |
| 39 | |
| 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 && |
| 47 | |
| 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 |
| 57 | ' |
| 58 | |
| 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 && |
| 64 | |
| 65 | echo 0 >expected && |
| 66 | test_must_fail git env--helper --type=ulong --default=0 MISSING >actual && |
| 67 | test_cmp expected actual && |
| 68 | |
| 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 && |
| 72 | |
| 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 && |
| 76 | |
| 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 |
| 81 | ' |
| 82 | |
Ævar Arnfjörð Bjarmason | 1ff750b | 2019-06-21 12:18:09 +0200 | [diff] [blame] | 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 && |
| 87 | |
| 88 | test_must_fail \ |
Ævar Arnfjörð Bjarmason | d162b25 | 2021-01-20 19:27:58 +0100 | [diff] [blame] | 89 | env HOME="$(pwd)/home" \ |
Ævar Arnfjörð Bjarmason | 1ff750b | 2019-06-21 12:18:09 +0200 | [diff] [blame] | 90 | git config -l 2>err && |
| 91 | grep "exceeded maximum include depth" err && |
| 92 | |
| 93 | test_must_fail \ |
Ævar Arnfjörð Bjarmason | d162b25 | 2021-01-20 19:27:58 +0100 | [diff] [blame] | 94 | env HOME="$(pwd)/home" GIT_TEST_ENV_HELPER=true \ |
| 95 | git -C cycle env--helper --type=bool --default=0 --exit-code GIT_TEST_ENV_HELPER 2>err && |
| 96 | grep "exceeded maximum include depth" err |
Ævar Arnfjörð Bjarmason | 1ff750b | 2019-06-21 12:18:09 +0200 | [diff] [blame] | 97 | ' |
| 98 | |
Ævar Arnfjörð Bjarmason | b4f207f | 2019-06-21 12:18:06 +0200 | [diff] [blame] | 99 | test_done |