Merge branch 'js/spell-out-options-in-tests'

The tests have been updated not to rely on the abbreviated option
names the parse-options API offers, to protect us from an
abbreviated form of an option that used to be unique within the
command getting non-unique when a new option that share the same
prefix is added.

* js/spell-out-options-in-tests:
  tests: disallow the use of abbreviated options (by default)
  tests (pack-objects): use the full, unabbreviated `--revs` option
  tests (status): spell out the `--find-renames` option in full
  tests (push): do not abbreviate the `--follow-tags` option
  t5531: avoid using an abbreviated option
  t7810: do not abbreviate `--no-exclude-standard` nor `--invert-match`
  tests (rebase): spell out the `--force-rebase` option
  tests (rebase): spell out the `--keep-empty` option
This commit is contained in:
Junio C Hamano 2019-04-22 11:14:47 +09:00
Родитель 87e20f8c4f b02e7d5d70
Коммит 39e4773daa
12 изменённых файлов: 75 добавлений и 43 удалений

Просмотреть файл

@ -6,6 +6,8 @@
#include "color.h"
#include "utf8.h"
static int disallow_abbreviated_options;
#define OPT_SHORT 1
#define OPT_UNSET 2
@ -344,6 +346,10 @@ is_abbreviated:
return get_value(p, options, all_opts, flags ^ opt_flags);
}
if (disallow_abbreviated_options && (ambiguous_option || abbrev_option))
die("disallowed abbreviated or ambiguous option '%.*s'",
(int)(arg_end - arg), arg);
if (ambiguous_option) {
error(_("ambiguous option: %s "
"(could be --%s%s or --%s%s)"),
@ -708,6 +714,9 @@ int parse_options(int argc, const char **argv, const char *prefix,
{
struct parse_opt_ctx_t ctx;
disallow_abbreviated_options =
git_env_bool("GIT_TEST_DISALLOW_ABBREVIATED_OPTIONS", 0);
parse_options_start(&ctx, argc, argv, prefix, options, flags);
switch (parse_options_step(&ctx, options, usagestr)) {
case PARSE_OPT_HELP:

Просмотреть файл

@ -402,6 +402,10 @@ GIT_TEST_SIDEBAND_ALL=<boolean>, when true, overrides the
fetch-pack to not request sideband-all (even if the server advertises
sideband-all).
GIT_TEST_DISALLOW_ABBREVIATED_OPTIONS=<boolean>, when true (which is
the default when running tests), errors out when an abbreviated option
is used.
Naming Tests
------------

Просмотреть файл

@ -203,20 +203,24 @@ file: (not set)
EOF
test_expect_success 'unambiguously abbreviated option' '
GIT_TEST_DISALLOW_ABBREVIATED_OPTIONS=false \
test-tool parse-options --int 2 --boolean --no-bo >output 2>output.err &&
test_must_be_empty output.err &&
test_cmp expect output
'
test_expect_success 'unambiguously abbreviated option with "="' '
GIT_TEST_DISALLOW_ABBREVIATED_OPTIONS=false \
test-tool parse-options --expect="integer: 2" --int=2
'
test_expect_success 'ambiguously abbreviated option' '
test_expect_code 129 test-tool parse-options --strin 123
test_expect_code 129 env GIT_TEST_DISALLOW_ABBREVIATED_OPTIONS=false \
test-tool parse-options --strin 123
'
test_expect_success 'non ambiguous option (after two options it abbreviates)' '
GIT_TEST_DISALLOW_ABBREVIATED_OPTIONS=false \
test-tool parse-options --expect="string: 123" --st 123
'
@ -325,6 +329,7 @@ file: (not set)
EOF
test_expect_success 'negation of OPT_NONEG flags is not ambiguous' '
GIT_TEST_DISALLOW_ABBREVIATED_OPTIONS=false \
test-tool parse-options --no-ambig >output 2>output.err &&
test_must_be_empty output.err &&
test_cmp expect output
@ -370,4 +375,11 @@ test_expect_success '--no-verbose resets multiple verbose to 0' '
test-tool parse-options --expect="verbose: 0" -v -v -v --no-verbose
'
test_expect_success 'GIT_TEST_DISALLOW_ABBREVIATED_OPTIONS works' '
GIT_TEST_DISALLOW_ABBREVIATED_OPTIONS=false \
test-tool parse-options --ye &&
test_must_fail env GIT_TEST_DISALLOW_ABBREVIATED_OPTIONS=true \
test-tool parse-options --ye
'
test_done

Просмотреть файл

@ -277,7 +277,7 @@ test_expect_success 'autosquash with empty custom instructionFormat' '
(
set_cat_todo_editor &&
test_must_fail git -c rebase.instructionFormat= \
rebase --autosquash --force -i HEAD^ >actual &&
rebase --autosquash --force-rebase -i HEAD^ >actual &&
git log -1 --format="pick %h %s" >expect &&
test_cmp expect actual
)

Просмотреть файл

@ -271,7 +271,7 @@ test_expect_success 'root commits' '
EOF
test_config sequence.editor \""$PWD"/replace-editor.sh\" &&
test_tick &&
git rebase -i --force --root -r &&
git rebase -i --force-rebase --root -r &&
test "Parsnip" = "$(git show -s --format=%an HEAD^)" &&
test $(git rev-parse second-root^0) != $(git rev-parse HEAD^) &&
test $(git rev-parse second-root:second-root.t) = \
@ -364,7 +364,7 @@ test_expect_success 'octopus merges' '
test_cmp_rev HEAD $before &&
test_tick &&
git rebase -i --force -r HEAD^^ &&
git rebase -i --force-rebase -r HEAD^^ &&
test "Hank" = "$(git show -s --format=%an HEAD)" &&
test "$before" != $(git rev-parse HEAD) &&
test_cmp_graph HEAD^^.. <<-\EOF

Просмотреть файл

@ -25,7 +25,7 @@ test_expect_success 'verify blob count in normal packfile' '
awk -f print_2.awk ls_files_result |
sort >expected &&
git -C r1 pack-objects --rev --stdout >all.pack <<-EOF &&
git -C r1 pack-objects --revs --stdout >all.pack <<-EOF &&
HEAD
EOF
git -C r1 index-pack ../all.pack &&
@ -39,7 +39,7 @@ test_expect_success 'verify blob count in normal packfile' '
'
test_expect_success 'verify blob:none packfile has no blobs' '
git -C r1 pack-objects --rev --stdout --filter=blob:none >filter.pack <<-EOF &&
git -C r1 pack-objects --revs --stdout --filter=blob:none >filter.pack <<-EOF &&
HEAD
EOF
git -C r1 index-pack ../filter.pack &&
@ -74,7 +74,7 @@ test_expect_success 'get an error for missing tree object' '
git -C r5 commit -m "foo" &&
del=$(git -C r5 rev-parse HEAD^{tree} | sed "s|..|&/|") &&
rm r5/.git/objects/$del &&
test_must_fail git -C r5 pack-objects --rev --stdout 2>bad_tree <<-EOF &&
test_must_fail git -C r5 pack-objects --revs --stdout 2>bad_tree <<-EOF &&
HEAD
EOF
grep "bad tree object" bad_tree
@ -88,7 +88,7 @@ test_expect_success 'setup for tests of tree:0' '
'
test_expect_success 'verify tree:0 packfile has no blobs or trees' '
git -C r1 pack-objects --rev --stdout --filter=tree:0 >commitsonly.pack <<-EOF &&
git -C r1 pack-objects --revs --stdout --filter=tree:0 >commitsonly.pack <<-EOF &&
HEAD
EOF
git -C r1 index-pack ../commitsonly.pack &&
@ -98,7 +98,7 @@ test_expect_success 'verify tree:0 packfile has no blobs or trees' '
test_expect_success 'grab tree directly when using tree:0' '
# We should get the tree specified directly but not its blobs or subtrees.
git -C r1 pack-objects --rev --stdout --filter=tree:0 >commitsonly.pack <<-EOF &&
git -C r1 pack-objects --revs --stdout --filter=tree:0 >commitsonly.pack <<-EOF &&
HEAD:
EOF
git -C r1 index-pack ../commitsonly.pack &&
@ -128,7 +128,7 @@ test_expect_success 'verify blob count in normal packfile' '
awk -f print_2.awk ls_files_result |
sort >expected &&
git -C r2 pack-objects --rev --stdout >all.pack <<-EOF &&
git -C r2 pack-objects --revs --stdout >all.pack <<-EOF &&
HEAD
EOF
git -C r2 index-pack ../all.pack &&
@ -142,7 +142,7 @@ test_expect_success 'verify blob count in normal packfile' '
'
test_expect_success 'verify blob:limit=500 omits all blobs' '
git -C r2 pack-objects --rev --stdout --filter=blob:limit=500 >filter.pack <<-EOF &&
git -C r2 pack-objects --revs --stdout --filter=blob:limit=500 >filter.pack <<-EOF &&
HEAD
EOF
git -C r2 index-pack ../filter.pack &&
@ -157,7 +157,7 @@ test_expect_success 'verify blob:limit=500 omits all blobs' '
'
test_expect_success 'verify blob:limit=1000' '
git -C r2 pack-objects --rev --stdout --filter=blob:limit=1000 >filter.pack <<-EOF &&
git -C r2 pack-objects --revs --stdout --filter=blob:limit=1000 >filter.pack <<-EOF &&
HEAD
EOF
git -C r2 index-pack ../filter.pack &&
@ -176,7 +176,7 @@ test_expect_success 'verify blob:limit=1001' '
awk -f print_2.awk ls_files_result |
sort >expected &&
git -C r2 pack-objects --rev --stdout --filter=blob:limit=1001 >filter.pack <<-EOF &&
git -C r2 pack-objects --revs --stdout --filter=blob:limit=1001 >filter.pack <<-EOF &&
HEAD
EOF
git -C r2 index-pack ../filter.pack &&
@ -194,7 +194,7 @@ test_expect_success 'verify blob:limit=10001' '
awk -f print_2.awk ls_files_result |
sort >expected &&
git -C r2 pack-objects --rev --stdout --filter=blob:limit=10001 >filter.pack <<-EOF &&
git -C r2 pack-objects --revs --stdout --filter=blob:limit=10001 >filter.pack <<-EOF &&
HEAD
EOF
git -C r2 index-pack ../filter.pack &&
@ -212,7 +212,7 @@ test_expect_success 'verify blob:limit=1k' '
awk -f print_2.awk ls_files_result |
sort >expected &&
git -C r2 pack-objects --rev --stdout --filter=blob:limit=1k >filter.pack <<-EOF &&
git -C r2 pack-objects --revs --stdout --filter=blob:limit=1k >filter.pack <<-EOF &&
HEAD
EOF
git -C r2 index-pack ../filter.pack &&
@ -230,7 +230,7 @@ test_expect_success 'verify explicitly specifying oversized blob in input' '
awk -f print_2.awk ls_files_result |
sort >expected &&
git -C r2 pack-objects --rev --stdout --filter=blob:limit=1k >filter.pack <<-EOF &&
git -C r2 pack-objects --revs --stdout --filter=blob:limit=1k >filter.pack <<-EOF &&
HEAD
$(git -C r2 rev-parse HEAD:large.10000)
EOF
@ -249,7 +249,7 @@ test_expect_success 'verify blob:limit=1m' '
awk -f print_2.awk ls_files_result |
sort >expected &&
git -C r2 pack-objects --rev --stdout --filter=blob:limit=1m >filter.pack <<-EOF &&
git -C r2 pack-objects --revs --stdout --filter=blob:limit=1m >filter.pack <<-EOF &&
HEAD
EOF
git -C r2 index-pack ../filter.pack &&
@ -302,7 +302,7 @@ test_expect_success 'verify blob count in normal packfile' '
awk -f print_2.awk ls_files_result |
sort >expected &&
git -C r3 pack-objects --rev --stdout >all.pack <<-EOF &&
git -C r3 pack-objects --revs --stdout >all.pack <<-EOF &&
HEAD
EOF
git -C r3 index-pack ../all.pack &&
@ -320,7 +320,7 @@ test_expect_success 'verify sparse:path=pattern1' '
awk -f print_2.awk ls_files_result |
sort >expected &&
git -C r3 pack-objects --rev --stdout --filter=sparse:path=../pattern1 >filter.pack <<-EOF &&
git -C r3 pack-objects --revs --stdout --filter=sparse:path=../pattern1 >filter.pack <<-EOF &&
HEAD
EOF
git -C r3 index-pack ../filter.pack &&
@ -352,7 +352,7 @@ test_expect_success 'verify sparse:path=pattern2' '
awk -f print_2.awk ls_files_result |
sort >expected &&
git -C r3 pack-objects --rev --stdout --filter=sparse:path=../pattern2 >filter.pack <<-EOF &&
git -C r3 pack-objects --revs --stdout --filter=sparse:path=../pattern2 >filter.pack <<-EOF &&
HEAD
EOF
git -C r3 index-pack ../filter.pack &&
@ -404,7 +404,7 @@ test_expect_success 'verify blob count in normal packfile' '
awk -f print_2.awk ls_files_result |
sort >expected &&
git -C r4 pack-objects --rev --stdout >all.pack <<-EOF &&
git -C r4 pack-objects --revs --stdout >all.pack <<-EOF &&
HEAD
EOF
git -C r4 index-pack ../all.pack &&
@ -423,7 +423,7 @@ test_expect_success 'verify sparse:oid=OID' '
sort >expected &&
oid=$(git -C r4 ls-files -s pattern | awk -f print_2.awk) &&
git -C r4 pack-objects --rev --stdout --filter=sparse:oid=$oid >filter.pack <<-EOF &&
git -C r4 pack-objects --revs --stdout --filter=sparse:oid=$oid >filter.pack <<-EOF &&
HEAD
EOF
git -C r4 index-pack ../filter.pack &&
@ -441,7 +441,7 @@ test_expect_success 'verify sparse:oid=oid-ish' '
awk -f print_2.awk ls_files_result |
sort >expected &&
git -C r4 pack-objects --rev --stdout --filter=sparse:oid=master:pattern >filter.pack <<-EOF &&
git -C r4 pack-objects --revs --stdout --filter=sparse:oid=master:pattern >filter.pack <<-EOF &&
HEAD
EOF
git -C r4 index-pack ../filter.pack &&
@ -470,19 +470,19 @@ test_expect_success 'setup r1 - delete loose blobs' '
'
test_expect_success 'verify pack-objects fails w/ missing objects' '
test_must_fail git -C r1 pack-objects --rev --stdout >miss.pack <<-EOF
test_must_fail git -C r1 pack-objects --revs --stdout >miss.pack <<-EOF
HEAD
EOF
'
test_expect_success 'verify pack-objects fails w/ --missing=error' '
test_must_fail git -C r1 pack-objects --rev --stdout --missing=error >miss.pack <<-EOF
test_must_fail git -C r1 pack-objects --revs --stdout --missing=error >miss.pack <<-EOF
HEAD
EOF
'
test_expect_success 'verify pack-objects w/ --missing=allow-any' '
git -C r1 pack-objects --rev --stdout --missing=allow-any >miss.pack <<-EOF
git -C r1 pack-objects --revs --stdout --missing=allow-any >miss.pack <<-EOF
HEAD
EOF
'

Просмотреть файл

@ -131,7 +131,7 @@ test_expect_success 'git rebase -m --skip' '
test_expect_success 'git rebase with implicit use of interactive backend' '
git reset --hard D &&
clear_hook_input &&
test_must_fail git rebase --keep --onto A B &&
test_must_fail git rebase --keep-empty --onto A B &&
echo C > foo &&
git add foo &&
git rebase --continue &&
@ -146,7 +146,7 @@ test_expect_success 'git rebase with implicit use of interactive backend' '
test_expect_success 'git rebase --skip with implicit use of interactive backend' '
git reset --hard D &&
clear_hook_input &&
test_must_fail git rebase --keep --onto A B &&
test_must_fail git rebase --keep-empty --onto A B &&
test_must_fail git rebase --skip &&
echo D > foo &&
git add foo &&

Просмотреть файл

@ -1382,7 +1382,7 @@ test_expect_success 'push does not follow tags by default' '
test_cmp expect actual
'
test_expect_success 'push --follow-tag only pushes relevant tags' '
test_expect_success 'push --follow-tags only pushes relevant tags' '
mk_test testrepo heads/master &&
rm -fr src dst &&
git init src &&
@ -1396,7 +1396,7 @@ test_expect_success 'push --follow-tag only pushes relevant tags' '
git tag -m "future" future &&
git checkout master &&
git for-each-ref refs/heads/master refs/tags/tag >../expect &&
git push --follow-tag ../dst master
git push --follow-tags ../dst master
) &&
(
cd dst &&

Просмотреть файл

@ -363,7 +363,7 @@ test_expect_success 'push succeeds if submodule has no remote and is on the firs
) &&
git add b &&
git commit -m "added submodule" &&
git push --recurse-submodule=check origin master
git push --recurse-submodules=check origin master
)
'

Просмотреть файл

@ -84,7 +84,7 @@ test_expect_success 'status score=100%' '
test_i18ngrep "deleted:" actual &&
test_i18ngrep "new file:" actual &&
git status --find-rename=100% >actual &&
git status --find-renames=100% >actual &&
test_i18ngrep "deleted:" actual &&
test_i18ngrep "new file:" actual
'
@ -93,11 +93,11 @@ test_expect_success 'status score=01%' '
git status -M=01% >actual &&
test_i18ngrep "renamed:" actual &&
git status --find-rename=01% >actual &&
git status --find-renames=01% >actual &&
test_i18ngrep "renamed:" actual
'
test_expect_success 'copies not overridden by find-rename' '
test_expect_success 'copies not overridden by find-renames' '
cp renamed copy &&
git add copy &&
@ -105,7 +105,7 @@ test_expect_success 'copies not overridden by find-rename' '
test_i18ngrep "copied:" actual &&
test_i18ngrep "renamed:" actual &&
git -c status.renames=copies status --find-rename=01% >actual &&
git -c status.renames=copies status --find-renames=01% >actual &&
test_i18ngrep "copied:" actual &&
test_i18ngrep "renamed:" actual
'

Просмотреть файл

@ -119,33 +119,33 @@ do
test_cmp expected actual
'
test_expect_success "grep -w $L (with --column, --invert)" '
test_expect_success "grep -w $L (with --column, --invert-match)" '
{
echo ${HC}file:1:foo mmap bar
echo ${HC}file:1:foo_mmap bar
echo ${HC}file:1:foo_mmap bar mmap
echo ${HC}file:1:foo mmap bar_mmap
} >expected &&
git grep --column --invert -w -e baz $H -- file >actual &&
git grep --column --invert-match -w -e baz $H -- file >actual &&
test_cmp expected actual
'
test_expect_success "grep $L (with --column, --invert, extended OR)" '
test_expect_success "grep $L (with --column, --invert-match, extended OR)" '
{
echo ${HC}hello_world:6:HeLLo_world
} >expected &&
git grep --column --invert -e ll --or --not -e _ $H -- hello_world \
git grep --column --invert-match -e ll --or --not -e _ $H -- hello_world \
>actual &&
test_cmp expected actual
'
test_expect_success "grep $L (with --column, --invert, extended AND)" '
test_expect_success "grep $L (with --column, --invert-match, extended AND)" '
{
echo ${HC}hello_world:3:Hello world
echo ${HC}hello_world:3:Hello_world
echo ${HC}hello_world:6:HeLLo_world
} >expected &&
git grep --column --invert --not -e _ --and --not -e ll $H -- hello_world \
git grep --column --invert-match --not -e _ --and --not -e ll $H -- hello_world \
>actual &&
test_cmp expected actual
'
@ -1010,7 +1010,7 @@ test_expect_success 'outside of git repository' '
echo ".gitignore:.*o*" &&
cat ../expect.full
} >../expect.with.ignored &&
git grep --no-index --no-exclude o >../actual.full &&
git grep --no-index --no-exclude-standard o >../actual.full &&
test_cmp ../expect.with.ignored ../actual.full
)
'
@ -1051,7 +1051,7 @@ test_expect_success 'outside of git repository with fallbackToNoIndex' '
echo ".gitignore:.*o*" &&
cat ../expect.full
} >../expect.with.ignored &&
git -c grep.fallbackToNoIndex grep --no-exclude o >../actual.full &&
git -c grep.fallbackToNoIndex grep --no-exclude-standard o >../actual.full &&
test_cmp ../expect.with.ignored ../actual.full
)
'

Просмотреть файл

@ -57,6 +57,13 @@ fi
. "$GIT_BUILD_DIR"/GIT-BUILD-OPTIONS
export PERL_PATH SHELL_PATH
# Disallow the use of abbreviated options in the test suite by default
if test -z "${GIT_TEST_DISALLOW_ABBREVIATED_OPTIONS}"
then
GIT_TEST_DISALLOW_ABBREVIATED_OPTIONS=true
export GIT_TEST_DISALLOW_ABBREVIATED_OPTIONS
fi
################################################################
# It appears that people try to run tests without building...
"${GIT_TEST_INSTALLED:-$GIT_BUILD_DIR}/git$X" >/dev/null