From: Junio C Hamano Date: Thu, 5 Mar 2015 20:45:43 +0000 (-0800) Subject: Merge branch 'jc/diff-test-updates' X-Git-Tag: v2.4.0-rc0~69 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/fa8baa4b2acf6f8be8f28bf84493e0889e45eb91?hp=-c Merge branch 'jc/diff-test-updates' Test clean-up. * jc/diff-test-updates: test_ln_s_add: refresh stat info of fake symbolic links t4008: modernise style t/diff-lib: check exact object names in compare_diff_raw tests: do not borrow from COPYING and README from the real source t4010: correct expected object names t9300: correct expected object names t4008: correct stale comments --- fa8baa4b2acf6f8be8f28bf84493e0889e45eb91 diff --combined t/t4005-diff-rename-2.sh index 7d2c6e13a2,3b23dc4fd5..135addbfbd --- a/t/t4005-diff-rename-2.sh +++ b/t/t4005-diff-rename-2.sh @@@ -11,7 -11,7 +11,7 @@@ test_description='Same rename detectio test_expect_success \ 'prepare reference tree' \ - 'cat "$TEST_DIRECTORY"/../COPYING >COPYING && + 'cat "$TEST_DIRECTORY"/diff-lib/COPYING >COPYING && echo frotz >rezrov && git update-index --add COPYING rezrov && tree=$(git write-tree) && @@@ -66,12 -66,12 +66,12 @@@ test_expect_success # tree has COPYING and rezrov. work tree has the same COPYING and # copy-edited COPYING.1, and unchanged rezrov. We should not say -# anything about rezrov nor COPYING, since the revised again diff-raw +# anything about rezrov or COPYING, since the revised again diff-raw # nows how to say Copy. test_expect_success \ 'prepare work tree once again' \ - 'cat "$TEST_DIRECTORY"/../COPYING >COPYING && + 'cat "$TEST_DIRECTORY"/diff-lib/COPYING >COPYING && git update-index --add --remove COPYING COPYING.1' git diff-index -C --find-copies-harder $tree >current diff --combined t/t4009-diff-rename-4.sh index 57c094fdce,4b520d6001..3641fd84d6 --- a/t/t4009-diff-rename-4.sh +++ b/t/t4009-diff-rename-4.sh @@@ -11,7 -11,7 +11,7 @@@ test_description='Same rename detectio test_expect_success \ 'prepare reference tree' \ - 'cat "$TEST_DIRECTORY"/../COPYING >COPYING && + 'cat "$TEST_DIRECTORY"/diff-lib/COPYING >COPYING && echo frotz >rezrov && git update-index --add COPYING rezrov && tree=$(git write-tree) && @@@ -73,12 -73,12 +73,12 @@@ test_expect_success # tree has COPYING and rezrov. work tree has the same COPYING and # copy-edited COPYING.1, and unchanged rezrov. We should not say -# anything about rezrov nor COPYING, since the revised again diff-raw +# anything about rezrov or COPYING, since the revised again diff-raw # nows how to say Copy. test_expect_success \ 'prepare work tree once again' \ - 'cat "$TEST_DIRECTORY"/../COPYING >COPYING && + 'cat "$TEST_DIRECTORY"/diff-lib/COPYING >COPYING && git update-index --add --remove COPYING COPYING.1' git diff-index -z -C --find-copies-harder $tree >current diff --combined t/t4010-diff-pathspec.sh index bf07841866,6219a2ec21..43c488b545 --- a/t/t4010-diff-pathspec.sh +++ b/t/t4010-diff-pathspec.sh @@@ -18,7 -18,7 +18,7 @@@ test_expect_success mkdir path1 && echo rezrov >path1/file1 && git update-index --add file0 path1/file1 && - tree=`git write-tree` && + tree=$(git write-tree) && echo "$tree" && echo nitfol >file0 && echo yomin >path1/file1 && @@@ -56,7 -56,7 +56,7 @@@ test_expect_success compare_diff_raw current expected' cat >expected <<\EOF - :100644 100644 766498d93a4b06057a8e49d23f4068f1170ff38f 0a41e115ab61be0328a19b29f18cdcb49338d516 M file0 + :100644 100644 8e4020bb5a8d8c873b25de15933e75cc0fc275df dca6b92303befc93086aa025d90a5facd7eb2812 M file0 EOF test_expect_success \ 'limit to file0 should show file0' \ @@@ -110,28 -110,11 +110,28 @@@ test_expect_success 'diff-tree -r with test_cmp expected result ' +test_expect_success 'setup submodules' ' + test_tick && + git init submod && + ( cd submod && test_commit first; ) && + git add submod && + git commit -m first && + ( cd submod && test_commit second; ) && + git add submod && + git commit -m second +' + +test_expect_success 'diff-tree ignores trailing slash on submodule path' ' + git diff --name-only HEAD^ HEAD submod >expect && + git diff --name-only HEAD^ HEAD submod/ >actual && + test_cmp expect actual +' + test_expect_success 'diff multiple wildcard pathspecs' ' mkdir path2 && echo rezrov >path2/file1 && git update-index --add path2/file1 && - tree3=`git write-tree` && + tree3=$(git write-tree) && git diff --name-only $tree $tree3 -- "path2*1" "path1*1" >actual && cat <<-\EOF >expect && path1/file1 @@@ -140,10 -123,4 +140,10 @@@ test_cmp expect actual ' +test_expect_success 'diff-cache ignores trailing slash on submodule path' ' + git diff --name-only HEAD^ submod >expect && + git diff --name-only HEAD^ submod/ >actual && + test_cmp expect actual +' + test_done diff --combined t/t9300-fast-import.sh index 37c2d633f0,e53def226a..c538e0a4e9 --- a/t/t9300-fast-import.sh +++ b/t/t9300-fast-import.sh @@@ -346,6 -346,36 +346,6 @@@ test_expect_success 'B: fail on invali ' rm -f .git/objects/pack_* .git/objects/index_* -cat >input < $GIT_COMMITTER_DATE -data <input < $GIT_COMMITTER_DATE -data <input < $GIT_COMMITTER_DATE @@@ -552,8 -582,8 +552,8 @@@ test_expect_success 'D: verify pack' ' cat >expect <actual test_expect_success \ @@@ -2306,7 -2336,7 +2306,7 @@@ test_expect_success 'R: cat-blob-fd mus test_must_fail git fast-import --cat-blob-fd=-1 expect <<-EOF && ${blob} blob 11 @@@ -2318,7 -2348,7 +2318,7 @@@ test_cmp expect actual ' -test_expect_success NOT_MINGW 'R: in-stream cat-blob-fd not respected' ' +test_expect_success !MINGW 'R: in-stream cat-blob-fd not respected' ' echo hello >greeting && blob=$(git hash-object -w greeting) && cat >expect <<-EOF && @@@ -2339,7 -2369,7 +2339,7 @@@ test_cmp expect actual.1 ' -test_expect_success NOT_MINGW 'R: print new blob' ' +test_expect_success !MINGW 'R: print new blob' ' blob=$(echo "yep yep yep" | git hash-object --stdin) && cat >expect <<-EOF && ${blob} blob 12 @@@ -2357,7 -2387,7 +2357,7 @@@ test_cmp expect actual ' -test_expect_success NOT_MINGW 'R: print new blob by sha1' ' +test_expect_success !MINGW 'R: print new blob by sha1' ' blob=$(echo "a new blob named by sha1" | git hash-object --stdin) && cat >expect <<-EOF && ${blob} blob 25 @@@ -2657,7 -2687,7 +2657,7 @@@ test_expect_success 'R: verify created test_expect_success \ 'R: verify written objects' \ 'git --git-dir=R/.git cat-file blob big-file:big1 >actual && - test_cmp expect actual && + test_cmp_bin expect actual && a=$(git --git-dir=R/.git rev-parse big-file:big1) && b=$(git --git-dir=R/.git rev-parse big-file:big2) && test $a = $b' @@@ -2836,7 -2866,7 +2836,7 @@@ test_expect_success 'S: notemodify wit # # notemodify, mark in commit-ish # -test_expect_success 'S: notemodify with garbarge after mark commit-ish must fail' ' +test_expect_success 'S: notemodify with garbage after mark commit-ish must fail' ' test_must_fail git fast-import --import-marks=marks <<-EOF 2>err && commit refs/heads/Snotes committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE @@@ -2969,126 -2999,4 +2969,126 @@@ test_expect_success 'T: ls root tree' test_cmp expect actual ' +test_expect_success 'T: delete branch' ' + git branch to-delete && + git fast-import <<-EOF && + reset refs/heads/to-delete + from 0000000000000000000000000000000000000000 + EOF + test_must_fail git rev-parse --verify refs/heads/to-delete +' + +test_expect_success 'T: empty reset doesnt delete branch' ' + git branch not-to-delete && + git fast-import <<-EOF && + reset refs/heads/not-to-delete + EOF + git show-ref && + git rev-parse --verify refs/heads/not-to-delete +' + +### +### series U (filedelete) +### + +cat >input < $GIT_COMMITTER_DATE +data <input < $GIT_COMMITTER_DATE +data <expect <actual + +test_expect_success 'U: validate file delete result' ' + compare_diff_raw expect actual +' + +cat >input < $GIT_COMMITTER_DATE +data <expect <actual + +test_expect_success 'U: validate directory delete result' ' + compare_diff_raw expect actual +' + +cat >input < $GIT_COMMITTER_DATE +data <expect <actual + +test_expect_success 'U: validate root delete result' ' + compare_diff_raw expect actual +' + test_done diff --combined t/test-lib-functions.sh index 0d93e33de4,17ecf4f168..0698ce7908 --- a/t/test-lib-functions.sh +++ b/t/test-lib-functions.sh @@@ -1,5 -1,4 +1,5 @@@ -#!/bin/sh +# Library of functions shared by all tests scripts, included by +# test-lib.sh. # # Copyright (c) 2005 Junio C Hamano # @@@ -32,11 -31,6 +32,11 @@@ test_set_editor () export EDITOR } +test_set_index_version () { + GIT_INDEX_VERSION="$1" + export GIT_INDEX_VERSION +} + test_decode_color () { awk ' function name(n) { @@@ -413,7 -407,7 +413,7 @@@ test_external () # test_run_, but keep its stdout on our stdout even in # non-verbose mode. "$@" 2>&4 - if [ "$?" = 0 ] + if test "$?" = 0 then if test $test_external_has_tap -eq 0; then test_ok_ "$descr" @@@ -440,12 -434,11 +440,12 @@@ test_external_without_stderr () tmp=${TMPDIR:-/tmp} stderr="$tmp/git-external-stderr.$$.tmp" test_external "$@" 4> "$stderr" - [ -f "$stderr" ] || error "Internal error: $stderr disappeared." + test -f "$stderr" || error "Internal error: $stderr disappeared." descr="no stderr: $1" shift say >&3 "# expecting no stderr from previous command" - if [ ! -s "$stderr" ]; then + if test ! -s "$stderr" + then rm "$stderr" if test $test_external_has_tap -eq 0; then @@@ -455,9 -448,8 +455,9 @@@ test_success=$(($test_success + 1)) fi else - if [ "$verbose" = t ]; then - output=`echo; echo "# Stderr is:"; cat "$stderr"` + if test "$verbose" = t + then + output=$(echo; echo "# Stderr is:"; cat "$stderr") else output= fi @@@ -476,7 -468,7 +476,7 @@@ # The commands test the existence or non-existence of $1. $2 can be # given to provide a more precise diagnosis. test_path_is_file () { - if ! [ -f "$1" ] + if ! test -f "$1" then echo "File $1 doesn't exist. $*" false @@@ -484,31 -476,19 +484,31 @@@ } test_path_is_dir () { - if ! [ -d "$1" ] + if ! test -d "$1" then echo "Directory $1 doesn't exist. $*" false fi } +# Check if the directory exists and is empty as expected, barf otherwise. +test_dir_is_empty () { + test_path_is_dir "$1" && + if test -n "$(ls -a1 "$1" | egrep -v '^\.\.?$')" + then + echo "Directory '$1' is not empty, it contains:" + ls -la "$1" + return 1 + fi +} + test_path_is_missing () { - if [ -e "$1" ] + if test -e "$1" then echo "Path exists:" ls -ld "$1" - if [ $# -ge 1 ]; then + if test $# -ge 1 + then echo "$*" fi false @@@ -556,7 -536,7 +556,7 @@@ test_must_fail () if test $exit_code = 0; then echo >&2 "test_must_fail: command succeeded: $*" return 1 - elif test $exit_code -gt 129 -a $exit_code -le 192; then + elif test $exit_code -gt 129 && test $exit_code -le 192; then echo >&2 "test_must_fail: died by signal: $*" return 1 elif test $exit_code = 127; then @@@ -583,7 -563,7 +583,7 @@@ test_might_fail () { "$@" exit_code=$? - if test $exit_code -gt 129 -a $exit_code -le 192; then + if test $exit_code -gt 129 && test $exit_code -le 192; then echo >&2 "test_might_fail: died by signal: $*" return 1 elif test $exit_code = 127; then @@@ -631,21 -611,6 +631,21 @@@ test_cmp() $GIT_TEST_CMP "$@" } +# test_cmp_bin - helper to compare binary files + +test_cmp_bin() { + cmp "$@" +} + +# Call any command "$@" but be more verbose about its +# failure. This is handy for commands like "test" which do +# not output anything when they fail. +verbose () { + "$@" && return 0 + echo >&2 "command failed: $(git rev-parse --sq-quote "$@")" + return 1 +} + # Check if the file expected to be empty is indeed empty, and barfs # otherwise. @@@ -669,12 -634,9 +669,12 @@@ test_cmp_rev () # similar to GNU seq(1), but the latter might not be available # everywhere (and does not do letters). It may be used like: # -# for i in `test_seq 100`; do -# for j in `test_seq 10 20`; do -# for k in `test_seq a z`; do +# for i in $(test_seq 100) +# do +# for j in $(test_seq 10 20) +# do +# for k in $(test_seq a z) +# do # echo $i-$j-$k # done # done @@@ -745,77 -707,16 +745,79 @@@ test_ln_s_add () else printf '%s' "$1" >"$2" && ln_s_obj=$(git hash-object -w "$2") && - git update-index --add --cacheinfo 120000 $ln_s_obj "$2" + git update-index --add --cacheinfo 120000 $ln_s_obj "$2" && + # pick up stat info from the file + git update-index "$2" fi } +# This function writes out its parameters, one per line +test_write_lines () { + printf "%s\n" "$@" +} + perl () { command "$PERL_PATH" "$@" } +# Is the value one of the various ways to spell a boolean true/false? +test_normalize_bool () { + git -c magic.variable="$1" config --bool magic.variable 2>/dev/null +} + +# Given a variable $1, normalize the value of it to one of "true", +# "false", or "auto" and store the result to it. +# +# test_tristate GIT_TEST_HTTPD +# +# A variable set to an empty string is set to 'false'. +# A variable set to 'false' or 'auto' keeps its value. +# Anything else is set to 'true'. +# An unset variable defaults to 'auto'. +# +# The last rule is to allow people to set the variable to an empty +# string and export it to decline testing the particular feature +# for versions both before and after this change. We used to treat +# both unset and empty variable as a signal for "do not test" and +# took any non-empty string as "please test". + +test_tristate () { + if eval "test x\"\${$1+isset}\" = xisset" + then + # explicitly set + eval " + case \"\$$1\" in + '') $1=false ;; + auto) ;; + *) $1=\$(test_normalize_bool \$$1 || echo true) ;; + esac + " + else + eval "$1=auto" + fi +} + +# Exit the test suite, either by skipping all remaining tests or by +# exiting with an error. If "$1" is "auto", we then we assume we were +# opportunistically trying to set up some tests and we skip. If it is +# "true", then we report a failure. +# +# The error/skip message should be given by $2. +# +test_skip_or_die () { + case "$1" in + auto) + skip_all=$2 + test_done + ;; + true) + error "$2" + ;; + *) + error "BUG: test tristate is '$1' (real error: $2)" + esac +} + # The following mingw_* functions obey POSIX shell syntax, but are actually # bash scripts, and are meant to be used only with bash on Windows.