提交 6508d035 编写于 作者: J Junio C Hamano

Merge branch 'jc/test-prereq' into maint

* jc/test-prereq:
  t3910: use the UTF8_NFD_TO_NFC test prereq
  test-lib: provide UTF8 behaviour as a prerequisite
  t0050: use the SYMLINKS test prereq
  t0050: use the CASE_INSENSITIVE_FS test prereq
  test-lib: provide case insensitivity as a prerequisite
  test: allow prerequisite to be evaluated lazily
  test: rename $satisfied to $satisfied_prereq
...@@ -625,6 +625,15 @@ use these, and "test_set_prereq" for how to define your own. ...@@ -625,6 +625,15 @@ use these, and "test_set_prereq" for how to define your own.
Git was compiled with USE_LIBPCRE=YesPlease. Wrap any tests Git was compiled with USE_LIBPCRE=YesPlease. Wrap any tests
that use git-grep --perl-regexp or git-grep -P in these. that use git-grep --perl-regexp or git-grep -P in these.
- CASE_INSENSITIVE_FS
Test is run on a case insensitive file system.
- UTF8_NFD_TO_NFC
Test is run on a filesystem which converts decomposed utf-8 (nfd)
to precomposed utf-8 (nfc).
Tips for Writing Tests Tips for Writing Tests
---------------------- ----------------------
......
...@@ -123,16 +123,6 @@ test_expect_success 'attribute matching is case insensitive when core.ignorecase ...@@ -123,16 +123,6 @@ test_expect_success 'attribute matching is case insensitive when core.ignorecase
' '
test_expect_success 'check whether FS is case-insensitive' '
mkdir junk &&
echo good >junk/CamelCase &&
echo bad >junk/camelcase &&
if test "$(cat junk/CamelCase)" != good
then
test_set_prereq CASE_INSENSITIVE_FS
fi
'
test_expect_success CASE_INSENSITIVE_FS 'additional case insensitivity tests' ' test_expect_success CASE_INSENSITIVE_FS 'additional case insensitivity tests' '
test_must_fail attr_check a/B/D/g "a/b/d/*" "-c core.ignorecase=0" && test_must_fail attr_check a/B/D/g "a/b/d/*" "-c core.ignorecase=0" &&
test_must_fail attr_check A/B/D/NO "a/b/d/*" "-c core.ignorecase=0" && test_must_fail attr_check A/B/D/NO "a/b/d/*" "-c core.ignorecase=0" &&
......
...@@ -7,48 +7,26 @@ test_description='Various filesystem issues' ...@@ -7,48 +7,26 @@ test_description='Various filesystem issues'
auml=$(printf '\303\244') auml=$(printf '\303\244')
aumlcdiar=$(printf '\141\314\210') aumlcdiar=$(printf '\141\314\210')
case_insensitive= if test_have_prereq CASE_INSENSITIVE_FS
unibad= then
no_symlinks=
test_expect_success 'see what we expect' '
test_case=test_expect_success &&
test_unicode=test_expect_success &&
mkdir junk &&
echo good >junk/CamelCase &&
echo bad >junk/camelcase &&
if test "$(cat junk/CamelCase)" != good
then
test_case=test_expect_failure &&
case_insensitive=t
fi &&
rm -fr junk &&
mkdir junk &&
>junk/"$auml" &&
case "$(cd junk && echo *)" in
"$aumlcdiar")
test_unicode=test_expect_failure &&
unibad=t
;;
*) ;;
esac &&
rm -fr junk &&
{
ln -s x y 2> /dev/null &&
test -h y 2> /dev/null ||
no_symlinks=1 &&
rm -f y
}
'
test "$case_insensitive" &&
say "will test on a case insensitive filesystem" say "will test on a case insensitive filesystem"
test "$unibad" && test_case=test_expect_failure
else
test_case=test_expect_success
fi
if test_have_prereq UTF8_NFD_TO_NFC
then
say "will test on a unicode corrupting filesystem" say "will test on a unicode corrupting filesystem"
test "$no_symlinks" && test_unicode=test_expect_failure
else
test_unicode=test_expect_success
fi
test_have_prereq SYMLINKS ||
say "will test on a filesystem lacking symbolic links" say "will test on a filesystem lacking symbolic links"
if test "$case_insensitive" if test_have_prereq CASE_INSENSITIVE_FS
then then
test_expect_success "detection of case insensitive filesystem during repo init" ' test_expect_success "detection of case insensitive filesystem during repo init" '
...@@ -62,18 +40,18 @@ test_expect_success "detection of case insensitive filesystem during repo init" ...@@ -62,18 +40,18 @@ test_expect_success "detection of case insensitive filesystem during repo init"
' '
fi fi
if test "$no_symlinks" if test_have_prereq SYMLINKS
then then
test_expect_success "detection of filesystem w/o symlink support during repo init" ' test_expect_success "detection of filesystem w/o symlink support during repo init" '
v=$(git config --bool core.symlinks) && test_must_fail git config --bool core.symlinks ||
test "$v" = false test "$(git config --bool core.symlinks)" = true
' '
else else
test_expect_success "detection of filesystem w/o symlink support during repo init" ' test_expect_success "detection of filesystem w/o symlink support during repo init" '
test_must_fail git config --bool core.symlinks || v=$(git config --bool core.symlinks) &&
test "$(git config --bool core.symlinks)" = true test "$v" = false
' '
fi fi
......
...@@ -7,158 +7,147 @@ test_description='utf-8 decomposed (nfd) converted to precomposed (nfc)' ...@@ -7,158 +7,147 @@ test_description='utf-8 decomposed (nfd) converted to precomposed (nfc)'
. ./test-lib.sh . ./test-lib.sh
if ! test_have_prereq UTF8_NFD_TO_NFC
then
skip_all="filesystem does not corrupt utf-8"
test_done
fi
# create utf-8 variables
Adiarnfc=`printf '\303\204'` Adiarnfc=`printf '\303\204'`
Adiarnfd=`printf 'A\314\210'` Adiarnfd=`printf 'A\314\210'`
# check if the feature is compiled in Odiarnfc=`printf '\303\226'`
mkdir junk && Odiarnfd=`printf 'O\314\210'`
>junk/"$Adiarnfc" && AEligatu=`printf '\303\206'`
case "$(cd junk && echo *)" in Invalidu=`printf '\303\377'`
"$Adiarnfd")
test_nfd=1
;;
*) ;;
esac
rm -rf junk
if test "$test_nfd" #Create a string with 255 bytes (decomposed)
then Alongd=$Adiarnfd$Adiarnfd$Adiarnfd$Adiarnfd$Adiarnfd$Adiarnfd$Adiarnfd #21 Byte
# create more utf-8 variables Alongd=$Alongd$Alongd$Alongd #63 Byte
Odiarnfc=`printf '\303\226'` Alongd=$Alongd$Alongd$Alongd$Alongd$Adiarnfd #255 Byte
Odiarnfd=`printf 'O\314\210'`
AEligatu=`printf '\303\206'`
Invalidu=`printf '\303\377'`
#Create a string with 254 bytes (precomposed)
Alongc=$AEligatu$AEligatu$AEligatu$AEligatu$AEligatu #10 Byte
Alongc=$Alongc$Alongc$Alongc$Alongc$Alongc #50 Byte
Alongc=$Alongc$Alongc$Alongc$Alongc$Alongc #250 Byte
Alongc=$Alongc$AEligatu$AEligatu #254 Byte
#Create a string with 255 bytes (decomposed) test_expect_success "detect if nfd needed" '
Alongd=$Adiarnfd$Adiarnfd$Adiarnfd$Adiarnfd$Adiarnfd$Adiarnfd$Adiarnfd #21 Byte precomposeunicode=`git config core.precomposeunicode` &&
Alongd=$Alongd$Alongd$Alongd #63 Byte test "$precomposeunicode" = false &&
Alongd=$Alongd$Alongd$Alongd$Alongd$Adiarnfd #255 Byte git config core.precomposeunicode true
'
#Create a string with 254 bytes (precomposed) test_expect_success "setup" '
Alongc=$AEligatu$AEligatu$AEligatu$AEligatu$AEligatu #10 Byte >x &&
Alongc=$Alongc$Alongc$Alongc$Alongc$Alongc #50 Byte git add x &&
Alongc=$Alongc$Alongc$Alongc$Alongc$Alongc #250 Byte git commit -m "1st commit" &&
Alongc=$Alongc$AEligatu$AEligatu #254 Byte git rm x &&
git commit -m "rm x"
test_expect_success "detect if nfd needed" ' '
precomposeunicode=`git config core.precomposeunicode` && test_expect_success "setup case mac" '
test "$precomposeunicode" = false && git checkout -b mac_os
git config core.precomposeunicode true '
' # This will test nfd2nfc in readdir()
test_expect_success "setup" ' test_expect_success "add file Adiarnfc" '
>x && echo f.Adiarnfc >f.$Adiarnfc &&
git add x && git add f.$Adiarnfc &&
git commit -m "1st commit" && git commit -m "add f.$Adiarnfc"
git rm x && '
git commit -m "rm x" # This will test nfd2nfc in git stage()
' test_expect_success "stage file d.Adiarnfd/f.Adiarnfd" '
test_expect_success "setup case mac" ' mkdir d.$Adiarnfd &&
git checkout -b mac_os echo d.$Adiarnfd/f.$Adiarnfd >d.$Adiarnfd/f.$Adiarnfd &&
' git stage d.$Adiarnfd/f.$Adiarnfd &&
# This will test nfd2nfc in readdir() git commit -m "add d.$Adiarnfd/f.$Adiarnfd"
test_expect_success "add file Adiarnfc" ' '
echo f.Adiarnfc >f.$Adiarnfc && test_expect_success "add link Adiarnfc" '
git add f.$Adiarnfc && ln -s d.$Adiarnfd/f.$Adiarnfd l.$Adiarnfc &&
git commit -m "add f.$Adiarnfc" git add l.$Adiarnfc &&
' git commit -m "add l.Adiarnfc"
# This will test nfd2nfc in git stage() '
test_expect_success "stage file d.Adiarnfd/f.Adiarnfd" ' # This will test git log
mkdir d.$Adiarnfd && test_expect_success "git log f.Adiar" '
echo d.$Adiarnfd/f.$Adiarnfd >d.$Adiarnfd/f.$Adiarnfd && git log f.$Adiarnfc > f.Adiarnfc.log &&
git stage d.$Adiarnfd/f.$Adiarnfd && git log f.$Adiarnfd > f.Adiarnfd.log &&
git commit -m "add d.$Adiarnfd/f.$Adiarnfd" test -s f.Adiarnfc.log &&
' test -s f.Adiarnfd.log &&
test_expect_success "add link Adiarnfc" ' test_cmp f.Adiarnfc.log f.Adiarnfd.log &&
ln -s d.$Adiarnfd/f.$Adiarnfd l.$Adiarnfc && rm f.Adiarnfc.log f.Adiarnfd.log
git add l.$Adiarnfc && '
git commit -m "add l.Adiarnfc" # This will test git ls-files
' test_expect_success "git lsfiles f.Adiar" '
# This will test git log git ls-files f.$Adiarnfc > f.Adiarnfc.log &&
test_expect_success "git log f.Adiar" ' git ls-files f.$Adiarnfd > f.Adiarnfd.log &&
git log f.$Adiarnfc > f.Adiarnfc.log && test -s f.Adiarnfc.log &&
git log f.$Adiarnfd > f.Adiarnfd.log && test -s f.Adiarnfd.log &&
test -s f.Adiarnfc.log && test_cmp f.Adiarnfc.log f.Adiarnfd.log &&
test -s f.Adiarnfd.log && rm f.Adiarnfc.log f.Adiarnfd.log
test_cmp f.Adiarnfc.log f.Adiarnfd.log && '
rm f.Adiarnfc.log f.Adiarnfd.log # This will test git mv
' test_expect_success "git mv" '
# This will test git ls-files git mv f.$Adiarnfd f.$Odiarnfc &&
test_expect_success "git lsfiles f.Adiar" ' git mv d.$Adiarnfd d.$Odiarnfc &&
git ls-files f.$Adiarnfc > f.Adiarnfc.log && git mv l.$Adiarnfd l.$Odiarnfc &&
git ls-files f.$Adiarnfd > f.Adiarnfd.log && git commit -m "mv Adiarnfd Odiarnfc"
test -s f.Adiarnfc.log && '
test -s f.Adiarnfd.log && # Files can be checked out as nfc
test_cmp f.Adiarnfc.log f.Adiarnfd.log && # And the link has been corrected from nfd to nfc
rm f.Adiarnfc.log f.Adiarnfd.log test_expect_success "git checkout nfc" '
' rm f.$Odiarnfc &&
# This will test git mv git checkout f.$Odiarnfc
test_expect_success "git mv" ' '
git mv f.$Adiarnfd f.$Odiarnfc && # Make it possible to checkout files with their NFD names
git mv d.$Adiarnfd d.$Odiarnfc && test_expect_success "git checkout file nfd" '
git mv l.$Adiarnfd l.$Odiarnfc && rm -f f.* &&
git commit -m "mv Adiarnfd Odiarnfc" git checkout f.$Odiarnfd
' '
# Files can be checked out as nfc # Make it possible to checkout links with their NFD names
# And the link has been corrected from nfd to nfc test_expect_success "git checkout link nfd" '
test_expect_success "git checkout nfc" ' rm l.* &&
rm f.$Odiarnfc && git checkout l.$Odiarnfd
git checkout f.$Odiarnfc '
' test_expect_success "setup case mac2" '
# Make it possible to checkout files with their NFD names git checkout master &&
test_expect_success "git checkout file nfd" ' git reset --hard &&
rm -f f.* && git checkout -b mac_os_2
git checkout f.$Odiarnfd '
' # This will test nfd2nfc in git commit
# Make it possible to checkout links with their NFD names test_expect_success "commit file d2.Adiarnfd/f.Adiarnfd" '
test_expect_success "git checkout link nfd" ' mkdir d2.$Adiarnfd &&
rm l.* && echo d2.$Adiarnfd/f.$Adiarnfd >d2.$Adiarnfd/f.$Adiarnfd &&
git checkout l.$Odiarnfd git add d2.$Adiarnfd/f.$Adiarnfd &&
' git commit -m "add d2.$Adiarnfd/f.$Adiarnfd" -- d2.$Adiarnfd/f.$Adiarnfd
test_expect_success "setup case mac2" ' '
git checkout master && test_expect_success "setup for long decomposed filename" '
git reset --hard && git checkout master &&
git checkout -b mac_os_2 git reset --hard &&
' git checkout -b mac_os_long_nfd_fn
# This will test nfd2nfc in git commit '
test_expect_success "commit file d2.Adiarnfd/f.Adiarnfd" ' test_expect_success "Add long decomposed filename" '
mkdir d2.$Adiarnfd && echo longd >$Alongd &&
echo d2.$Adiarnfd/f.$Adiarnfd >d2.$Adiarnfd/f.$Adiarnfd && git add * &&
git add d2.$Adiarnfd/f.$Adiarnfd && git commit -m "Long filename"
git commit -m "add d2.$Adiarnfd/f.$Adiarnfd" -- d2.$Adiarnfd/f.$Adiarnfd '
' test_expect_success "setup for long precomposed filename" '
test_expect_success "setup for long decomposed filename" ' git checkout master &&
git checkout master && git reset --hard &&
git reset --hard && git checkout -b mac_os_long_nfc_fn
git checkout -b mac_os_long_nfd_fn '
' test_expect_success "Add long precomposed filename" '
test_expect_success "Add long decomposed filename" ' echo longc >$Alongc &&
echo longd >$Alongd && git add * &&
git add * && git commit -m "Long filename"
git commit -m "Long filename" '
' # Test if the global core.precomposeunicode stops autosensing
test_expect_success "setup for long precomposed filename" ' # Must be the last test case
git checkout master && test_expect_success "respect git config --global core.precomposeunicode" '
git reset --hard && git config --global core.precomposeunicode true &&
git checkout -b mac_os_long_nfc_fn rm -rf .git &&
' git init &&
test_expect_success "Add long precomposed filename" ' precomposeunicode=`git config core.precomposeunicode` &&
echo longc >$Alongc && test "$precomposeunicode" = "true"
git add * && '
git commit -m "Long filename"
'
# Test if the global core.precomposeunicode stops autosensing
# Must be the last test case
test_expect_success "respect git config --global core.precomposeunicode" '
git config --global core.precomposeunicode true &&
rm -rf .git &&
git init &&
precomposeunicode=`git config core.precomposeunicode` &&
test "$precomposeunicode" = "true"
'
else
say "Skipping nfc/nfd tests"
fi
test_done test_done
...@@ -221,9 +221,35 @@ write_script () { ...@@ -221,9 +221,35 @@ write_script () {
# capital letters by convention). # capital letters by convention).
test_set_prereq () { test_set_prereq () {
satisfied="$satisfied$1 " satisfied_prereq="$satisfied_prereq$1 "
}
satisfied_prereq=" "
lazily_testable_prereq= lazily_tested_prereq=
# Usage: test_lazy_prereq PREREQ 'script'
test_lazy_prereq () {
lazily_testable_prereq="$lazily_testable_prereq$1 "
eval test_prereq_lazily_$1=\$2
}
test_run_lazy_prereq_ () {
script='
mkdir -p "$TRASH_DIRECTORY/prereq-test-dir" &&
(
cd "$TRASH_DIRECTORY/prereq-test-dir" &&'"$2"'
)'
say >&3 "checking prerequisite: $1"
say >&3 "$script"
test_eval_ "$script"
eval_ret=$?
rm -rf "$TRASH_DIRECTORY/prereq-test-dir"
if test "$eval_ret" = 0; then
say >&3 "prerequisite $1 ok"
else
say >&3 "prerequisite $1 not satisfied"
fi
return $eval_ret
} }
satisfied=" "
test_have_prereq () { test_have_prereq () {
# prerequisites can be concatenated with ',' # prerequisites can be concatenated with ','
...@@ -238,8 +264,24 @@ test_have_prereq () { ...@@ -238,8 +264,24 @@ test_have_prereq () {
for prerequisite for prerequisite
do do
case " $lazily_tested_prereq " in
*" $prerequisite "*)
;;
*)
case " $lazily_testable_prereq " in
*" $prerequisite "*)
eval "script=\$test_prereq_lazily_$prerequisite" &&
if test_run_lazy_prereq_ "$prerequisite" "$script"
then
test_set_prereq $prerequisite
fi
lazily_tested_prereq="$lazily_tested_prereq$prerequisite "
esac
;;
esac
total_prereq=$(($total_prereq + 1)) total_prereq=$(($total_prereq + 1))
case $satisfied in case "$satisfied_prereq" in
*" $prerequisite "*) *" $prerequisite "*)
ok_prereq=$(($ok_prereq + 1)) ok_prereq=$(($ok_prereq + 1))
;; ;;
......
...@@ -659,9 +659,29 @@ test_i18ngrep () { ...@@ -659,9 +659,29 @@ test_i18ngrep () {
fi fi
} }
# test whether the filesystem supports symbolic links test_lazy_prereq SYMLINKS '
ln -s x y 2>/dev/null && test -h y 2>/dev/null && test_set_prereq SYMLINKS # test whether the filesystem supports symbolic links
rm -f y ln -s x y && test -h y
'
test_lazy_prereq CASE_INSENSITIVE_FS '
echo good >CamelCase &&
echo bad >camelcase &&
test "$(cat CamelCase)" != good
'
test_lazy_prereq UTF8_NFD_TO_NFC '
# check whether FS converts nfd unicode to nfc
auml=$(printf "\303\244")
aumlcdiar=$(printf "\141\314\210")
>"$auml" &&
case "$(echo *)" in
"$aumlcdiar")
true ;;
*)
false ;;
esac
'
# When the tests are run as root, permission tests will report that # When the tests are run as root, permission tests will report that
# things are writable when they shouldn't be. # things are writable when they shouldn't be.
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册