Skip to content

Commit

Permalink
Fix tests under GETTEXT_POISON on parseopt
Browse files Browse the repository at this point in the history
Use the i18n-specific test functions in test scripts for parseopt tests.
This issue was was introduced in v1.7.10.1-488-g54e6d:

    54e6d i18n: parseopt: lookup help and argument translations when showing usage

and been broken under GETTEXT_POISON=YesPlease since.

Signed-off-by: Jiang Xin <worldhello.net@gmail.com>
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
jiangxin authored and gitster committed Aug 27, 2012
1 parent f7dc6a9 commit 9a00138
Show file tree
Hide file tree
Showing 11 changed files with 46 additions and 22 deletions.
34 changes: 29 additions & 5 deletions t/t0040-parse-options.sh
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ EOF
test_expect_success 'test help' '
test_must_fail test-parse-options -h > output 2> output.err &&
test ! -s output.err &&
test_cmp expect output
test_i18ncmp expect output
'

mv expect expect.err
Expand Down Expand Up @@ -79,6 +79,17 @@ check() {
test_cmp expect output
}

check_i18n() {
what="$1" &&
shift &&
expect="$1" &&
shift &&
sed "s/^$what .*/$what $expect/" <expect.template >expect &&
test-parse-options $* >output 2>output.err &&
test ! -s output.err &&
test_i18ncmp expect output
}

check_unknown() {
case "$1" in
--*)
Expand All @@ -92,6 +103,19 @@ check_unknown() {
test_cmp expect output.err
}

