mirror of
https://github.com/git-for-windows/git.git
synced 2026-06-19 07:12:51 -05:00
Replace bare grep with test_grep in test assertions across the
suite, including sourced test helpers (lib-*.sh, *-tests.sh).
test_grep prints the contents of the file being searched on
failure, making debugging easier than a bare grep which fails
silently.
Only assertion-style greps are converted: grep used as a filter
in pipelines, command substitutions, conditionals, or with
redirected I/O is left as-is with a "# lint-ok" annotation.
Existing '! test_grep' calls are rewritten to 'test_grep !' so
that the diagnostic output is preserved on failure.
The conversion was generated using a grep-assertion linter
(greplint.pl, added in the following commit) to identify bare
grep calls at command position. To reproduce:
# Step 1: mark bare greps that should not be converted
sed -i '/! grep "$m" \.git\/packed-refs/s/$/ # lint-ok: file may not exist (reftable)/' \
t/t1400-update-ref.sh
sed -i '/! grep dirty file3 &&/{/lint-ok/!s/$/ # lint-ok: file may not exist after --quit/}' \
t/t3420-rebase-autostash.sh
sed -i '/grep -vf before commits\.raw/s/$/ # lint-ok: data filter/' \
t/t5326-multi-pack-bitmaps.sh
sed -i '/! grep $d shallow-client\/\.git\/shallow/s/$/ # lint-ok: file may not exist after repack/' \
t/t5537-fetch-shallow.sh
sed -i '/grep -E "^\[0-9a-f\].*|| :/s/$/ # lint-ok: data filter/' \
t/t5702-protocol-v2.sh
sed -i '/! grep gitdir squatting-clone/s/$/ # lint-ok: file may not exist after failed clone/' \
t/t7450-bad-git-dotfiles.sh
# Step 2: reorder pre-existing '! test_grep' to 'test_grep !'
# (must come before steps 3-4 so greplint does not see them)
sed -i 's/! test_grep/test_grep !/' t/t0031-lockfile-pid.sh
sed -i 's/! test_grep/test_grep !/' t/t5300-pack-object.sh
sed -i 's/! test_grep/test_grep !/' t/t5319-multi-pack-index.sh
# Step 3: convert '! grep' -> 'test_grep !'
perl t/greplint.pl t/*.sh 2>&1 | cut -d: -f1,2 |
while IFS=: read f l; do
sed -i "${l}s/! *grep/test_grep !/" "$f"
done
# Step 4: convert remaining 'grep' -> 'test_grep'
perl t/greplint.pl t/*.sh 2>&1 | cut -d: -f1,2 |
while IFS=: read f l; do
sed -i "${l}s/grep/test_grep/" "$f"
done
To verify, run: make -C t test-greplint
Signed-off-by: Michael Montalbo <mmontalbo@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
109 lines
4.1 KiB
Bash
Executable File
109 lines
4.1 KiB
Bash
Executable File
#!/bin/sh
|
|
#
|
|
# Copyright (c) 2010 Ævar Arnfjörð Bjarmason
|
|
#
|
|
|
|
test_description='Gettext support for Git'
|
|
|
|
. ./lib-gettext.sh
|
|
|
|
test_expect_success "sanity: \$GIT_INTERNAL_GETTEXT_SH_SCHEME is set (to $GIT_INTERNAL_GETTEXT_SH_SCHEME)" '
|
|
test -n "$GIT_INTERNAL_GETTEXT_SH_SCHEME"
|
|
'
|
|
|
|
test_expect_success 'sanity: $TEXTDOMAIN is git' '
|
|
test $TEXTDOMAIN = "git"
|
|
'
|
|
|
|
test_expect_success 'xgettext sanity: Perl _() strings are not extracted' '
|
|
test_grep ! "A Perl string xgettext will not get" "$GIT_PO_PATH"/is.po
|
|
'
|
|
|
|
test_expect_success 'xgettext sanity: Comment extraction with --add-comments' '
|
|
grep "TRANSLATORS: This is a test" "$TEST_DIRECTORY"/t0200/* | wc -l >expect &&
|
|
grep "TRANSLATORS: This is a test" "$GIT_PO_PATH"/is.po | wc -l >actual &&
|
|
test_cmp expect actual
|
|
'
|
|
|
|
test_expect_success 'xgettext sanity: Comment extraction with --add-comments stops at statements' '
|
|
test_grep ! "This is a phony" "$GIT_PO_PATH"/is.po &&
|
|
test_grep ! "the above comment" "$GIT_PO_PATH"/is.po
|
|
'
|
|
|
|
test_expect_success GETTEXT 'sanity: $TEXTDOMAINDIR exists without NO_GETTEXT=YesPlease' '
|
|
test -d "$TEXTDOMAINDIR" &&
|
|
test "$TEXTDOMAINDIR" = "$GIT_TEXTDOMAINDIR"
|
|
'
|
|
|
|
test_expect_success GETTEXT 'sanity: Icelandic locale was compiled' '
|
|
test -f "$TEXTDOMAINDIR/is/LC_MESSAGES/git.mo"
|
|
'
|
|
|
|
# TODO: When we have more locales, generalize this to test them
|
|
# all. Maybe we'll need a dir->locale map for that.
|
|
test_expect_success GETTEXT_LOCALE 'sanity: gettext("") metadata is OK' '
|
|
# Return value may be non-zero
|
|
LANGUAGE=is LC_ALL="$is_IS_locale" gettext "" >zero-expect &&
|
|
test_grep "Project-Id-Version: Git" zero-expect &&
|
|
test_grep "Git Mailing List <git@vger.kernel.org>" zero-expect &&
|
|
test_grep "Content-Type: text/plain; charset=UTF-8" zero-expect &&
|
|
test_grep "Content-Transfer-Encoding: 8bit" zero-expect
|
|
'
|
|
|
|
test_expect_success GETTEXT_LOCALE 'sanity: gettext(unknown) is passed through' '
|
|
printf "This is not a translation string" >expect &&
|
|
gettext "This is not a translation string" >actual &&
|
|
eval_gettext "This is not a translation string" >actual &&
|
|
test_cmp expect actual
|
|
'
|
|
|
|
# xgettext from C
|
|
test_expect_success GETTEXT_LOCALE 'xgettext: C extraction of _() and N_() strings' '
|
|
printf "TILRAUN: C tilraunastrengur" >expect &&
|
|
printf "\n" >>expect &&
|
|
printf "Sjá '\''git help SKIPUN'\'' til að sjá hjálp fyrir tiltekna skipun." >>expect &&
|
|
LANGUAGE=is LC_ALL="$is_IS_locale" gettext "TEST: A C test string" >actual &&
|
|
printf "\n" >>actual &&
|
|
LANGUAGE=is LC_ALL="$is_IS_locale" gettext "See '\''git help COMMAND'\'' for more information on a specific command." >>actual &&
|
|
test_cmp expect actual
|
|
'
|
|
|
|
test_expect_success GETTEXT_LOCALE 'xgettext: C extraction with %s' '
|
|
printf "TILRAUN: C tilraunastrengur %%s" >expect &&
|
|
LANGUAGE=is LC_ALL="$is_IS_locale" gettext "TEST: A C test string %s" >actual &&
|
|
test_cmp expect actual
|
|
'
|
|
|
|
# xgettext from Shell
|
|
test_expect_success GETTEXT_LOCALE 'xgettext: Shell extraction' '
|
|
printf "TILRAUN: Skeljartilraunastrengur" >expect &&
|
|
LANGUAGE=is LC_ALL="$is_IS_locale" gettext "TEST: A Shell test string" >actual &&
|
|
test_cmp expect actual
|
|
'
|
|
|
|
test_expect_success GETTEXT_LOCALE 'xgettext: Shell extraction with $variable' '
|
|
printf "TILRAUN: Skeljartilraunastrengur með breytunni a var i able" >x-expect &&
|
|
LANGUAGE=is LC_ALL="$is_IS_locale" variable="a var i able" eval_gettext "TEST: A Shell test \$variable" >x-actual &&
|
|
test_cmp x-expect x-actual
|
|
'
|
|
|
|
# xgettext from Perl
|
|
test_expect_success GETTEXT_LOCALE 'xgettext: Perl extraction' '
|
|
printf "TILRAUN: Perl tilraunastrengur" >expect &&
|
|
LANGUAGE=is LC_ALL="$is_IS_locale" gettext "TEST: A Perl test string" >actual &&
|
|
test_cmp expect actual
|
|
'
|
|
|
|
test_expect_success GETTEXT_LOCALE 'xgettext: Perl extraction with %s' '
|
|
printf "TILRAUN: Perl tilraunastrengur með breytunni %%s" >expect &&
|
|
LANGUAGE=is LC_ALL="$is_IS_locale" gettext "TEST: A Perl test variable %s" >actual &&
|
|
test_cmp expect actual
|
|
'
|
|
|
|
test_expect_success GETTEXT_LOCALE 'sanity: Some gettext("") data for real locale' '
|
|
LANGUAGE=is LC_ALL="$is_IS_locale" gettext "" >real-locale &&
|
|
test -s real-locale
|
|
'
|
|
|
|
test_done
|