aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorĐoàn Trần Công Danh <congdanhqx@gmail.com>2021-07-04 12:46:10 +0700
committerJunio C Hamano <gitster@pobox.com>2021-07-06 12:22:27 -0700
commitcdff1bb5a3d6f0e6bf26d8ff088a0e10b40bc4f3 (patch)
tree18ca6fab2e667f160d245f776e0bc108287672c2
parent670b81a890388c60b7032a4f5b879f2ece8c4558 (diff)
downloadgit-cdff1bb5a3d6f0e6bf26d8ff088a0e10b40bc4f3.tar.gz
test-lib-functions: introduce test_stdout_line_count
In some tests, we're checking the number of lines in output of some commands, including but not limited to Git's command. We're doing the check by running those commands in the left side of a pipe, thus losing the exit status code of those commands. Meanwhile, we really want to check the exit status code of Git's command. Let's write the output of those commands to a temporary file, and use test_line_count separately in order to check exit status code of those commands properly. Signed-off-by: Đoàn Trần Công Danh <congdanhqx@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
-rw-r--r--t/test-lib-functions.sh26
1 files changed, 26 insertions, 0 deletions
diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh
index f0448daa74..4345027c76 100644
--- a/t/test-lib-functions.sh
+++ b/t/test-lib-functions.sh
@@ -845,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"