diff options
Diffstat (limited to 't/test-lib-functions.sh')
-rw-r--r-- | t/test-lib-functions.sh | 179 |
1 files changed, 109 insertions, 70 deletions
diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh index 2f08ce7cba..6348e8d733 100644 --- a/t/test-lib-functions.sh +++ b/t/test-lib-functions.sh @@ -32,11 +32,6 @@ test_set_editor () { export EDITOR } -test_set_index_version () { - GIT_INDEX_VERSION="$1" - export GIT_INDEX_VERSION -} - test_decode_color () { awk ' function name(n) { @@ -116,13 +111,6 @@ remove_cr () { tr '\015' Q | sed -e 's/Q$//' } -# Generate an output of $1 bytes of all zeroes (NULs, not ASCII zeroes). -# If $1 is 'infinity', output forever or until the receiving pipe stops reading, -# whichever comes first. -generate_zero_bytes () { - test-tool genzeros "$@" -} - # In some bourne shell implementations, the "unset" builtin returns # nonzero status when a variable to be unset was not set in the first # place. @@ -178,34 +166,60 @@ debug () { GIT_DEBUGGER="${GIT_DEBUGGER}" "$@" <&6 >&5 2>&7 } -# Call test_commit with the arguments -# [-C <directory>] <message> [<file> [<contents> [<tag>]]]" +# Usage: test_commit [options] <message> [<file> [<contents> [<tag>]]] +# -C <dir>: +# Run all git commands in directory <dir> +# --notick +# Do not call test_tick before making a commit +# --append +# Use "echo >>" instead of "echo >" when writing "<contents>" to +# "<file>" +# --signoff +# Invoke "git commit" with --signoff +# --author <author> +# Invoke "git commit" with --author <author> # # This will commit a file with the given contents and the given commit # message, and tag the resulting commit with the given tag name. # # <file>, <contents>, and <tag> all default to <message>. -# -# If the first argument is "-C", the second argument is used as a path for -# the git invocations. test_commit () { notick= && + append= && + author= && signoff= && indir= && + no_tag= && while test $# != 0 do case "$1" in --notick) notick=yes ;; + --append) + append=yes + ;; + --author) + author="$2" + shift + ;; --signoff) signoff="$1" ;; + --date) + notick=yes + GIT_COMMITTER_DATE="$2" + GIT_AUTHOR_DATE="$2" + shift + ;; -C) indir="$2" shift ;; + --no-tag) + no_tag=yes + ;; *) break ;; @@ -214,14 +228,24 @@ test_commit () { done && indir=${indir:+"$indir"/} && file=${2:-"$1.t"} && - echo "${3-$1}" > "$indir$file" && + if test -n "$append" + then + echo "${3-$1}" >>"$indir$file" + else + echo "${3-$1}" >"$indir$file" + fi && git ${indir:+ -C "$indir"} add "$file" && if test -z "$notick" then test_tick fi && - git ${indir:+ -C "$indir"} commit $signoff -m "$1" && - git ${indir:+ -C "$indir"} tag "${4:-$1}" + git ${indir:+ -C "$indir"} commit \ + ${author:+ --author "$author"} \ + $signoff -m "$1" && + if test -z "$no_tag" + then + git ${indir:+ -C "$indir"} tag "${4:-$1}" + fi } # Call test_merge with the arguments "<message> <commit>", where <commit> @@ -706,34 +730,37 @@ test_external_without_stderr () { } # debugging-friendly alternatives to "test [-f|-d|-e]" -# The commands test the existence or non-existence of $1. $2 can be -# given to provide a more precise diagnosis. +# The commands test the existence or non-existence of $1 test_path_is_file () { + test "$#" -ne 1 && BUG "1 param" if ! test -f "$1" then - echo "File $1 doesn't exist. $2" + echo "File $1 doesn't exist" false fi } test_path_is_dir () { + test "$#" -ne 1 && BUG "1 param" if ! test -d "$1" then - echo "Directory $1 doesn't exist. $2" + echo "Directory $1 doesn't exist" false fi } test_path_exists () { + test "$#" -ne 1 && BUG "1 param" if ! test -e "$1" then - echo "Path $1 doesn't exist. $2" + echo "Path $1 doesn't exist" false fi } # Check if the directory exists and is empty as expected, barf otherwise. test_dir_is_empty () { + test "$#" -ne 1 && BUG "1 param" test_path_is_dir "$1" && if test -n "$(ls -a1 "$1" | egrep -v '^\.\.?$')" then @@ -745,6 +772,7 @@ test_dir_is_empty () { # Check if the file exists and has a size greater than zero test_file_not_empty () { + test "$#" = 2 && BUG "2 param" if ! test -s "$1" then echo "'$1' is not a non-empty file." @@ -753,6 +781,7 @@ test_file_not_empty () { } test_path_is_missing () { + test "$#" -ne 1 && BUG "1 param" if test -e "$1" then echo "Path exists:" @@ -789,6 +818,7 @@ test_line_count () { } test_file_size () { + test "$#" -ne 1 && BUG "1 param" test-tool path-utils file-size "$1" } @@ -961,6 +991,7 @@ test_expect_code () { # - not all diff versions understand "-u" test_cmp () { + test "$#" -ne 2 && BUG "2 param" eval "$GIT_TEST_CMP" '"$@"' } @@ -990,22 +1021,20 @@ test_cmp_config () { # test_cmp_bin - helper to compare binary files test_cmp_bin () { + test "$#" -ne 2 && BUG "2 param" cmp "$@" } -# Use this instead of test_cmp to compare files that contain expected and -# actual output from git commands that can be translated. When running -# under GIT_TEST_GETTEXT_POISON this pretends that the command produced expected -# results. +# Wrapper for test_cmp which used to be used for +# GIT_TEST_GETTEXT_POISON=false. Only here as a shim for other +# in-flight changes. Should not be used and will be removed soon. test_i18ncmp () { - ! test_have_prereq C_LOCALE_OUTPUT || test_cmp "$@" + test_cmp "$@" } -# Use this instead of "grep expected-string actual" to see if the -# output from a git command that can be translated either contains an -# expected string, or does not contain an unwanted one. When running -# under GIT_TEST_GETTEXT_POISON this pretends that the command produced expected -# results. +# Wrapper for grep which used to be used for +# GIT_TEST_GETTEXT_POISON=false. Only here as a shim for other +# in-flight changes. Should not be used and will be removed soon. test_i18ngrep () { eval "last_arg=\${$#}" @@ -1018,12 +1047,6 @@ test_i18ngrep () { BUG "too few parameters to test_i18ngrep" fi - if test_have_prereq !C_LOCALE_OUTPUT - then - # pretend success - return 0 - fi - if test "x!" = "x$1" then shift @@ -1059,6 +1082,7 @@ verbose () { # otherwise. test_must_be_empty () { + test "$#" -ne 1 && BUG "1 param" test_path_is_file "$1" && if test -s "$1" then @@ -1082,7 +1106,7 @@ test_cmp_rev () { fi if test $# != 2 then - error "bug in the test script: test_cmp_rev requires two revisions, but got $#" + BUG "test_cmp_rev requires two revisions, but got $#" else local r1 r2 r1=$(git rev-parse --verify "$1") && @@ -1193,7 +1217,7 @@ test_atexit () { # doing so on Bash is better than nothing (the test will # silently pass on other shells). test "${BASH_SUBSHELL-0}" = 0 || - error "bug in test script: test_atexit does nothing in a subshell" + BUG "test_atexit does nothing in a subshell" test_atexit_cleanup="{ $* } && (exit \"\$eval_ret\"); eval_ret=\$?; $test_atexit_cleanup" } @@ -1591,33 +1615,6 @@ test_set_port () { eval $var=$port } -# Compare a file containing rev-list bitmap traversal output to its non-bitmap -# counterpart. You can't just use test_cmp for this, because the two produce -# subtly different output: -# -# - regular output is in traversal order, whereas bitmap is split by type, -# with non-packed objects at the end -# -# - regular output has a space and the pathname appended to non-commit -# objects; bitmap output omits this -# -# This function normalizes and compares the two. The second file should -# always be the bitmap output. -test_bitmap_traversal () { - if test "$1" = "--no-confirm-bitmaps" - then - shift - elif cmp "$1" "$2" - then - echo >&2 "identical raw outputs; are you sure bitmaps were used?" - return 1 - fi && - cut -d' ' -f1 "$1" | sort >"$1.normalized" && - sort "$2" >"$2.normalized" && - test_cmp "$1.normalized" "$2.normalized" && - rm -f "$1.normalized" "$2.normalized" -} - # Tests for the hidden file attribute on Windows test_path_is_hidden () { test_have_prereq MINGW || @@ -1660,3 +1657,45 @@ test_subcommand () { grep "\[$expr\]" fi } + +# Check that the given command was invoked as part of the +# trace2-format trace on stdin. +# +# test_region [!] <category> <label> git <command> <args>... +# +# For example, to look for trace2_region_enter("index", "do_read_index", repo) +# in an invocation of "git checkout HEAD~1", run +# +# GIT_TRACE2_EVENT="$(pwd)/trace.txt" GIT_TRACE2_EVENT_NESTING=10 \ +# git checkout HEAD~1 && +# test_region index do_read_index <trace.txt +# +# If the first parameter passed is !, this instead checks that +# the given region was not entered. +# +test_region () { + local expect_exit=0 + if test "$1" = "!" + then + expect_exit=1 + shift + fi + + grep -e '"region_enter".*"category":"'"$1"'","label":"'"$2"\" "$3" + exitcode=$? + + if test $exitcode != $expect_exit + then + return 1 + fi + + grep -e '"region_leave".*"category":"'"$1"'","label":"'"$2"\" "$3" + exitcode=$? + + if test $exitcode != $expect_exit + then + return 1 + fi + + return 0 +} |