diff options
Diffstat (limited to 't/test-lib-functions.sh')
-rw-r--r-- | t/test-lib-functions.sh | 94 |
1 files changed, 71 insertions, 23 deletions
diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh index b823c14027..ce41596514 100644 --- a/t/test-lib-functions.sh +++ b/t/test-lib-functions.sh @@ -172,12 +172,23 @@ debug () { # --notick # Do not call test_tick before making a commit # --append -# Use "echo >>" instead of "echo >" when writing "<contents>" to -# "<file>" +# Use ">>" instead of ">" when writing "<contents>" to "<file>" +# --printf +# Use "printf" instead of "echo" when writing "<contents>" to +# "<file>", use this to write escape sequences such as "\0", a +# trailing "\n" won't be added automatically. This option +# supports nothing but the FORMAT of printf(1), i.e. no custom +# ARGUMENT(s). # --signoff # Invoke "git commit" with --signoff # --author <author> # Invoke "git commit" with --author <author> +# --no-tag +# Do not tag the resulting commit +# --annotate +# Create an annotated tag with "--annotate -m <message>". Calls +# test_tick between making the commit and tag, unless --notick +# is given. # # This will commit a file with the given contents and the given commit # message, and tag the resulting commit with the given tag name. @@ -186,17 +197,21 @@ debug () { test_commit () { notick= && + echo=echo && append= && author= && signoff= && indir= && - no_tag= && + tag=light && while test $# != 0 do case "$1" in --notick) notick=yes ;; + --printf) + echo=printf + ;; --append) append=yes ;; @@ -218,7 +233,10 @@ test_commit () { shift ;; --no-tag) - no_tag=yes + tag=none + ;; + --annotate) + tag=annotate ;; *) break @@ -230,9 +248,9 @@ test_commit () { file=${2:-"$1.t"} && if test -n "$append" then - echo "${3-$1}" >>"$indir$file" + $echo "${3-$1}" >>"$indir$file" else - echo "${3-$1}" >"$indir$file" + $echo "${3-$1}" >"$indir$file" fi && git ${indir:+ -C "$indir"} add "$file" && if test -z "$notick" @@ -242,10 +260,20 @@ test_commit () { git ${indir:+ -C "$indir"} commit \ ${author:+ --author "$author"} \ $signoff -m "$1" && - if test -z "$no_tag" - then + case "$tag" in + none) + ;; + light) git ${indir:+ -C "$indir"} tag "${4:-$1}" - fi + ;; + annotate) + if test -z "$notick" + then + test_tick + fi && + git ${indir:+ -C "$indir"} tag -a -m "$1" "${4:-$1}" + ;; + esac } # Call test_merge with the arguments "<message> <commit>", where <commit> @@ -817,6 +845,32 @@ test_line_count () { fi } +# SYNOPSIS: +# test_stdout_line_count <bin-ops> <value> <cmd> [<args>...] +# +# test_stdout_line_count checks that the output of a command has the number +# of lines it ought to. For example: +# +# test_stdout_line_count = 3 git ls-files -u +# test_stdout_line_count -gt 10 ls +test_stdout_line_count () { + local ops val trashdir && + if test "$#" -le 3 + then + BUG "expect 3 or more arguments" + fi && + ops="$1" && + val="$2" && + shift 2 && + if ! trashdir="$(git rev-parse --git-dir)/trash"; then + BUG "expect to be run inside a worktree" + fi && + mkdir -p "$trashdir" && + "$@" >"$trashdir/output" && + test_line_count "$ops" "$val" "$trashdir/output" +} + + test_file_size () { test "$#" -ne 1 && BUG "1 param" test-tool path-utils file-size "$1" @@ -1215,22 +1269,10 @@ test_atexit () { } && (exit \"\$eval_ret\"); eval_ret=\$?; $test_atexit_cleanup" } -# Most tests can use the created repository, but some may need to create more. +# Deprecated wrapper for "git init", use "git init" directly instead # Usage: test_create_repo <directory> test_create_repo () { - test "$#" = 1 || - BUG "not 1 parameter to test-create-repo" - repo="$1" - mkdir -p "$repo" - ( - cd "$repo" || error "Cannot setup test environment" - "${GIT_TEST_INSTALLED:-$GIT_EXEC_PATH}/git$X" -c \ - init.defaultBranch="${GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME-master}" \ - init \ - "--template=$GIT_BUILD_DIR/templates/blt/" >&3 2>&4 || - error "cannot run git init -- have you built things yet?" - mv .git/hooks .git/hooks-disabled - ) || exit + git init "$@" } # This function helps on symlink challenged file systems when it is not @@ -1692,3 +1734,9 @@ test_region () { return 0 } + +# Print the destination of symlink(s) provided as arguments. Basically +# the same as the readlink command, but it's not available everywhere. +test_readlink () { + perl -le 'print readlink($_) for @ARGV' "$@" +} |