check_unknown_i18n() {
case "$1" in
--*)
echo error: unknown option \`${1#--}\' >expect ;;
-*)
echo error: unknown switch \`${1#-}\' >expect ;;
esac &&
cat expect.err >>expect &&
test_must_fail test-parse-options $* >output 2>output.err &&
test ! -s output &&
test_i18ncmp expect output.err
}

test_expect_success 'OPT_BOOL() #1' 'check boolean: 1 --yes'
test_expect_success 'OPT_BOOL() #2' 'check boolean: 1 --no-doubt'
test_expect_success 'OPT_BOOL() #3' 'check boolean: 1 -D'
Expand All @@ -104,8 +128,8 @@ test_expect_success 'OPT_BOOL() is idempotent #2' 'check boolean: 1 -DB'
test_expect_success 'OPT_BOOL() negation #1' 'check boolean: 0 -D --no-yes'
test_expect_success 'OPT_BOOL() negation #2' 'check boolean: 0 -D --no-no-doubt'

test_expect_success 'OPT_BOOL() no negation #1' 'check_unknown --fear'
test_expect_success 'OPT_BOOL() no negation #2' 'check_unknown --no-no-fear'
test_expect_success 'OPT_BOOL() no negation #1' 'check_unknown_i18n --fear'
test_expect_success 'OPT_BOOL() no negation #2' 'check_unknown_i18n --no-no-fear'

test_expect_success 'OPT_BOOL() positivation' 'check boolean: 0 -D --doubt'

Expand Down Expand Up @@ -310,8 +334,8 @@ EOF

test_expect_success 'OPT_CALLBACK() and callback errors work' '
test_must_fail test-parse-options --no-length > output 2> output.err &&
test_cmp expect output &&
test_cmp expect.err output.err
test_i18ncmp expect output &&
test_i18ncmp expect.err output.err
'

cat > expect <<EOF
Expand Down
2 changes: 1 addition & 1 deletion t/t1300-repo-config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ test_expect_success 'get bool variable with empty value' \

test_expect_success 'no arguments, but no crash' '
test_must_fail git config >output 2>&1 &&
grep usage output
test_i18ngrep usage output
'

cat > .git/config << EOF
Expand Down
2 changes: 1 addition & 1 deletion t/t1502-rev-parse-parseopt.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ EOF

test_expect_success 'test --parseopt help output' '
test_expect_code 129 git rev-parse --parseopt -- -h > output < optionspec &&
test_cmp expect output
test_i18ncmp expect output
'

cat > expect <<EOF
Expand Down
4 changes: 2 additions & 2 deletions t/t2006-checkout-index-basic.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ test_description='basic checkout-index tests

test_expect_success 'checkout-index --gobbledegook' '
test_expect_code 129 git checkout-index --gobbledegook 2>err &&
grep "[Uu]sage" err
test_i18ngrep "[Uu]sage" err
'

test_expect_success 'checkout-index -h in broken repository' '
Expand All @@ -18,7 +18,7 @@ test_expect_success 'checkout-index -h in broken repository' '
>.git/index &&
test_expect_code 129 git checkout-index -h >usage 2>&1
) &&
grep "[Uu]sage" broken/usage
test_i18ngrep "[Uu]sage" broken/usage
'

test_done
4 changes: 2 additions & 2 deletions t/t2107-update-index-basic.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ test_expect_success 'update-index --nonsense fails' '

test_expect_success 'update-index --nonsense dumps usage' '
test_expect_code 129 git update-index --nonsense 2>err &&
grep "[Uu]sage: git update-index" err
test_i18ngrep "[Uu]sage: git update-index" err
'

test_expect_success 'update-index -h with corrupt index' '
Expand All @@ -26,7 +26,7 @@ test_expect_success 'update-index -h with corrupt index' '
>.git/index &&
test_expect_code 129 git update-index -h >usage 2>&1
) &&
grep "[Uu]sage: git update-index" broken/usage
test_i18ngrep "[Uu]sage: git update-index" broken/usage
'

test_done
4 changes: 2 additions & 2 deletions t/t3004-ls-files-basic.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ test_expect_success 'ls-files with nonexistent path' '

test_expect_success 'ls-files with nonsense option' '
test_expect_code 129 git ls-files --nonsense 2>actual &&
grep "[Uu]sage: git ls-files" actual
test_i18ngrep "[Uu]sage: git ls-files" actual
'

test_expect_success 'ls-files -h in corrupt repository' '
Expand All @@ -33,7 +33,7 @@ test_expect_success 'ls-files -h in corrupt repository' '
>.git/index &&
test_expect_code 129 git ls-files -h >usage 2>&1
) &&
grep "[Uu]sage: git ls-files " broken/usage
test_i18ngrep "[Uu]sage: git ls-files " broken/usage
'

test_done
4 changes: 2 additions & 2 deletions t/t3200-branch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ test_expect_success 'branch -h in broken repository' '
>.git/refs/heads/master &&
test_expect_code 129 git branch -h >usage 2>&1
) &&
grep "[Uu]sage" broken/usage
test_i18ngrep "[Uu]sage" broken/usage
'

test_expect_success \
Expand Down Expand Up @@ -74,7 +74,7 @@ test_expect_success \
test_expect_success \
'git branch -m dumps usage' \
'test_expect_code 129 git branch -m 2>err &&
grep "[Uu]sage: git branch" err'
test_i18ngrep "[Uu]sage: git branch" err'

test_expect_success \
'git branch -m m m/m should work' \
Expand Down
4 changes: 2 additions & 2 deletions t/t3501-revert-cherry-pick.sh
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ test_expect_success 'cherry-pick --nonsense' '
git diff --exit-code HEAD &&
test_must_fail git cherry-pick --nonsense 2>msg &&
git diff --exit-code HEAD "$pos" &&
grep '[Uu]sage:' msg
test_i18ngrep '[Uu]sage:' msg
'

test_expect_success 'revert --nonsense' '
Expand All @@ -56,7 +56,7 @@ test_expect_success 'revert --nonsense' '
git diff --exit-code HEAD &&
test_must_fail git revert --nonsense 2>msg &&
git diff --exit-code HEAD "$pos" &&
grep '[Uu]sage:' msg
test_i18ngrep '[Uu]sage:' msg
'

test_expect_success 'cherry-pick after renaming branch' '
Expand Down
4 changes: 2 additions & 2 deletions t/t4200-rerere.sh
Original file line number Diff line number Diff line change
Expand Up @@ -382,13 +382,13 @@ test_expect_success 'rerere --no-no-rerere-autoupdate' '
git update-index --index-info <failedmerge &&
cp file3.conflict file3 &&
test_must_fail git rerere --no-no-rerere-autoupdate 2>err &&
grep [Uu]sage err &&
test_i18ngrep [Uu]sage err &&
test_must_fail git update-index --refresh
'

test_expect_success 'rerere -h' '
test_must_fail git rerere -h >help &&
grep [Uu]sage help
test_i18ngrep [Uu]sage help
'

test_done
4 changes: 2 additions & 2 deletions t/t6500-gc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ test_expect_success 'gc empty repository' '

test_expect_success 'gc --gobbledegook' '
test_expect_code 129 git gc --nonsense 2>err &&
grep "[Uu]sage: git gc" err
test_i18ngrep "[Uu]sage: git gc" err
'

test_expect_success 'gc -h with invalid configuration' '
Expand All @@ -22,7 +22,7 @@ test_expect_success 'gc -h with invalid configuration' '
echo "[gc] pruneexpire = CORRUPT" >>.git/config &&
test_expect_code 129 git gc -h >usage 2>&1
) &&
grep "[Uu]sage" broken/usage
test_i18ngrep "[Uu]sage" broken/usage
'

test_done
2 changes: 1 addition & 1 deletion t/t7600-merge.sh
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ test_expect_success 'merge -h with invalid index' '
>.git/index &&
test_expect_code 129 git merge -h 2>usage
) &&
grep "[Uu]sage: git merge" broken/usage
test_i18ngrep "[Uu]sage: git merge" broken/usage
'

test_expect_success 'reject non-strategy with a git-merge-foo name' '
Expand Down

0 comments on commit 9a00138

Please sign in to comment.