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

t4008: modernise style

Update this ancient test script to a more modern style in which the
expected result is prepared inside the body of the test that uses
it.  Also, instead of using $tree, a shell variable, throughout the
test script, create a tag that points at it, to make it easier to
manually debug the test script in its trash directory.
Signed-off-by: NJunio C Hamano <gitster@pobox.com>
上级 bd9150b7
...@@ -24,165 +24,131 @@ Further, with -B and -M together, these should turn into two renames. ...@@ -24,165 +24,131 @@ Further, with -B and -M together, these should turn into two renames.
. ./test-lib.sh . ./test-lib.sh
. "$TEST_DIRECTORY"/diff-lib.sh ;# test-lib chdir's into trash . "$TEST_DIRECTORY"/diff-lib.sh ;# test-lib chdir's into trash
test_expect_success \ test_expect_success setup '
setup \ cat "$TEST_DIRECTORY"/diff-lib/README >file0 &&
'cat "$TEST_DIRECTORY"/diff-lib/README >file0 && cat "$TEST_DIRECTORY"/diff-lib/COPYING >file1 &&
cat "$TEST_DIRECTORY"/diff-lib/COPYING >file1 && git update-index --add file0 file1 &&
git update-index --add file0 file1 && git tag reference $(git write-tree)
tree=$(git write-tree) && '
echo "$tree"'
test_expect_success 'change file1 with copy-edit of file0 and remove file0' '
test_expect_success \ sed -e "s/git/GIT/" file0 >file1 &&
'change file1 with copy-edit of file0 and remove file0' \ rm -f file0 &&
'sed -e "s/git/GIT/" file0 >file1 && git update-index --remove file0 file1
rm -f file0 && '
git update-index --remove file0 file1'
test_expect_success 'run diff with -B (#1)' '
test_expect_success \ git diff-index -B --cached reference >current &&
'run diff with -B' \ cat >expect <<-\EOF &&
'git diff-index -B --cached "$tree" >current' :100644 000000 548142c327a6790ff8821d67c2ee1eff7a656b52 0000000000000000000000000000000000000000 D file0
:100644 100644 6ff87c4664981e4397625791c8ea3bbb5f2279a3 2fbedd0b5d4b8126e4750c3bee305e8ff79f80ec M100 file1
cat >expected <<\EOF EOF
:100644 000000 548142c327a6790ff8821d67c2ee1eff7a656b52 0000000000000000000000000000000000000000 D file0 compare_diff_raw expect current
:100644 100644 6ff87c4664981e4397625791c8ea3bbb5f2279a3 2fbedd0b5d4b8126e4750c3bee305e8ff79f80ec M100 file1 '
EOF
test_expect_success 'run diff with -B and -M (#2)' '
test_expect_success \ git diff-index -B -M reference >current &&
'validate result of -B (#1)' \ cat >expect <<-\EOF &&
'compare_diff_raw expected current' :100644 100644 548142c327a6790ff8821d67c2ee1eff7a656b52 2fbedd0b5d4b8126e4750c3bee305e8ff79f80ec R100 file0 file1
EOF
test_expect_success \ compare_diff_raw expect current
'run diff with -B and -M' \ '
'git diff-index -B -M "$tree" >current'
test_expect_success 'swap file0 and file1' '
cat >expected <<\EOF rm -f file0 file1 &&
:100644 100644 548142c327a6790ff8821d67c2ee1eff7a656b52 2fbedd0b5d4b8126e4750c3bee305e8ff79f80ec R100 file0 file1 git read-tree -m reference &&
EOF git checkout-index -f -u -a &&
mv file0 tmp &&
test_expect_success \ mv file1 file0 &&
'validate result of -B -M (#2)' \ mv tmp file1 &&
'compare_diff_raw expected current' git update-index file0 file1
'
test_expect_success \
'swap file0 and file1' \ test_expect_success 'run diff with -B (#3)' '
'rm -f file0 file1 && git diff-index -B reference >current &&
git read-tree -m $tree && cat >expect <<-\EOF &&
git checkout-index -f -u -a && :100644 100644 548142c327a6790ff8821d67c2ee1eff7a656b52 6ff87c4664981e4397625791c8ea3bbb5f2279a3 M100 file0
mv file0 tmp && :100644 100644 6ff87c4664981e4397625791c8ea3bbb5f2279a3 548142c327a6790ff8821d67c2ee1eff7a656b52 M100 file1
mv file1 file0 && EOF
mv tmp file1 && compare_diff_raw expect current
git update-index file0 file1' '
test_expect_success \ test_expect_success 'run diff with -B and -M (#4)' '
'run diff with -B' \ git diff-index -B -M reference >current &&
'git diff-index -B "$tree" >current' cat >expect <<-\EOF &&
:100644 100644 6ff87c4664981e4397625791c8ea3bbb5f2279a3 6ff87c4664981e4397625791c8ea3bbb5f2279a3 R100 file1 file0
cat >expected <<\EOF :100644 100644 548142c327a6790ff8821d67c2ee1eff7a656b52 548142c327a6790ff8821d67c2ee1eff7a656b52 R100 file0 file1
:100644 100644 548142c327a6790ff8821d67c2ee1eff7a656b52 6ff87c4664981e4397625791c8ea3bbb5f2279a3 M100 file0 EOF
:100644 100644 6ff87c4664981e4397625791c8ea3bbb5f2279a3 548142c327a6790ff8821d67c2ee1eff7a656b52 M100 file1 compare_diff_raw expect current
EOF '
test_expect_success \ test_expect_success 'make file0 into something completely different' '
'validate result of -B (#3)' \ rm -f file0 &&
'compare_diff_raw expected current' test_ln_s_add frotz file0 &&
git update-index file1
test_expect_success \ '
'run diff with -B and -M' \
'git diff-index -B -M "$tree" >current' test_expect_success 'run diff with -B (#5)' '
git diff-index -B reference >current &&
cat >expected <<\EOF cat >expect <<-\EOF &&
:100644 100644 6ff87c4664981e4397625791c8ea3bbb5f2279a3 6ff87c4664981e4397625791c8ea3bbb5f2279a3 R100 file1 file0 :100644 120000 548142c327a6790ff8821d67c2ee1eff7a656b52 67be421f88824578857624f7b3dc75e99a8a1481 T file0
:100644 100644 548142c327a6790ff8821d67c2ee1eff7a656b52 548142c327a6790ff8821d67c2ee1eff7a656b52 R100 file0 file1 :100644 100644 6ff87c4664981e4397625791c8ea3bbb5f2279a3 548142c327a6790ff8821d67c2ee1eff7a656b52 M100 file1
EOF EOF
compare_diff_raw expect current
test_expect_success \ '
'validate result of -B -M (#4)' \
'compare_diff_raw expected current' test_expect_success 'run diff with -B -M (#6)' '
git diff-index -B -M reference >current &&
test_expect_success \
'make file0 into something completely different' \ # file0 changed from regular to symlink. file1 is the same as the preimage
'rm -f file0 && # of file0. Because the change does not make file0 disappear, file1 is
test_ln_s_add frotz file0 && # denoted as a copy of file0
git update-index file1' cat >expect <<-\EOF &&
:100644 120000 548142c327a6790ff8821d67c2ee1eff7a656b52 67be421f88824578857624f7b3dc75e99a8a1481 T file0
test_expect_success \ :100644 100644 548142c327a6790ff8821d67c2ee1eff7a656b52 548142c327a6790ff8821d67c2ee1eff7a656b52 C file0 file1
'run diff with -B' \ EOF
'git diff-index -B "$tree" >current' compare_diff_raw expect current
'
cat >expected <<\EOF
:100644 120000 548142c327a6790ff8821d67c2ee1eff7a656b52 67be421f88824578857624f7b3dc75e99a8a1481 T file0 test_expect_success 'run diff with -M (#7)' '
:100644 100644 6ff87c4664981e4397625791c8ea3bbb5f2279a3 548142c327a6790ff8821d67c2ee1eff7a656b52 M100 file1 git diff-index -M reference >current &&
EOF
# This should not mistake file0 as the copy source of new file1
test_expect_success \ # due to type differences.
'validate result of -B (#5)' \ cat >expect <<-\EOF &&
'compare_diff_raw expected current' :100644 120000 548142c327a6790ff8821d67c2ee1eff7a656b52 67be421f88824578857624f7b3dc75e99a8a1481 T file0
:100644 100644 6ff87c4664981e4397625791c8ea3bbb5f2279a3 548142c327a6790ff8821d67c2ee1eff7a656b52 M file1
test_expect_success \ EOF
'run diff with -B -M' \ compare_diff_raw expect current
'git diff-index -B -M "$tree" >current' '
# file0 changed from regular to symlink. file1 is very close to the preimage of file0. test_expect_success 'file1 edited to look like file0 and file0 rename-edited to file2' '
# the change does not make file0 disappear, so file1 is denoted as a copy of file0 rm -f file0 file1 &&
cat >expected <<\EOF git read-tree -m reference &&
:100644 120000 548142c327a6790ff8821d67c2ee1eff7a656b52 67be421f88824578857624f7b3dc75e99a8a1481 T file0 git checkout-index -f -u -a &&
:100644 100644 548142c327a6790ff8821d67c2ee1eff7a656b52 548142c327a6790ff8821d67c2ee1eff7a656b52 C file0 file1 sed -e "s/git/GIT/" file0 >file1 &&
EOF sed -e "s/git/GET/" file0 >file2 &&
rm -f file0 &&
test_expect_success \ git update-index --add --remove file0 file1 file2
'validate result of -B -M (#6)' \ '
'compare_diff_raw expected current'
test_expect_success 'run diff with -B (#8)' '
test_expect_success \ git diff-index -B reference >current &&
'run diff with -M' \ cat >expect <<-\EOF &&
'git diff-index -M "$tree" >current' :100644 000000 548142c327a6790ff8821d67c2ee1eff7a656b52 0000000000000000000000000000000000000000 D file0
:100644 100644 6ff87c4664981e4397625791c8ea3bbb5f2279a3 2fbedd0b5d4b8126e4750c3bee305e8ff79f80ec M100 file1
# This should not mistake file0 as the copy source of new file1 :000000 100644 0000000000000000000000000000000000000000 69a939f651686f56322566e2fd76715947a24162 A file2
# due to type differences. EOF
cat >expected <<\EOF compare_diff_raw expect current
:100644 120000 548142c327a6790ff8821d67c2ee1eff7a656b52 67be421f88824578857624f7b3dc75e99a8a1481 T file0 '
:100644 100644 6ff87c4664981e4397625791c8ea3bbb5f2279a3 548142c327a6790ff8821d67c2ee1eff7a656b52 M file1
EOF test_expect_success 'run diff with -B -C (#9)' '
git diff-index -B -C reference >current &&
test_expect_success \ cat >expect <<-\EOF &&
'validate result of -M (#7)' \ :100644 100644 548142c327a6790ff8821d67c2ee1eff7a656b52 2fbedd0b5d4b8126e4750c3bee305e8ff79f80ec C095 file0 file1
'compare_diff_raw expected current' :100644 100644 548142c327a6790ff8821d67c2ee1eff7a656b52 69a939f651686f56322566e2fd76715947a24162 R095 file0 file2
EOF
test_expect_success \ compare_diff_raw expect current
'file1 edited to look like file0 and file0 rename-edited to file2' \ '
'rm -f file0 file1 &&
git read-tree -m $tree &&
git checkout-index -f -u -a &&
sed -e "s/git/GIT/" file0 >file1 &&
sed -e "s/git/GET/" file0 >file2 &&
rm -f file0 &&
git update-index --add --remove file0 file1 file2'
test_expect_success \
'run diff with -B' \
'git diff-index -B "$tree" >current'
cat >expected <<\EOF
:100644 000000 548142c327a6790ff8821d67c2ee1eff7a656b52 0000000000000000000000000000000000000000 D file0
:100644 100644 6ff87c4664981e4397625791c8ea3bbb5f2279a3 2fbedd0b5d4b8126e4750c3bee305e8ff79f80ec M100 file1
:000000 100644 0000000000000000000000000000000000000000 69a939f651686f56322566e2fd76715947a24162 A file2
EOF
test_expect_success \
'validate result of -B (#8)' \
'compare_diff_raw expected current'
test_expect_success \
'run diff with -B -C' \
'git diff-index -B -C "$tree" >current'
cat >expected <<\EOF
:100644 100644 548142c327a6790ff8821d67c2ee1eff7a656b52 2fbedd0b5d4b8126e4750c3bee305e8ff79f80ec C095 file0 file1
:100644 100644 548142c327a6790ff8821d67c2ee1eff7a656b52 69a939f651686f56322566e2fd76715947a24162 R095 file0 file2
EOF
test_expect_success \
'validate result of -B -M (#9)' \
'compare_diff_raw expected current'
test_done test_done
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册