mirror of
https://github.com/git/git
synced 2024-08-24 02:11:08 +00:00
![Ævar Arnfjörð Bjarmason](/assets/img/avatar_default.png)
Change the GIT_TEST_GETTEXT_POISON variable from being "non-empty?" to
being a more standard boolean variable.
Since it needed to be checked in both C code and shellscript (via test
-n) it was one of the remaining shellscript-like variables. Now that
we have "env--helper" we can change that.
There's a couple of tricky edge cases that arise because we're using
git_env_bool() early, and the config-reading "env--helper".
If GIT_TEST_GETTEXT_POISON is set to an invalid value die_bad_number()
will die, but to do so it would usually call gettext(). Let's detect
the special case of GIT_TEST_GETTEXT_POISON and always emit that
message in the C locale, lest we infinitely loop.
As seen in the updated tests in t0017-env-helper.sh there's also a
caveat related to "env--helper" needing to read the config for trace2
purposes.
Since the C_LOCALE_OUTPUT prerequisite is lazy and relies on
"env--helper" we could get invalid results if we failed to read the
config (e.g. because we'd loop on includes) when combined with
e.g. "test_i18ngrep" wanting to check with "env--helper" if
GIT_TEST_GETTEXT_POISON was true or not.
I'm crossing my fingers and hoping that a test similar to the one I
removed in the earlier "config tests: simplify include cycle test"
change in this series won't happen again, and testing for this
explicitly in "env--helper"'s own tests.
This change breaks existing uses of
e.g. GIT_TEST_GETTEXT_POISON=YesPlease, which we've documented in
po/README and other places. As noted in [1] we might want to consider
also accepting "YesPlease" in "env--helper" as a special-case.
But as the lack of uproar over 6cdccfce1e
("i18n: make GETTEXT_POISON
a runtime option", 2018-11-08) demonstrates the audience for this
option is a really narrow set of git developers, who shouldn't have
much trouble modifying their test scripts, so I think it's better to
deal with that minor headache now and make all the relevant GIT_TEST_*
variables boolean in the same way than carry the "YesPlease"
special-case forward.
1. https://public-inbox.org/git/xmqqtvckm3h8.fsf@gitster-ct.c.googlers.com/
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
100 lines
3.5 KiB
Bash
Executable file
100 lines
3.5 KiB
Bash
Executable file
#!/bin/sh
|
|
|
|
test_description='test env--helper'
|
|
|
|
. ./test-lib.sh
|
|
|
|
|
|
test_expect_success 'env--helper usage' '
|
|
test_must_fail git env--helper &&
|
|
test_must_fail git env--helper --type=bool &&
|
|
test_must_fail git env--helper --type=ulong &&
|
|
test_must_fail git env--helper --type=bool &&
|
|
test_must_fail git env--helper --type=bool --default &&
|
|
test_must_fail git env--helper --type=bool --default= &&
|
|
test_must_fail git env--helper --defaultxyz
|
|
'
|
|
|
|
test_expect_success 'env--helper bad default values' '
|
|
test_must_fail git env--helper --type=bool --default=1xyz MISSING &&
|
|
test_must_fail git env--helper --type=ulong --default=1xyz MISSING
|
|
'
|
|
|
|
test_expect_success 'env--helper --type=bool' '
|
|
# Test various --default bool values
|
|
echo true >expected &&
|
|
git env--helper --type=bool --default=1 MISSING >actual &&
|
|
test_cmp expected actual &&
|
|
git env--helper --type=bool --default=yes MISSING >actual &&
|
|
test_cmp expected actual &&
|
|
git env--helper --type=bool --default=true MISSING >actual &&
|
|
test_cmp expected actual &&
|
|
echo false >expected &&
|
|
test_must_fail git env--helper --type=bool --default=0 MISSING >actual &&
|
|
test_cmp expected actual &&
|
|
test_must_fail git env--helper --type=bool --default=no MISSING >actual &&
|
|
test_cmp expected actual &&
|
|
test_must_fail git env--helper --type=bool --default=false MISSING >actual &&
|
|
test_cmp expected actual &&
|
|
|
|
# No output with --exit-code
|
|
git env--helper --type=bool --default=true --exit-code MISSING >actual.out 2>actual.err &&
|
|
test_must_be_empty actual.out &&
|
|
test_must_be_empty actual.err &&
|
|
test_must_fail git env--helper --type=bool --default=false --exit-code MISSING >actual.out 2>actual.err &&
|
|
test_must_be_empty actual.out &&
|
|
test_must_be_empty actual.err &&
|
|
|
|
# Existing variable
|
|
EXISTS=true git env--helper --type=bool --default=false --exit-code EXISTS >actual.out 2>actual.err &&
|
|
test_must_be_empty actual.out &&
|
|
test_must_be_empty actual.err &&
|
|
test_must_fail \
|
|
env EXISTS=false \
|
|
git env--helper --type=bool --default=true --exit-code EXISTS >actual.out 2>actual.err &&
|
|
test_must_be_empty actual.out &&
|
|
test_must_be_empty actual.err
|
|
'
|
|
|
|
test_expect_success 'env--helper --type=ulong' '
|
|
echo 1234567890 >expected &&
|
|
git env--helper --type=ulong --default=1234567890 MISSING >actual.out 2>actual.err &&
|
|
test_cmp expected actual.out &&
|
|
test_must_be_empty actual.err &&
|
|
|
|
echo 0 >expected &&
|
|
test_must_fail git env--helper --type=ulong --default=0 MISSING >actual &&
|
|
test_cmp expected actual &&
|
|
|
|
git env--helper --type=ulong --default=1234567890 --exit-code MISSING >actual.out 2>actual.err &&
|
|
test_must_be_empty actual.out &&
|
|
test_must_be_empty actual.err &&
|
|
|
|
EXISTS=1234567890 git env--helper --type=ulong --default=0 EXISTS --exit-code >actual.out 2>actual.err &&
|
|
test_must_be_empty actual.out &&
|
|
test_must_be_empty actual.err &&
|
|
|
|
echo 1234567890 >expected &&
|
|
EXISTS=1234567890 git env--helper --type=ulong --default=0 EXISTS >actual.out 2>actual.err &&
|
|
test_cmp expected actual.out &&
|
|
test_must_be_empty actual.err
|
|
'
|
|
|
|
test_expect_success 'env--helper reads config thanks to trace2' '
|
|
mkdir home &&
|
|
git config -f home/.gitconfig include.path cycle &&
|
|
git config -f home/cycle include.path .gitconfig &&
|
|
|
|
test_must_fail \
|
|
env HOME="$(pwd)/home" GIT_TEST_GETTEXT_POISON=false \
|
|
git config -l 2>err &&
|
|
grep "exceeded maximum include depth" err &&
|
|
|
|
test_must_fail \
|
|
env HOME="$(pwd)/home" GIT_TEST_GETTEXT_POISON=true \
|
|
git -C cycle env--helper --type=bool --default=0 --exit-code GIT_TEST_GETTEXT_POISON 2>err &&
|
|
grep "# GETTEXT POISON #" err
|
|
'
|
|
|
|
test_done
|