summaryrefslogtreecommitdiff
path: root/t/test-lib-functions.sh
diff options
context:
space:
mode:
authorLibravatar Junio C Hamano <gitster@pobox.com>2021-02-10 14:48:32 -0800
committerLibravatar Junio C Hamano <gitster@pobox.com>2021-02-10 14:48:33 -0800
commit2f794620f5dda37405e4ba9b606061468eceed98 (patch)
tree5536aa9904d3db0128ef6a50a0500a2d258c0d5f /t/test-lib-functions.sh
parentMerge branch 'rs/worktree-list-verbose' (diff)
parentt1092: test interesting sparse-checkout scenarios (diff)
downloadtgif-2f794620f5dda37405e4ba9b606061468eceed98.tar.xz
Merge branch 'ds/more-index-cleanups'
Cleaning various codepaths up. * ds/more-index-cleanups: t1092: test interesting sparse-checkout scenarios test-lib: test_region looks for trace2 regions sparse-checkout: load sparse-checkout patterns name-hash: use trace2 regions for init repository: add repo reference to index_state fsmonitor: de-duplicate BUG()s around dirty bits cache-tree: extract subtree_pos() cache-tree: simplify verify_cache() prototype cache-tree: clean up cache_tree_update()
Diffstat (limited to 't/test-lib-functions.sh')
-rw-r--r--t/test-lib-functions.sh42
1 files changed, 42 insertions, 0 deletions
diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh
index 6bca002316..aca17f8945 100644
--- a/t/test-lib-functions.sh
+++ b/t/test-lib-functions.sh
@@ -1683,3 +1683,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
+}