]> git.ipfire.org Git - thirdparty/git.git/blobdiff - t/test-lib-functions.sh
tests: fix description of 'test_set_prereq'
[thirdparty/git.git] / t / test-lib-functions.sh
index f9904066feed6d609d8d568dbd16080957ed7aa3..21b2ea55b7b5a358bf1075a9095526dcf5cce4ee 100644 (file)
@@ -423,7 +423,7 @@ write_script () {
 # - Explicitly using test_have_prereq.
 #
 # - Implicitly by specifying the prerequisite tag in the calls to
-#   test_expect_{success,failure,code}.
+#   test_expect_{success,failure} and test_external{,_without_stderr}.
 #
 # The single parameter is the prerequisite tag (a simple word, in all
 # capital letters by convention).
@@ -474,15 +474,15 @@ test_lazy_prereq () {
 
 test_run_lazy_prereq_ () {
        script='
-mkdir -p "$TRASH_DIRECTORY/prereq-test-dir" &&
+mkdir -p "$TRASH_DIRECTORY/prereq-test-dir-'"$1"'" &&
 (
-       cd "$TRASH_DIRECTORY/prereq-test-dir" &&'"$2"'
+       cd "$TRASH_DIRECTORY/prereq-test-dir-'"$1"'" &&'"$2"'
 )'
        say >&3 "checking prerequisite: $1"
        say >&3 "$script"
        test_eval_ "$script"
        eval_ret=$?
-       rm -rf "$TRASH_DIRECTORY/prereq-test-dir"
+       rm -rf "$TRASH_DIRECTORY/prereq-test-dir-$1"
        if test "$eval_ret" = 0; then
                say >&3 "prerequisite $1 ok"
        else
@@ -1628,3 +1628,36 @@ test_path_is_hidden () {
        case "$("$SYSTEMROOT"/system32/attrib "$1")" in *H*?:*) return 0;; esac
        return 1
 }
+
+# Check that the given command was invoked as part of the
+# trace2-format trace on stdin.
+#
+#      test_subcommand [!] <command> <args>... < <trace>
+#
+# For example, to look for an invocation of "git upload-pack
+# /path/to/repo"
+#
+#      GIT_TRACE2_EVENT=event.log git fetch ... &&
+#      test_subcommand git upload-pack "$PATH" <event.log
+#
+# If the first parameter passed is !, this instead checks that
+# the given command was not called.
+#
+test_subcommand () {
+       local negate=
+       if test "$1" = "!"
+       then
+               negate=t
+               shift
+       fi
+
+       local expr=$(printf '"%s",' "$@")
+       expr="${expr%,}"
+
+       if test -n "$negate"
+       then
+               ! grep "\[$expr\]"
+       else
+               grep "\[$expr\]"
+       fi
+}