tests: use test_i18n* functions to suppress false positives

The test functions test_i18ncmp and test_i18ngrep pretend success if run
under GETTEXT_POISON. By using those functions to test output which is
correctly marked as translatable, enables one to detect if the strings
newly marked for translation are from plumbing output. If they are
indeed from plumbing, the test would fail, and the string should be
unmarked, since it is not seen by users.

Thus, it is productive to not have false positives when running the test
under GETTEXT_POISON. This commit replaces normal test functions by
their i18n aware variants in use-cases know to be correctly marked for
translation, suppressing false positives.

Signed-off-by: Vasco Almeida <vascomalmeida@sapo.pt>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Vasco Almeida 2016-06-17 20:21:07 +00:00 committed by Junio C Hamano
parent ab33a76ec5
commit 1edbaac3bb
21 changed files with 41 additions and 44 deletions

View file

@ -34,7 +34,7 @@ expect_from_stdin () {
test_stderr () { test_stderr () {
expected="$1" expected="$1"
expect_in stderr "$1" && expect_in stderr "$1" &&
test_cmp "$HOME/expected-stderr" "$HOME/stderr" test_i18ncmp "$HOME/expected-stderr" "$HOME/stderr"
} }
broken_c_unquote () { broken_c_unquote () {
@ -47,7 +47,7 @@ broken_c_unquote_verbose () {
stderr_contains () { stderr_contains () {
regexp="$1" regexp="$1"
if grep "$regexp" "$HOME/stderr" if test_i18ngrep "$regexp" "$HOME/stderr"
then then
return 0 return 0
else else

View file

@ -886,7 +886,7 @@ test_expect_success !MINGW 'get --path copes with unset $HOME' '
git config --get --path path.normal >>result && git config --get --path path.normal >>result &&
git config --get --path path.trailingtilde >>result git config --get --path path.trailingtilde >>result
) && ) &&
grep "[Ff]ailed to expand.*~/" msg && test_i18ngrep "[Ff]ailed to expand.*~/" msg &&
test_cmp expect result test_cmp expect result
' '
@ -1126,7 +1126,7 @@ test_expect_success 'barf on syntax error' '
key garbage key garbage
EOF EOF
test_must_fail git config --get section.key >actual 2>error && test_must_fail git config --get section.key >actual 2>error &&
grep " line 3 " error test_i18ngrep " line 3 " error
' '
test_expect_success 'barf on incomplete section header' ' test_expect_success 'barf on incomplete section header' '
@ -1136,7 +1136,7 @@ test_expect_success 'barf on incomplete section header' '
key = value key = value
EOF EOF
test_must_fail git config --get section.key >actual 2>error && test_must_fail git config --get section.key >actual 2>error &&
grep " line 2 " error test_i18ngrep " line 2 " error
' '
test_expect_success 'barf on incomplete string' ' test_expect_success 'barf on incomplete string' '
@ -1146,7 +1146,7 @@ test_expect_success 'barf on incomplete string' '
key = "value string key = "value string
EOF EOF
test_must_fail git config --get section.key >actual 2>error && test_must_fail git config --get section.key >actual 2>error &&
grep " line 3 " error test_i18ngrep " line 3 " error
' '
test_expect_success 'urlmatch' ' test_expect_success 'urlmatch' '

View file

@ -61,10 +61,7 @@ test_expect_success 'parse errors in blobs are properly attributed' '
git commit -m broken && git commit -m broken &&
test_must_fail git config --blob=HEAD:config some.value 2>err && test_must_fail git config --blob=HEAD:config some.value 2>err &&
test_i18ngrep "HEAD:config" err
# just grep for our token as the exact error message is likely to
# change or be internationalized
grep "HEAD:config" err
' '
test_expect_success 'can parse blob ending with CR' ' test_expect_success 'can parse blob ending with CR' '

View file

@ -197,14 +197,14 @@ test_expect_success 'proper error on error in default config files' '
echo "[" >>.git/config && echo "[" >>.git/config &&
echo "fatal: bad config line 34 in file .git/config" >expect && echo "fatal: bad config line 34 in file .git/config" >expect &&
test_expect_code 128 test-config get_value foo.bar 2>actual && test_expect_code 128 test-config get_value foo.bar 2>actual &&
test_cmp expect actual test_i18ncmp expect actual
' '
test_expect_success 'proper error on error in custom config files' ' test_expect_success 'proper error on error in custom config files' '
echo "[" >>syntax-error && echo "[" >>syntax-error &&
echo "fatal: bad config line 1 in file syntax-error" >expect && echo "fatal: bad config line 1 in file syntax-error" >expect &&
test_expect_code 128 test-config configset_get_value foo.bar syntax-error 2>actual && test_expect_code 128 test-config configset_get_value foo.bar syntax-error 2>actual &&
test_cmp expect actual test_i18ncmp expect actual
' '
test_expect_success 'check line errors for malformed values' ' test_expect_success 'check line errors for malformed values' '

View file

@ -361,7 +361,7 @@ test_expect_success 'stdin test setup' '
test_expect_success '-z fails without --stdin' ' test_expect_success '-z fails without --stdin' '
test_must_fail git update-ref -z $m $m $m 2>err && test_must_fail git update-ref -z $m $m $m 2>err &&
grep "usage: git update-ref" err test_i18ngrep "usage: git update-ref" err
' '
test_expect_success 'stdin works with no input' ' test_expect_success 'stdin works with no input' '

View file

@ -49,7 +49,7 @@ test_expect_success 'disambiguate checking out from a tree-ish' '
test_expect_success 'accurate error message with more than one ref' ' test_expect_success 'accurate error message with more than one ref' '
test_must_fail git checkout HEAD master -- 2>actual && test_must_fail git checkout HEAD master -- 2>actual &&
grep 2 actual && test_i18ngrep 2 actual &&
test_i18ngrep "one reference expected, 2 given" actual test_i18ngrep "one reference expected, 2 given" actual
' '

View file

@ -124,7 +124,7 @@ test_expect_success 'checkout -b to @{-1} fails with the right branch name' '
git checkout branch2 && git checkout branch2 &&
echo >expect "fatal: A branch named '\''branch1'\'' already exists." && echo >expect "fatal: A branch named '\''branch1'\'' already exists." &&
test_must_fail git checkout -b @{-1} 2>actual && test_must_fail git checkout -b @{-1} 2>actual &&
test_cmp expect actual test_i18ncmp expect actual
' '
test_expect_success 'checkout -B to an existing branch resets branch to HEAD' ' test_expect_success 'checkout -B to an existing branch resets branch to HEAD' '

View file

@ -550,7 +550,7 @@ If you wanted to make '"'master'"' track '"'origin/master'"', do this:
git branch -d origin/master git branch -d origin/master
git branch --set-upstream-to origin/master git branch --set-upstream-to origin/master
EOF EOF
test_cmp expected actual test_i18ncmp expected actual
' '
test_expect_success '--set-upstream with two args only shows the deprecation message' ' test_expect_success '--set-upstream with two args only shows the deprecation message' '
@ -559,7 +559,7 @@ test_expect_success '--set-upstream with two args only shows the deprecation mes
cat >expected <<EOF && cat >expected <<EOF &&
The --set-upstream flag is deprecated and will be removed. Consider using --track or --set-upstream-to The --set-upstream flag is deprecated and will be removed. Consider using --track or --set-upstream-to
EOF EOF
test_cmp expected actual test_i18ncmp expected actual
' '
test_expect_success '--set-upstream with one arg only shows the deprecation message if the branch existed' ' test_expect_success '--set-upstream with one arg only shows the deprecation message if the branch existed' '
@ -568,7 +568,7 @@ test_expect_success '--set-upstream with one arg only shows the deprecation mess
cat >expected <<EOF && cat >expected <<EOF &&
The --set-upstream flag is deprecated and will be removed. Consider using --track or --set-upstream-to The --set-upstream flag is deprecated and will be removed. Consider using --track or --set-upstream-to
EOF EOF
test_cmp expected actual test_i18ncmp expected actual
' '
test_expect_success '--set-upstream-to notices an error to set branch as own upstream' ' test_expect_success '--set-upstream-to notices an error to set branch as own upstream' '

View file

@ -156,7 +156,7 @@ test_expect_success 'branch --merged with --verbose' '
* topic 2c939f4 [ahead 1] foo * topic 2c939f4 [ahead 1] foo
zzz c77a0a9 second on master zzz c77a0a9 second on master
EOF EOF
test_cmp expect actual test_i18ncmp expect actual
' '
test_done test_done

View file

@ -52,7 +52,7 @@ test_expect_success 'merge z into y while mid-merge in another workdir fails' '
cd worktree && cd worktree &&
git config core.notesRef refs/notes/y && git config core.notesRef refs/notes/y &&
test_must_fail git notes merge z 2>err && test_must_fail git notes merge z 2>err &&
grep "A notes merge into refs/notes/y is already in-progress at" err test_i18ngrep "A notes merge into refs/notes/y is already in-progress at" err
) && ) &&
test_path_is_missing .git/worktrees/worktree/NOTES_MERGE_REF test_path_is_missing .git/worktrees/worktree/NOTES_MERGE_REF
' '

View file

@ -1182,7 +1182,7 @@ test_expect_success 'extra args: setup' '
test_extra_arg () { test_extra_arg () {
test_expect_success "extra args: $*" " test_expect_success "extra args: $*" "
test_must_fail git remote $* bogus_extra_arg 2>actual && test_must_fail git remote $* bogus_extra_arg 2>actual &&
grep '^usage:' actual test_i18ngrep '^usage:' actual
" "
} }

View file

@ -644,7 +644,7 @@ test_expect_success 'fetch --prune prints the remotes url' '
git fetch --prune origin 2>&1 | head -n1 >../actual git fetch --prune origin 2>&1 | head -n1 >../actual
) && ) &&
echo "From ${D}/." >expect && echo "From ${D}/." >expect &&
test_cmp expect actual test_i18ncmp expect actual
' '
test_expect_success 'branchname D/F conflict resolved by --prune' ' test_expect_success 'branchname D/F conflict resolved by --prune' '

View file

@ -75,7 +75,7 @@ test_expect_success TTY 'progress messages go to tty' '
ensure_fresh_upstream && ensure_fresh_upstream &&
test_terminal git push -u upstream master >out 2>err && test_terminal git push -u upstream master >out 2>err &&
grep "Writing objects" err test_i18ngrep "Writing objects" err
' '
test_expect_success 'progress messages do not go to non-tty' ' test_expect_success 'progress messages do not go to non-tty' '
@ -91,7 +91,7 @@ test_expect_success 'progress messages go to non-tty (forced)' '
# force progress messages to stderr, even though it is non-tty # force progress messages to stderr, even though it is non-tty
git push -u --progress upstream master >out 2>err && git push -u --progress upstream master >out 2>err &&
grep "Writing objects" err test_i18ngrep "Writing objects" err
' '
test_expect_success TTY 'push -q suppresses progress' ' test_expect_success TTY 'push -q suppresses progress' '

View file

@ -22,8 +22,8 @@ verify_stderr () {
cat >expected && cat >expected &&
# We're not interested in the error # We're not interested in the error
# "fatal: The remote end hung up unexpectedly": # "fatal: The remote end hung up unexpectedly":
grep -E '^(fatal|warning):' <error | grep -v 'hung up' >actual | sort && test_i18ngrep -E '^(fatal|warning):' <error | grep -v 'hung up' >actual | sort &&
test_cmp expected actual test_i18ncmp expected actual
} }
test_expect_success 'setup' ' test_expect_success 'setup' '

View file

@ -20,8 +20,8 @@ test_expect_success 'Broken refs are reported correctly' '
test_when_finished "rm -f .git/$r" && test_when_finished "rm -f .git/$r" &&
echo "warning: ignoring broken ref $r" >broken-err && echo "warning: ignoring broken ref $r" >broken-err &&
git for-each-ref >out 2>err && git for-each-ref >out 2>err &&
test_cmp full-list out && test_i18ncmp full-list out &&
test_cmp broken-err err test_i18ncmp broken-err err
' '
test_expect_success 'NULL_SHA1 refs are reported correctly' ' test_expect_success 'NULL_SHA1 refs are reported correctly' '
@ -31,10 +31,10 @@ test_expect_success 'NULL_SHA1 refs are reported correctly' '
echo "warning: ignoring broken ref $r" >zeros-err && echo "warning: ignoring broken ref $r" >zeros-err &&
git for-each-ref >out 2>err && git for-each-ref >out 2>err &&
test_cmp full-list out && test_cmp full-list out &&
test_cmp zeros-err err && test_i18ncmp zeros-err err &&
git for-each-ref --format="%(objectname) %(refname)" >brief-out 2>brief-err && git for-each-ref --format="%(objectname) %(refname)" >brief-out 2>brief-err &&
test_cmp brief-list brief-out && test_cmp brief-list brief-out &&
test_cmp zeros-err brief-err test_i18ncmp zeros-err brief-err
' '
test_expect_success 'Missing objects are reported correctly' ' test_expect_success 'Missing objects are reported correctly' '
@ -43,7 +43,7 @@ test_expect_success 'Missing objects are reported correctly' '
test_when_finished "rm -f .git/$r" && test_when_finished "rm -f .git/$r" &&
echo "fatal: missing object $MISSING for $r" >missing-err && echo "fatal: missing object $MISSING for $r" >missing-err &&
test_must_fail git for-each-ref 2>err && test_must_fail git for-each-ref 2>err &&
test_cmp missing-err err && test_i18ncmp missing-err err &&
( (
cat brief-list && cat brief-list &&
echo "$MISSING $r" echo "$MISSING $r"

View file

@ -643,7 +643,7 @@ test_expect_success 'test ident field is working' '
cp -R done dthree dtwo four three ../other_worktree && cp -R done dthree dtwo four three ../other_worktree &&
GIT_WORK_TREE=../other_worktree git status 2>../err && GIT_WORK_TREE=../other_worktree git status 2>../err &&
echo "warning: Untracked cache is disabled on this system or location." >../expect && echo "warning: Untracked cache is disabled on this system or location." >../expect &&
test_cmp ../expect ../err test_i18ncmp ../expect ../err
' '
test_done test_done

View file

@ -66,14 +66,14 @@ test_expect_success 'reset --hard message' '
hex=$(git log -1 --format="%h") && hex=$(git log -1 --format="%h") &&
git reset --hard > .actual && git reset --hard > .actual &&
echo HEAD is now at $hex $(commit_msg) > .expected && echo HEAD is now at $hex $(commit_msg) > .expected &&
test_cmp .expected .actual test_i18ncmp .expected .actual
' '
test_expect_success 'reset --hard message (ISO8859-1 logoutputencoding)' ' test_expect_success 'reset --hard message (ISO8859-1 logoutputencoding)' '
hex=$(git log -1 --format="%h") && hex=$(git log -1 --format="%h") &&
git -c "i18n.logOutputEncoding=$test_encoding" reset --hard > .actual && git -c "i18n.logOutputEncoding=$test_encoding" reset --hard > .actual &&
echo HEAD is now at $hex $(commit_msg $test_encoding) > .expected && echo HEAD is now at $hex $(commit_msg $test_encoding) > .expected &&
test_cmp .expected .actual test_i18ncmp .expected .actual
' '
>.diff_expect >.diff_expect

View file

@ -942,7 +942,7 @@ test_expect_success 'submodule deinit from subdirectory' '
cd sub && cd sub &&
git submodule deinit ../init >../output git submodule deinit ../init >../output
) && ) &&
grep "\\.\\./init" output && test_i18ngrep "\\.\\./init" output &&
test -z "$(git config --get-regexp "submodule\.example\.")" && test -z "$(git config --get-regexp "submodule\.example\.")" &&
test -n "$(git config --get-regexp "submodule\.example2\.")" && test -n "$(git config --get-regexp "submodule\.example2\.")" &&
test -f example2/.git && test -f example2/.git &&

View file

@ -157,7 +157,7 @@ test_expect_success '"git submodule sync" should update submodule URLs - subdire
cd sub && cd sub &&
git submodule sync >../../output git submodule sync >../../output
) && ) &&
grep "\\.\\./submodule" output && test_i18ngrep "\\.\\./submodule" output &&
test -d "$( test -d "$(
cd super-clone/submodule && cd super-clone/submodule &&
git config remote.origin.url git config remote.origin.url
@ -188,7 +188,7 @@ test_expect_success '"git submodule sync --recursive" should update all submodul
cd sub && cd sub &&
git submodule sync --recursive >../../output git submodule sync --recursive >../../output
) && ) &&
grep "\\.\\./submodule/sub-submodule" output && test_i18ngrep "\\.\\./submodule/sub-submodule" output &&
test -d "$( test -d "$(
cd super-clone/submodule && cd super-clone/submodule &&
git config remote.origin.url git config remote.origin.url

View file

@ -136,8 +136,8 @@ test_expect_success 'submodule update --init --recursive from subdirectory' '
cd tmp && cd tmp &&
git submodule update --init --recursive ../super >../../actual 2>../../actual2 git submodule update --init --recursive ../super >../../actual 2>../../actual2
) && ) &&
test_cmp expect actual && test_i18ncmp expect actual &&
test_cmp expect2 actual2 test_i18ncmp expect2 actual2
' '
apos="'"; apos="'";
@ -370,7 +370,7 @@ test_expect_success 'submodule update - command in .git/config catches failure'
(cd super && (cd super &&
test_must_fail git submodule update submodule 2>../actual test_must_fail git submodule update submodule 2>../actual
) && ) &&
test_cmp actual expect test_i18ncmp actual expect
' '
cat << EOF >expect cat << EOF >expect
@ -388,7 +388,7 @@ test_expect_success 'submodule update - command in .git/config catches failure -
mkdir tmp && cd tmp && mkdir tmp && cd tmp &&
test_must_fail git submodule update ../submodule 2>../../actual test_must_fail git submodule update ../submodule 2>../../actual
) && ) &&
test_cmp actual expect test_i18ncmp actual expect
' '
cat << EOF >expect cat << EOF >expect
@ -408,7 +408,7 @@ test_expect_success 'recursive submodule update - command in .git/config catches
mkdir -p tmp && cd tmp && mkdir -p tmp && cd tmp &&
test_must_fail git submodule update --recursive ../super 2>../../actual test_must_fail git submodule update --recursive ../super 2>../../actual
) && ) &&
test_cmp actual expect test_i18ncmp actual expect
' '
test_expect_success 'submodule init does not copy command into .git/config' ' test_expect_success 'submodule init does not copy command into .git/config' '

View file

@ -1377,7 +1377,7 @@ EOF
git config --add -f .gitmodules submodule.subname.ignore all && git config --add -f .gitmodules submodule.subname.ignore all &&
git config --add -f .gitmodules submodule.subname.path sm && git config --add -f .gitmodules submodule.subname.path sm &&
git status > output && git status > output &&
test_cmp expect output && test_i18ncmp expect output &&
git config -f .gitmodules --remove-section submodule.subname git config -f .gitmodules --remove-section submodule.subname
' '
@ -1387,7 +1387,7 @@ test_expect_success '.git/config ignore=all suppresses unstaged submodule summar
git config --add submodule.subname.ignore all && git config --add submodule.subname.ignore all &&
git config --add submodule.subname.path sm && git config --add submodule.subname.path sm &&
git status > output && git status > output &&
test_cmp expect output && test_i18ncmp expect output &&
git config --remove-section submodule.subname && git config --remove-section submodule.subname &&
git config -f .gitmodules --remove-section submodule.subname git config -f .gitmodules --remove-section submodule.subname
' '