From: Đoàn Trần Công Danh <hidden> Date: 2021-06-15 17:20:58
In Git project, we have multiple occasions that requires checking number
of lines of text in stdout and/or stderr of a command. One of such
example is t6400, which checks number of files in various states.
Some of those commands are Git command, and we would like to check their
exit status. In some of those checks, we pipe the stdout of those
commands to "wc -l" to check for line count, thus loosing the exit status.
Introduce a helper function to check for number of lines in stdout and
stderr from those commands.
This helper will create 2 temporary files in process, thus it may affect
output of some checks.
Signed-off-by: Đoàn Trần Công Danh <redacted>
---
t/test-lib-functions.sh | 117 ++++++++++++++++++++++++++++++++++++++++
1 file changed, 117 insertions(+)
@@ -845,6 +845,123 @@ test_line_count () {fi}+# test_line_count_cmd checks exit status, and the number of lines in+# captured stdout and/or stderr of a command.+#+# Usage:+#+# test_line_count_cmd [--[out|err] <binop> <value>]... [--] [!] cmd [args...]+#+# Options:+# --out <binop> <value>:+# --err <binop> <value>:+# Run sh's "test <# of lines> <binop> <value>" on # of lines in stdout+# (for --out) or stderr (for --err)+# !:+# Instead of expecting "cmd [args...]" succeed, expect its failure.+# Note, if command under testing is "git", test_must_fail should be used+# instead of "!".+#+# Example:+# test_line_count_cmd --out -ge 10 --err = 0 git tag --no-contains v1.0.0+# test_line_count_cmd --out -le 10 ! grep some-text a-file+# test_line_count_cmd --out = 0 test_must_fail git rev-parse --verify abcd1234+#+# NOTE:+# * if "--out" is specified, a temporary file named test_line_count_cmd_.out+# will be created.+# * if "--err" is specified, a temporary file named test_line_count_cmd_.err+# will be created.+# Those temporary files will be created under $TRASH_DIRECTORY/.git/trash+# if $TRASH_DIRECTORY/.git directory existed.+# Otherwise, they will be created in $TRASH_DIRECTORY.+# Those temporary files will be cleant by test_when_finished+test_line_count_cmd(){+{+localoutopoutvaloutfile+localerroperrvalerrfile+localexpect_failureactual_failure+localtrashdir="$TRASH_DIRECTORY"++iftest-d"$TRASH_DIRECTORY/.git"+then+trashdir="$TRASH_DIRECTORY/.git/trash"&&+mkdir-p"$trashdir"+fi&&+whiletest$#!=0+do+case"$1"in+--out)+outop="$2"&&+outval="$3"&&+outfile="$trashdir/test_line_count_cmd_.out"&&+shift3+;;+--err)+errop="$2"&&+errval="$3"&&+errfile="$trashdir/test_line_count_cmd_.err"&&+shift3+;;+--)+shift&&+break+;;+-*)+BUG"test_line_count_cmd: unknown options: '$1'"+;;+*)+break+;;+esac+done&&+iftest"x$1"="x!"+then+shift&&+expect_failure=yes+fi&&+iftest$#=0+then+BUG"test_line_count_cmd: no command to be run"+eliftest-z"$outop$errop"+then+BUG"test_line_count_cmd: check which stream?"+else+iftest-n"$outfile"+then+test_when_finished"rm -f '$outfile'"&&+exec8>"$outfile"+fi&&+iftest-n"$errfile"+then+test_when_finished"rm -f '$errfile'"&&+exec9>"$errfile"+fi&&+if!"$@">&82>&9+then+actual_failure=yes+fi+fi8>&1&&+case"$expect_failure,$actual_failure"in+yes,)+echo>&4"error: '$@' succeed!"+return1+;;+,yes)+echo>&4"error: '$@' run into failure!"+return1+esac&&+iftest-n"$outop"+then+test_line_count"$outop""$outval""$outfile">&4+fi&&+iftest-n"$errop"+then+test_line_count"$errop""$errval""$errfile">&4+fi+}9>&22>&4+}+ test_file_size(){test"$#"-ne1&&BUG"1 param"test-toolpath-utilsfile-size"$1"
From: Đoàn Trần Công Danh <hidden> Date: 2021-06-15 17:21:04
find(1) has a builtin (-prune) to filter its output, save a bit of time
for invoking grep(1).
In addition, in a later change, we will try to use test_line_count_cmd
to count number of lines in stdout and/or stderr of a command, due to
limitation of current implementation, it can handle pipe.
Let's replace grep(1)'s usage with find(1) builtin filter.
Signed-off-by: Đoàn Trần Công Danh <redacted>
---
t/t6402-merge-rename.sh | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
@@ -330,8 +320,8 @@ test_expect_success 'Rename+D/F conflict; renamed file merges but dir in way' 'test_i18ngrep"Adding as dir~HEAD instead"outputfi&&-test3-eq"$(gitls-files-u|wc-l)"&&-test2-eq"$(gitls-files-udir/file-in-the-way|wc-l)"&&+test_line_count_cmd--out=3gitls-files-u&&+test_line_count_cmd--out=2gitls-files-udir/file-in-the-way&&test_must_failgitdiff--quiet&&test_must_failgitdiff--cached--quiet&&
@@ -357,8 +347,8 @@ test_expect_success 'Same as previous, but merged other way' 'test_i18ngrep"Adding as dir~renamed-file-has-no-conflicts instead"outputfi&&-test3-eq"$(gitls-files-u|wc-l)"&&-test2-eq"$(gitls-files-udir/file-in-the-way|wc-l)"&&+test_line_count_cmd--out=3gitls-files-u&&+test_line_count_cmd--out=2gitls-files-udir/file-in-the-way&&test_must_failgitdiff--quiet&&test_must_failgitdiff--cached--quiet&&
@@ -374,8 +364,8 @@ test_expect_success 'Rename+D/F conflict; renamed file cannot merge, dir not ingitcheckout-qrenamed-file-has-conflicts^0&&test_must_failgitmerge--strategy=recursivedir-not-in-way&&-test3-eq"$(gitls-files-u|wc-l)"&&-test3-eq"$(gitls-files-udir|wc-l)"&&+test_line_count_cmd--out=3gitls-files-u&&+test_line_count_cmd--out=3gitls-files-udir&&test_must_failgitdiff--quiet&&test_must_failgitdiff--cached--quiet&&
@@ -409,14 +399,15 @@ test_expect_success 'Rename+D/F conflict; renamed file cannot merge and dir in tgitcheckout-qrenamed-file-has-conflicts^0&&test_must_failgitmerge--strategy=recursivedir-in-way&&-test5-eq"$(gitls-files-u|wc-l)"&&+test_line_count_cmd--out=5gitls-files-u&&iftest"$GIT_TEST_MERGE_ALGORITHM"=ortthen-test3-eq"$(gitls-files-udir~HEAD|wc-l)"+test_line_count_cmd--out=3gitls-files-udir~HEADelse-test3-eq"$(gitls-files-udir|grep-vfile-in-the-way|wc-l)"+gitls-files-udir>out&&+test_line_count_cmd--out=3grep-vfile-in-the-wayoutfi&&-test2-eq"$(gitls-files-udir/file-in-the-way|wc-l)"&&+test_line_count_cmd--out=2gitls-files-udir/file-in-the-way&&test_must_failgitdiff--quiet&&test_must_failgitdiff--cached--quiet&&
@@ -432,14 +423,15 @@ test_expect_success 'Same as previous, but merged other way' 'gitcheckout-qdir-in-way^0&&test_must_failgitmerge--strategy=recursiverenamed-file-has-conflicts&&-test5-eq"$(gitls-files-u|wc-l)"&&+test_line_count_cmd--out=5gitls-files-u&&iftest"$GIT_TEST_MERGE_ALGORITHM"=ortthen-test3-eq"$(gitls-files-udir~renamed-file-has-conflicts|wc-l)"+test_line_count_cmd--out=3gitls-files-udir~renamed-file-has-conflictselse-test3-eq"$(gitls-files-udir|grep-vfile-in-the-way|wc-l)"+gitls-files-udir>out&&+test_line_count_cmd--out=3grep-vfile-in-the-wayoutfi&&-test2-eq"$(gitls-files-udir/file-in-the-way|wc-l)"&&+test_line_count_cmd--out=2gitls-files-udir/file-in-the-way&&test_must_failgitdiff--quiet&&test_must_failgitdiff--cached--quiet&&
@@ -496,9 +488,9 @@ test_expect_success 'both rename source and destination involved in D/F conflictiftest"$GIT_TEST_MERGE_ALGORITHM"=ortthen-test2-eq"$(gitls-files-u|wc-l)"+test_line_count_cmd--out=2gitls-files-uelse-test1-eq"$(gitls-files-u|wc-l)"+test_line_count_cmd--out=1gitls-files-ufi&&test_must_failgitdiff--quiet&&
+#
+# Usage:
+#
+# test_line_count_cmd [--[out|err] <binop> <value>]... [--] [!] cmd [args...]
+#
+# Options:
+# --out <binop> <value>:
+# --err <binop> <value>:
+# Run sh's "test <# of lines> <binop> <value>" on # of lines in stdout
+# (for --out) or stderr (for --err)
+# !:
+# Instead of expecting "cmd [args...]" succeed, expect its failure.
+# Note, if command under testing is "git",
the command under...
test_must_fail should be used
+# instead of "!".
+#
+# Example:
+# test_line_count_cmd --out -ge 10 --err = 0 git tag --no-contains v1.0.0
+# test_line_count_cmd --out -le 10 ! grep some-text a-file
+# test_line_count_cmd --out = 0 test_must_fail git rev-parse --verify abcd1234
+#
+# NOTE:
+# * if "--out" is specified, a temporary file named test_line_count_cmd_.out
+# will be created.
+# * if "--err" is specified, a temporary file named test_line_count_cmd_.err
+# will be created.
+# Those temporary files will be created under $TRASH_DIRECTORY/.git/trash
+# if $TRASH_DIRECTORY/.git directory existed.
if $TRASH_DIRECTORY/.git/ exists
+# Otherwise, they will be created in $TRASH_DIRECTORY.
+# Those temporary files will be cleant by test_when_finished
From: Đoàn Trần Công Danh <hidden> Date: 2021-06-19 01:31:14
In the Git project, we have multiple instances that requires
checking number of lines of text in the stdout of a command.
One of such examples is t6400, that checks number of files
in various states.
Some of those commands are Git command, and we would like to check
their exit status. In some of those checks, we pipe the stdout of
those commands to "wc -l" to count the number lines, thus losing
the exit status.
Introduce a helper function to check for the number of lines in stdout
from those commands.
This helper will create a temporary file in the process, thus it may
affect the output of some checks.
Signed-off-by: Đoàn Trần Công Danh <redacted>
---
t/test-lib-functions.sh | 80 +++++++++++++++++++++++++++++++++++++++++
1 file changed, 80 insertions(+)
@@ -845,6 +845,86 @@ test_line_count () {fi}+# test_line_count_cmd checks the exit status, and the number of lines in+# the captured stdout of a command.+#+# SYNOPSIS:+#+# test_line_count_cmd <binop> <value> [!] cmd [args...]+#+# Expect succeed exit status when running+#+# cmd [args...]+#+# then, run sh's "test <# of lines in stdout> <binop> <value>"+#+# OPTIONS:+# !:+# Instead of expecting "cmd [args...]" succeed, expect its failure.+# Note, if the command under testing is "git",+# test_must_fail should be used instead of "!".+#+# EXAMPLE:+# test_line_count_cmd -ge 10 git tag --no-contains v1.0.0+# test_line_count_cmd -le 10 ! grep some-text a-file+# test_line_count_cmd = 0 test_must_fail git rev-parse --verify abcd1234+#+# NOTE:+# * a temporary file named test_line_count_cmd_.out will be created under+# $TRASH_DIRECTORY/.git/trash iff $TRASH_DIRECTORY/.git/ exists.+# Otherwise, created in $TRASH_DIRECTORY. This temporary file will be+# cleaned by test_when_finished+test_line_count_cmd(){+{+localoutopoutvaloutfile+localexpect_failureactual_failure+localtrashdir="$TRASH_DIRECTORY"++iftest-d"$TRASH_DIRECTORY/.git"+then+trashdir="$TRASH_DIRECTORY/.git/trash"&&+mkdir-p"$trashdir"+fi&&+iftest$#-lt3+then+BUG"missing <binary-ops> and <value>"+fi&&+outop="$1"&&+outval="$2"&&+shift2&&+outfile="$trashdir/test_line_count_cmd_.out"&&+iftest"x$1"="x!"+then+shift&&+expect_failure=yes+fi&&+iftest$#=0+then+BUG"test_line_count_cmd: no command to be run"+else+test_when_finished"rm -f '$outfile'"&&+exec8>"$outfile"+# We need to redirect stderr to &9,+# and redirect this function's 9>&2+# in order to not messed with -x+if!"$@">&82>&9+then+actual_failure=yes+fi+fi8>&1&&+case"$expect_failure,$actual_failure"in+yes,)+echo>&4"error: '$@' succeed!"&&+return1+;;+,yes)+echo>&4"error: '$@' run into failure!"&&+return1+esac&&+test_line_count"$outop""$outval""$outfile">&4+}9>&22>&4+}+ test_file_size(){test"$#"-ne1&&BUG"1 param"test-toolpath-utilsfile-size"$1"
From: Đoàn Trần Công Danh <hidden> Date: 2021-06-19 01:31:14
find(1) has a builtin (-prune) to filter its output, save a bit of time
for invoking grep(1).
In addition, in a later change, we will try to use test_line_count_cmd
to count number of lines in stdout and/or stderr of a command, due to
limitation of current implementation, it can handle pipe.
Let's replace grep(1)'s usage with find(1) builtin filter.
Signed-off-by: Đoàn Trần Công Danh <redacted>
---
t/t6402-merge-rename.sh | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
@@ -330,8 +320,8 @@ test_expect_success 'Rename+D/F conflict; renamed file merges but dir in way' 'test_i18ngrep"Adding as dir~HEAD instead"outputfi&&-test3-eq"$(gitls-files-u|wc-l)"&&-test2-eq"$(gitls-files-udir/file-in-the-way|wc-l)"&&+test_line_count_cmd=3gitls-files-u&&+test_line_count_cmd=2gitls-files-udir/file-in-the-way&&test_must_failgitdiff--quiet&&test_must_failgitdiff--cached--quiet&&
@@ -357,8 +347,8 @@ test_expect_success 'Same as previous, but merged other way' 'test_i18ngrep"Adding as dir~renamed-file-has-no-conflicts instead"outputfi&&-test3-eq"$(gitls-files-u|wc-l)"&&-test2-eq"$(gitls-files-udir/file-in-the-way|wc-l)"&&+test_line_count_cmd=3gitls-files-u&&+test_line_count_cmd=2gitls-files-udir/file-in-the-way&&test_must_failgitdiff--quiet&&test_must_failgitdiff--cached--quiet&&
@@ -374,8 +364,8 @@ test_expect_success 'Rename+D/F conflict; renamed file cannot merge, dir not ingitcheckout-qrenamed-file-has-conflicts^0&&test_must_failgitmerge--strategy=recursivedir-not-in-way&&-test3-eq"$(gitls-files-u|wc-l)"&&-test3-eq"$(gitls-files-udir|wc-l)"&&+test_line_count_cmd=3gitls-files-u&&+test_line_count_cmd=3gitls-files-udir&&test_must_failgitdiff--quiet&&test_must_failgitdiff--cached--quiet&&
@@ -409,14 +399,15 @@ test_expect_success 'Rename+D/F conflict; renamed file cannot merge and dir in tgitcheckout-qrenamed-file-has-conflicts^0&&test_must_failgitmerge--strategy=recursivedir-in-way&&-test5-eq"$(gitls-files-u|wc-l)"&&+test_line_count_cmd=5gitls-files-u&&iftest"$GIT_TEST_MERGE_ALGORITHM"=ortthen-test3-eq"$(gitls-files-udir~HEAD|wc-l)"+test_line_count_cmd=3gitls-files-udir~HEADelse-test3-eq"$(gitls-files-udir|grep-vfile-in-the-way|wc-l)"+gitls-files-udir>out&&+test_line_count_cmd=3grep-vfile-in-the-wayoutfi&&-test2-eq"$(gitls-files-udir/file-in-the-way|wc-l)"&&+test_line_count_cmd=2gitls-files-udir/file-in-the-way&&test_must_failgitdiff--quiet&&test_must_failgitdiff--cached--quiet&&
@@ -432,14 +423,15 @@ test_expect_success 'Same as previous, but merged other way' 'gitcheckout-qdir-in-way^0&&test_must_failgitmerge--strategy=recursiverenamed-file-has-conflicts&&-test5-eq"$(gitls-files-u|wc-l)"&&+test_line_count_cmd=5gitls-files-u&&iftest"$GIT_TEST_MERGE_ALGORITHM"=ortthen-test3-eq"$(gitls-files-udir~renamed-file-has-conflicts|wc-l)"+test_line_count_cmd=3gitls-files-udir~renamed-file-has-conflictselse-test3-eq"$(gitls-files-udir|grep-vfile-in-the-way|wc-l)"+gitls-files-udir>out&&+test_line_count_cmd=3grep-vfile-in-the-wayoutfi&&-test2-eq"$(gitls-files-udir/file-in-the-way|wc-l)"&&+test_line_count_cmd=2gitls-files-udir/file-in-the-way&&test_must_failgitdiff--quiet&&test_must_failgitdiff--cached--quiet&&
@@ -496,9 +488,9 @@ test_expect_success 'both rename source and destination involved in D/F conflictiftest"$GIT_TEST_MERGE_ALGORITHM"=ortthen-test2-eq"$(gitls-files-u|wc-l)"+test_line_count_cmd=2gitls-files-uelse-test1-eq"$(gitls-files-u|wc-l)"+test_line_count_cmd=1gitls-files-ufi&&test_must_failgitdiff--quiet&&
From: Eric Sunshine <hidden> Date: 2021-06-19 05:50:45
On Fri, Jun 18, 2021 at 9:31 PM Đoàn Trần Công Danh
[off-list ref] wrote:
Change in v3 since v2:
* --err was dropped entirely
* --out is not an option anymore, <binops> and <value> is the first two
arguments that fed into test_line_count_cmd
When I read the previous version of this series, I found that many of
the instances where test_line_count_cmd() were used became quite
noisy, to the point that it was difficult to see at-a-glance the
command being tested. As an experiment, on top of your patch 1, I
crafted a patch which made `--out` and `--err` optional (defaulting to
`--out`). That helped reduce the noise level a good deal, however, I
still found it too noisy. Consequently, I crafted a second patch which
renamed the function to test_output_count(), and only then did the
noise level drop sufficiently that the command being tested didn't
entirely disappear into the background.
Since you've dropped the `--out` and `--err` options entirely, I
wonder if now would be a good time to shorten the function name, as
well, in order to further reduce the noise level. Since it now only
tests stdout (and doesn't deal with stderr), a name even shorter than
what I tried for the last version might be even better. So, for
instance, the name test_out_count() might not be too bad:
test_out_count = 0 git ls-files -o &&
From: Andrei Rybak <hidden> Date: 2021-06-21 08:18:02
On 19/06/2021 03:30, Đoàn Trần Công Danh wrote:
find(1) has a builtin (-prune) to filter its output, save a bit of time
for invoking grep(1).
In addition, in a later change, we will try to use test_line_count_cmd
to count number of lines in stdout and/or stderr of a command, due to
Looking at [PATCH v3 1/4] of this series, mention of "stderr" here is no
longer relevant.
limitation of current implementation, it can handle pipe.
Seems like a typo s/can/can't/ ?
quoted hunk
Let's replace grep(1)'s usage with find(1) builtin filter.
Signed-off-by: Đoàn Trần Công Danh <redacted>
---
t/t6402-merge-rename.sh | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
@@ -593,7 +593,7 @@ test_expect_success 'pair rename to parent of other (D/F conflicts) w/ clean statest_must_failgitdiff--quiet&&-test3-eq$(find.|grep-v.git|wc-l)&&+test3-eq$(find.-name.git-prune-o-print|wc-l)&&
Because in the original `grep` wasn't invoked with `-F` it means that
".git" is a regex which would match any path which contains the word
"git" in it, because "." matches any character, including the leading
slash that `find` outputs. Such narrowing of what we intend to filter
out is a good change.
This semantic change in filtering doesn't affect tests in t6402, as the
test directory doesn't have paths with the word "git" except for the
".git" directory. It might be worth mentioning in the commit message.
From: Andrei Rybak <hidden> Date: 2021-06-21 09:08:15
On 19/06/2021 03:30, Đoàn Trần Công Danh wrote:
In the Git project, we have multiple instances that requires
s/requires/require/
quoted hunk
checking number of lines of text in the stdout of a command.
One of such examples is t6400, that checks number of files
in various states.
Some of those commands are Git command, and we would like to check
their exit status. In some of those checks, we pipe the stdout of
those commands to "wc -l" to count the number lines, thus losing
the exit status.
Introduce a helper function to check for the number of lines in stdout
from those commands.
This helper will create a temporary file in the process, thus it may
affect the output of some checks.
Signed-off-by: Đoàn Trần Công Danh <redacted>
---
t/test-lib-functions.sh | 80 +++++++++++++++++++++++++++++++++++++++++
1 file changed, 80 insertions(+)
@@ -845,6 +845,86 @@ test_line_count () {fi}+# test_line_count_cmd checks the exit status, and the number of lines in+# the captured stdout of a command.+#+# SYNOPSIS:+#+# test_line_count_cmd <binop> <value> [!] cmd [args...]+#+# Expect succeed exit status when running+#+# cmd [args...]+#+# then, run sh's "test <# of lines in stdout> <binop> <value>"+#+# OPTIONS:+# !:+# Instead of expecting "cmd [args...]" succeed, expect its failure.+# Note, if the command under testing is "git",+# test_must_fail should be used instead of "!".+#+# EXAMPLE:+# test_line_count_cmd -ge 10 git tag --no-contains v1.0.0+# test_line_count_cmd -le 10 ! grep some-text a-file+# test_line_count_cmd = 0 test_must_fail git rev-parse --verify abcd1234+#+# NOTE:+# * a temporary file named test_line_count_cmd_.out will be created under+# $TRASH_DIRECTORY/.git/trash iff $TRASH_DIRECTORY/.git/ exists.+# Otherwise, created in $TRASH_DIRECTORY. This temporary file will be+# cleaned by test_when_finished+test_line_count_cmd(){+{+localoutopoutvaloutfile+localexpect_failureactual_failure+localtrashdir="$TRASH_DIRECTORY"++iftest-d"$TRASH_DIRECTORY/.git"+then+trashdir="$TRASH_DIRECTORY/.git/trash"&&+mkdir-p"$trashdir"+fi&&+iftest$#-lt3+then+BUG"missing <binary-ops> and <value>"
Nit: s/binary-ops/binop/ for consistency with documentation comment
above. Also, technically the invocation of test_line_count_cmd could be
missing any of its required three parameters, including "cmd". How
about something similar to the call to BUG in test_i18ngrep:
BUG "too few parameters to test_line_count_cmd"
?
+ fi &&
+ outop="$1" &&
+ outval="$2" &&
+ shift 2 &&
+ outfile="$trashdir/test_line_count_cmd_.out" &&
+ if test "x$1" = "x!"
+ then
+ shift &&
+ expect_failure=yes
+ fi &&
+ if test $# = 0
+ then
+ BUG "test_line_count_cmd: no command to be run"
+ else
+ test_when_finished "rm -f '$outfile'" &&
+ exec 8>"$outfile"
+ # We need to redirect stderr to &9,
+ # and redirect this function's 9>&2
+ # in order to not messed with -x
+ if ! "$@" >&8 2>&9
+ then
+ actual_failure=yes
+ fi
+ fi 8>&1 &&
+ case "$expect_failure,$actual_failure" in
+ yes,)
+ echo >&4 "error: '$@' succeed!" &&
It seems that function error() could be used here and below instead of
"echo >&4".
s/succeed/succeeded/ --- it might be worth borrowing wording from
test_must_fail(). Something like:
error "test_line_count_cmd: command succeeded: '$@'"
From: Đoàn Trần Công Danh <hidden> Date: 2021-06-21 23:54:32
On 2021-06-21 10:17:52+0200, Andrei Rybak [off-list ref] wrote:
On 19/06/2021 03:30, Đoàn Trần Công Danh wrote:
quoted
find(1) has a builtin (-prune) to filter its output, save a bit of time
for invoking grep(1).
In addition, in a later change, we will try to use test_line_count_cmd
to count number of lines in stdout and/or stderr of a command, due to
Looking at [PATCH v3 1/4] of this series, mention of "stderr" here is no
longer relevant.
Yes, you're correct.
quoted
limitation of current implementation, it can handle pipe.
Seems like a typo s/can/can't/ ?
This is correct, too.
quoted
Let's replace grep(1)'s usage with find(1) builtin filter.
Signed-off-by: Đoàn Trần Công Danh <redacted>
---
t/t6402-merge-rename.sh | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
@@ -593,7 +593,7 @@ test_expect_success 'pair rename to parent of other (D/F conflicts) w/ clean statest_must_failgitdiff--quiet&&-test3-eq$(find.|grep-v.git|wc-l)&&+test3-eq$(find.-name.git-prune-o-print|wc-l)&&
Because in the original `grep` wasn't invoked with `-F` it means that
".git" is a regex which would match any path which contains the word
"git" in it, because "." matches any character, including the leading
slash that `find` outputs. Such narrowing of what we intend to filter
out is a good change.
I think the original intention is using "grep -F". I'll add that
information into the commit message.
This semantic change in filtering doesn't affect tests in t6402, as the
test directory doesn't have paths with the word "git" except for the
".git" directory. It might be worth mentioning in the commit message.
fi
}
+# test_line_count_cmd checks the exit status, and the number of lines in
+# the captured stdout of a command.
+#
+# SYNOPSIS:
+#
+# test_line_count_cmd <binop> <value> [!] cmd [args...]
+#
+# Expect succeed exit status when running
+#
+# cmd [args...]
+#
+# then, run sh's "test <# of lines in stdout> <binop> <value>"
+#
+# OPTIONS:
+# !:
+# Instead of expecting "cmd [args...]" succeed, expect its failure.
+# Note, if the command under testing is "git",
+# test_must_fail should be used instead of "!".
+#
+# EXAMPLE:
+# test_line_count_cmd -ge 10 git tag --no-contains v1.0.0
+# test_line_count_cmd -le 10 ! grep some-text a-file
+# test_line_count_cmd = 0 test_must_fail git rev-parse --verify
abcd1234
+#
+# NOTE:
+# * a temporary file named test_line_count_cmd_.out will be created
under
+# $TRASH_DIRECTORY/.git/trash iff $TRASH_DIRECTORY/.git/ exists.
+# Otherwise, created in $TRASH_DIRECTORY. This temporary file will be
+# cleaned by test_when_finished
+test_line_count_cmd () {
+ {
+ local outop outval outfile
+ local expect_failure actual_failure
+ local trashdir="$TRASH_DIRECTORY"
+
+ if test -d "$TRASH_DIRECTORY/.git"
+ then
+ trashdir="$TRASH_DIRECTORY/.git/trash" &&
+ mkdir -p "$trashdir"
+ fi &&
+ if test $# -lt 3
+ then
+ BUG "missing <binary-ops> and <value>"
Nit: s/binary-ops/binop/ for consistency with documentation comment
above. Also, technically the invocation of test_line_count_cmd could be
missing any of its required three parameters, including "cmd". How
about something similar to the call to BUG in test_i18ngrep:
BUG "too few parameters to test_line_count_cmd"
?
quoted
+ fi &&
+ outop="$1" &&
+ outval="$2" &&
+ shift 2 &&
+ outfile="$trashdir/test_line_count_cmd_.out" &&
+ if test "x$1" = "x!"
+ then
+ shift &&
+ expect_failure=yes
+ fi &&
+ if test $# = 0
+ then
+ BUG "test_line_count_cmd: no command to be run"
+ else
+ test_when_finished "rm -f '$outfile'" &&
+ exec 8>"$outfile"
+ # We need to redirect stderr to &9,
+ # and redirect this function's 9>&2
+ # in order to not messed with -x
+ if ! "$@" >&8 2>&9
+ then
+ actual_failure=yes
+ fi
+ fi 8>&1 &&
+ case "$expect_failure,$actual_failure" in
+ yes,)
+ echo >&4 "error: '$@' succeed!" &&
It seems that function error() could be used here and below instead of
"echo >&4".
After spending some time reading t/test-lib-functions.sh, now I don't
think that using error() is a good suggestion. Closest relatives of
test_line_count_cmd -- test_line_count and test_must_be_empty -- both
just use "echo". Other usages of error() in t/test-lib.sh and
t/test-lib-functions.sh suggest that error() is not meant to be used
for reporting test failure messages, but internal failures. For example:
error "You haven't built things yet, have you?"
and
error "Internal error: $stderr disappeared."
s/succeed/succeeded/ --- it might be worth borrowing wording from
test_must_fail(). Something like:
error "test_line_count_cmd: command succeeded: '$@'"
From: Đoàn Trần Công Danh <hidden> Date: 2021-06-29 13:57:56
This is a series to clear false positive when applying Junio's suggestion to
to a series written by Ævar [1].
Not that we have any conclusion on that suggestion, just to clear the way out.
In v4, I dropped the test_line_count_cmd completely.
A local to t640{0,2} helper was written instead.
Hence, the changelog and range-diff for v2 and v3 is dropped.
1: https://lore.kernel.org/git/87r1j42ffz.fsf@evledraar.gmail.com/
Đoàn Trần Công Danh (2):
t6400: preserve git ls-files exit status code
t6402: preserve git exit status code
t/t6400-merge-df.sh | 30 ++++++---
t/t6402-merge-rename.sh | 146 +++++++++++++++++++++-------------------
2 files changed, 100 insertions(+), 76 deletions(-)
--
2.32.0.278.gd42b80f139
From: Đoàn Trần Công Danh <hidden> Date: 2021-06-29 13:58:00
In t6400, we're checking number of files in the index and the working
tree by piping the output of "git ls-files" to "wc -l", thus losing the
exit status code of git.
Let's write the output of "git ls-files" to a temporary file, in order
to check exit status code of "git ls-files" properly.
Signed-off-by: Đoàn Trần Công Danh <redacted>
---
t/t6400-merge-df.sh | 30 ++++++++++++++++++++++--------
1 file changed, 22 insertions(+), 8 deletions(-)
From: Đoàn Trần Công Danh <hidden> Date: 2021-06-29 13:58:06
In t6402, we're checking number of files in the index and the working
tree by piping the output of "git ls-files" to "wc -l", thus losing the
exit status code of git.
Let's write the output of "git ls-files" to a temporary file, in order
to check exit status code of "git ls-files" properly.
While we're at it, also check exit status code of an invocation of
git-rev-parse, too.
Signed-off-by: Đoàn Trần Công Danh <redacted>
---
t/t6402-merge-rename.sh | 146 +++++++++++++++++++++-------------------
1 file changed, 78 insertions(+), 68 deletions(-)
@@ -330,8 +334,8 @@ test_expect_success 'Rename+D/F conflict; renamed file merges but dir in way' 'test_i18ngrep"Adding as dir~HEAD instead"outputfi&&-test3-eq"$(gitls-files-u|wc-l)"&&-test2-eq"$(gitls-files-udir/file-in-the-way|wc-l)"&&+check_ls_files_count=3-u&&+check_ls_files_count=2-udir/file-in-the-way&&test_must_failgitdiff--quiet&&test_must_failgitdiff--cached--quiet&&
@@ -357,8 +361,8 @@ test_expect_success 'Same as previous, but merged other way' 'test_i18ngrep"Adding as dir~renamed-file-has-no-conflicts instead"outputfi&&-test3-eq"$(gitls-files-u|wc-l)"&&-test2-eq"$(gitls-files-udir/file-in-the-way|wc-l)"&&+check_ls_files_count=3-u&&+check_ls_files_count=2-udir/file-in-the-way&&test_must_failgitdiff--quiet&&test_must_failgitdiff--cached--quiet&&
@@ -374,8 +378,8 @@ test_expect_success 'Rename+D/F conflict; renamed file cannot merge, dir not ingitcheckout-qrenamed-file-has-conflicts^0&&test_must_failgitmerge--strategy=recursivedir-not-in-way&&-test3-eq"$(gitls-files-u|wc-l)"&&-test3-eq"$(gitls-files-udir|wc-l)"&&+check_ls_files_count=3-u&&+check_ls_files_count=3-udir&&test_must_failgitdiff--quiet&&test_must_failgitdiff--cached--quiet&&
@@ -409,14 +413,16 @@ test_expect_success 'Rename+D/F conflict; renamed file cannot merge and dir in tgitcheckout-qrenamed-file-has-conflicts^0&&test_must_failgitmerge--strategy=recursivedir-in-way&&-test5-eq"$(gitls-files-u|wc-l)"&&+check_ls_files_count=5-u&&iftest"$GIT_TEST_MERGE_ALGORITHM"=ortthen-test3-eq"$(gitls-files-udir~HEAD|wc-l)"+check_ls_files_count=3-udir~HEADelse-test3-eq"$(gitls-files-udir|grep-vfile-in-the-way|wc-l)"+gitls-files-udir>out&&+test3-eq$(grep-vfile-in-the-wayout|wc-l)&&+rm-foutfi&&-test2-eq"$(gitls-files-udir/file-in-the-way|wc-l)"&&+check_ls_files_count=2-udir/file-in-the-way&&test_must_failgitdiff--quiet&&test_must_failgitdiff--cached--quiet&&
@@ -432,14 +438,16 @@ test_expect_success 'Same as previous, but merged other way' 'gitcheckout-qdir-in-way^0&&test_must_failgitmerge--strategy=recursiverenamed-file-has-conflicts&&-test5-eq"$(gitls-files-u|wc-l)"&&+check_ls_files_count=5-u&&iftest"$GIT_TEST_MERGE_ALGORITHM"=ortthen-test3-eq"$(gitls-files-udir~renamed-file-has-conflicts|wc-l)"+check_ls_files_count=3-udir~renamed-file-has-conflictselse-test3-eq"$(gitls-files-udir|grep-vfile-in-the-way|wc-l)"+gitls-files-udir>out&&+test3-eq$(grep-vfile-in-the-wayout|wc-l)&&+rm-foutfi&&-test2-eq"$(gitls-files-udir/file-in-the-way|wc-l)"&&+check_ls_files_count=2-udir/file-in-the-way&&test_must_failgitdiff--quiet&&test_must_failgitdiff--cached--quiet&&
@@ -496,9 +504,9 @@ test_expect_success 'both rename source and destination involved in D/F conflictiftest"$GIT_TEST_MERGE_ALGORITHM"=ortthen-test2-eq"$(gitls-files-u|wc-l)"+check_ls_files_count=2-uelse-test1-eq"$(gitls-files-u|wc-l)"+check_ls_files_count=1-ufi&&test_must_failgitdiff--quiet&&
@@ -582,13 +590,13 @@ test_expect_success 'pair rename to parent of other (D/F conflicts) w/ clean staiftest"$GIT_TEST_MERGE_ALGORITHM"=ortthen-test4-eq"$(gitls-files-u|wc-l)"&&-test2-eq"$(gitls-files-uone|wc-l)"&&-test2-eq"$(gitls-files-utwo|wc-l)"+check_ls_files_count=4-u&&+check_ls_files_count=2-uone&&+check_ls_files_count=2-utwoelse-test2-eq"$(gitls-files-u|wc-l)"&&-test1-eq"$(gitls-files-uone|wc-l)"&&-test1-eq"$(gitls-files-utwo|wc-l)"+check_ls_files_count=2-u&&+check_ls_files_count=1-uone&&+check_ls_files_count=1-utwofi&&test_must_failgitdiff--quiet&&
@@ -631,19 +639,19 @@ test_expect_success 'check handling of differently renamed file with D/F confliciftest"$GIT_TEST_MERGE_ALGORITHM"=ortthen-test5-eq"$(gitls-files-s|wc-l)"&&-test3-eq"$(gitls-files-u|wc-l)"&&-test1-eq"$(gitls-files-uone~HEAD|wc-l)"&&-test1-eq"$(gitls-files-utwo~second-rename|wc-l)"&&-test1-eq"$(gitls-files-uoriginal|wc-l)"&&-test0-eq"$(gitls-files-o|wc-l)"+check_ls_files_count=5-s&&+check_ls_files_count=3-u&&+check_ls_files_count=1-uone~HEAD&&+check_ls_files_count=1-utwo~second-rename&&+check_ls_files_count=1-uoriginal&&+check_ls_files_count=0-oelse-test5-eq"$(gitls-files-s|wc-l)"&&-test3-eq"$(gitls-files-u|wc-l)"&&-test1-eq"$(gitls-files-uone|wc-l)"&&-test1-eq"$(gitls-files-utwo|wc-l)"&&-test1-eq"$(gitls-files-uoriginal|wc-l)"&&-test2-eq"$(gitls-files-o|wc-l)"+check_ls_files_count=5-s&&+check_ls_files_count=3-u&&+check_ls_files_count=1-uone&&+check_ls_files_count=1-utwo&&+check_ls_files_count=1-uoriginal&&+check_ls_files_count=2-ofi&&test_path_is_fileone/file&&
@@ -679,11 +687,11 @@ test_expect_success 'check handling of differently renamed file with D/F conflicgitcheckout-qfirst-rename-redo^0&&test_must_failgitmerge--strategy=recursivesecond-rename-redo&&-test3-eq"$(gitls-files-u|wc-l)"&&-test1-eq"$(gitls-files-uone|wc-l)"&&-test1-eq"$(gitls-files-utwo|wc-l)"&&-test1-eq"$(gitls-files-uoriginal|wc-l)"&&-test0-eq"$(gitls-files-o|wc-l)"&&+check_ls_files_count=3-u&&+check_ls_files_count=1-uone&&+check_ls_files_count=1-utwo&&+check_ls_files_count=1-uoriginal&&+check_ls_files_count=0-o&&test_path_is_fileone&&test_path_is_filetwo&&
@@ -861,9 +869,11 @@ test_expect_success 'setup merge of rename + small change' ' test_expect_success'merge rename + small change''gitmergerename_branch&&-test1-eq$(gitls-files-s|wc-l)&&-test0-eq$(gitls-files-o|wc-l)&&-test$(gitrev-parseHEAD:renamed_file)=$(gitrev-parseHEAD~1:file)+check_ls_files_count=1-s&&+check_ls_files_count=0-o&&+newhash=$(gitrev-parseHEAD:renamed_file)&&+oldhash=$(gitrev-parseHEAD~1:file)&&+test$newhash=$oldhash' test_expect_success'setup for use of extended merge markers''
From: Eric Sunshine <hidden> Date: 2021-06-29 14:11:37
On Tue, Jun 29, 2021 at 9:57 AM Đoàn Trần Công Danh
[off-list ref] wrote:
In t6400, we're checking number of files in the index and the working
tree by piping the output of "git ls-files" to "wc -l", thus losing the
exit status code of git.
Let's write the output of "git ls-files" to a temporary file, in order
to check exit status code of "git ls-files" properly.
Thanks, the simplicity of this version over the previous attempts is appealing.
Just a few extremely minor style nits below; don't know if any of them
are worth a re-roll.
I also &&-chain the `local` declaration:
local ops val &&
if test "$#" -le 2
By making it easy to see the `&&` upfront, when new code is inserted,
there is a better chance that the &&-chain will be kept intact:
local ops val &&
my new code &&
if test "$#" -le 2
+ then
+ BUG "Expect 2 or more arguments"
+ fi &&
A quick grep of the tests indicates that they are consistent about
using lowercase for the first word in a BUG():
BUG "expect 2 or more arguments"
From: Junio C Hamano <hidden> Date: 2021-06-29 20:49:24
Đoàn Trần Công Danh [off-list ref] writes:
This is a series to clear false positive when applying Junio's suggestion to
to a series written by Ævar [1].
Not that we have any conclusion on that suggestion, just to clear the way out.
I do not think the careless and loose pattern I suggested in the old
thread has much value, so any change whose purpose is to reduce
false positive from the pattern is not needed.
But if these two patches are genuine improvement for other reasons
(like "we avoid feeding output from 'git' into pipe"), they are very
much welcome.
Thanks.
From: Junio C Hamano <hidden> Date: 2021-06-29 22:49:30
Eric Sunshine [off-list ref] writes:
quoted
+check_ls_files_count() {
style: funcname () {
...
I also &&-chain the `local` declaration:
local ops val &&
if test "$#" -le 2
...
A quick grep of the tests indicates that they are consistent about
using lowercase for the first word in a BUG():
Thanks for a pair of sharp eyes, Eric, in your review.
I have one more comment on the main part of the patch. It is easy
to see that this conversion is correctly done in this particular
patch from the way 5/4 and -s/u are reproduced from the preimage to
the postimage, but I doubt that readers in the future, who long have
forgotten that the "-s" came from "ls-files -s", would find the new
form easy to read and understand.
Do we have the same helper duplicated across two test scripts?
I wonder if it is worth adding a single copy that forces the callers
to spell out the command name in test-lib.sh and make the above into
something like
test_output_wc_l = 5 ls-files -s
or even
test_output_wc_l = 5 git ls-files -s
That way, it is easier to see what command is being run (yes, I know
you have _ls_files_ in the middle of the name of the custom helper,
but the thing is that "-s" and "_ls_files_" in the middle of the
helper are so far apart that it is not immediately obvious what the
argument "-s" is about), and by not having two identical copies, we
have less risk of them drifting apart.
Hmm?
From: Eric Sunshine <hidden> Date: 2021-06-30 01:58:13
On Tue, Jun 29, 2021 at 6:49 PM Junio C Hamano [off-list ref] wrote:
I wonder if it is worth adding a single copy that forces the callers
to spell out the command name in test-lib.sh and make the above into
something like
test_output_wc_l = 5 ls-files -s
or even
test_output_wc_l = 5 git ls-files -s
That way, it is easier to see what command is being run (yes, I know
you have _ls_files_ in the middle of the name of the custom helper,
but the thing is that "-s" and "_ls_files_" in the middle of the
helper are so far apart that it is not immediately obvious what the
argument "-s" is about), and by not having two identical copies, we
have less risk of them drifting apart.
Hmm?
I may be misunderstanding your suggestion, but isn't the proposed
test_output_wc_l() function the same as what Danh had originally
implemented several re-rolls back (though he named it
test_line_count_cmd())?
From: Đoàn Trần Công Danh <hidden> Date: 2021-07-04 05:46:27
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 <redacted>
---
t/test-lib-functions.sh | 26 ++++++++++++++++++++++++++
1 file changed, 26 insertions(+)
@@ -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(){+localopsvaltrashdir&&+iftest"$#"-le3+then+BUG"expect 3 or more arguments"+fi&&+ops="$1"&&+val="$2"&&+shift2&&+if!trashdir="$(gitrev-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"$#"-ne1&&BUG"1 param"test-toolpath-utilsfile-size"$1"
From: Đoàn Trần Công Danh <hidden> Date: 2021-07-04 05:46:28
In t6400, we're checking number of files in the index and the working
tree by piping the output of "git ls-files" to "wc -l", thus losing the
exit status code of git.
Let's use the newly introduced test_stdout_line_count in order to check
the exit status code of Git's command.
Signed-off-by: Đoàn Trần Công Danh <redacted>
---
t/t6400-merge-df.sh | 16 ++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)
From: Đoàn Trần Công Danh <hidden> Date: 2021-07-04 05:46:30
In t6402, we're checking number of files in the index and the working
tree by piping the output of Git's command to "wc -l", thus losing the
exit status code of git.
Let's use the new helper test_stdout_line_count in order to preserve
Git's exit status code.
Signed-off-by: Đoàn Trần Công Danh <redacted>
---
t/t6402-merge-rename.sh | 132 +++++++++++++++++++---------------------
1 file changed, 64 insertions(+), 68 deletions(-)
@@ -330,8 +320,8 @@ test_expect_success 'Rename+D/F conflict; renamed file merges but dir in way' 'test_i18ngrep"Adding as dir~HEAD instead"outputfi&&-test3-eq"$(gitls-files-u|wc-l)"&&-test2-eq"$(gitls-files-udir/file-in-the-way|wc-l)"&&+test_stdout_line_count=3gitls-files-u&&+test_stdout_line_count=2gitls-files-udir/file-in-the-way&&test_must_failgitdiff--quiet&&test_must_failgitdiff--cached--quiet&&
@@ -357,8 +347,8 @@ test_expect_success 'Same as previous, but merged other way' 'test_i18ngrep"Adding as dir~renamed-file-has-no-conflicts instead"outputfi&&-test3-eq"$(gitls-files-u|wc-l)"&&-test2-eq"$(gitls-files-udir/file-in-the-way|wc-l)"&&+test_stdout_line_count=3gitls-files-u&&+test_stdout_line_count=2gitls-files-udir/file-in-the-way&&test_must_failgitdiff--quiet&&test_must_failgitdiff--cached--quiet&&
@@ -374,8 +364,8 @@ test_expect_success 'Rename+D/F conflict; renamed file cannot merge, dir not ingitcheckout-qrenamed-file-has-conflicts^0&&test_must_failgitmerge--strategy=recursivedir-not-in-way&&-test3-eq"$(gitls-files-u|wc-l)"&&-test3-eq"$(gitls-files-udir|wc-l)"&&+test_stdout_line_count=3gitls-files-u&&+test_stdout_line_count=3gitls-files-udir&&test_must_failgitdiff--quiet&&test_must_failgitdiff--cached--quiet&&
@@ -409,14 +399,16 @@ test_expect_success 'Rename+D/F conflict; renamed file cannot merge and dir in tgitcheckout-qrenamed-file-has-conflicts^0&&test_must_failgitmerge--strategy=recursivedir-in-way&&-test5-eq"$(gitls-files-u|wc-l)"&&+test_stdout_line_count=5gitls-files-u&&iftest"$GIT_TEST_MERGE_ALGORITHM"=ortthen-test3-eq"$(gitls-files-udir~HEAD|wc-l)"+test_stdout_line_count=3gitls-files-udir~HEADelse-test3-eq"$(gitls-files-udir|grep-vfile-in-the-way|wc-l)"+gitls-files-udir>out&&+test3-eq$(grep-vfile-in-the-wayout|wc-l)&&+rm-foutfi&&-test2-eq"$(gitls-files-udir/file-in-the-way|wc-l)"&&+test_stdout_line_count=2gitls-files-udir/file-in-the-way&&test_must_failgitdiff--quiet&&test_must_failgitdiff--cached--quiet&&
@@ -432,14 +424,16 @@ test_expect_success 'Same as previous, but merged other way' 'gitcheckout-qdir-in-way^0&&test_must_failgitmerge--strategy=recursiverenamed-file-has-conflicts&&-test5-eq"$(gitls-files-u|wc-l)"&&+test_stdout_line_count=5gitls-files-u&&iftest"$GIT_TEST_MERGE_ALGORITHM"=ortthen-test3-eq"$(gitls-files-udir~renamed-file-has-conflicts|wc-l)"+test_stdout_line_count=3gitls-files-udir~renamed-file-has-conflictselse-test3-eq"$(gitls-files-udir|grep-vfile-in-the-way|wc-l)"+gitls-files-udir>out&&+test3-eq$(grep-vfile-in-the-wayout|wc-l)&&+rm-foutfi&&-test2-eq"$(gitls-files-udir/file-in-the-way|wc-l)"&&+test_stdout_line_count=2gitls-files-udir/file-in-the-way&&test_must_failgitdiff--quiet&&test_must_failgitdiff--cached--quiet&&
@@ -496,9 +490,9 @@ test_expect_success 'both rename source and destination involved in D/F conflictiftest"$GIT_TEST_MERGE_ALGORITHM"=ortthen-test2-eq"$(gitls-files-u|wc-l)"+test_stdout_line_count=2gitls-files-uelse-test1-eq"$(gitls-files-u|wc-l)"+test_stdout_line_count=1gitls-files-ufi&&test_must_failgitdiff--quiet&&
@@ -582,13 +576,13 @@ test_expect_success 'pair rename to parent of other (D/F conflicts) w/ clean staiftest"$GIT_TEST_MERGE_ALGORITHM"=ortthen-test4-eq"$(gitls-files-u|wc-l)"&&-test2-eq"$(gitls-files-uone|wc-l)"&&-test2-eq"$(gitls-files-utwo|wc-l)"+test_stdout_line_count=4gitls-files-u&&+test_stdout_line_count=2gitls-files-uone&&+test_stdout_line_count=2gitls-files-utwoelse-test2-eq"$(gitls-files-u|wc-l)"&&-test1-eq"$(gitls-files-uone|wc-l)"&&-test1-eq"$(gitls-files-utwo|wc-l)"+test_stdout_line_count=2gitls-files-u&&+test_stdout_line_count=1gitls-files-uone&&+test_stdout_line_count=1gitls-files-utwofi&&test_must_failgitdiff--quiet&&
@@ -631,19 +625,19 @@ test_expect_success 'check handling of differently renamed file with D/F confliciftest"$GIT_TEST_MERGE_ALGORITHM"=ortthen-test5-eq"$(gitls-files-s|wc-l)"&&-test3-eq"$(gitls-files-u|wc-l)"&&-test1-eq"$(gitls-files-uone~HEAD|wc-l)"&&-test1-eq"$(gitls-files-utwo~second-rename|wc-l)"&&-test1-eq"$(gitls-files-uoriginal|wc-l)"&&-test0-eq"$(gitls-files-o|wc-l)"+test_stdout_line_count=5gitls-files-s&&+test_stdout_line_count=3gitls-files-u&&+test_stdout_line_count=1gitls-files-uone~HEAD&&+test_stdout_line_count=1gitls-files-utwo~second-rename&&+test_stdout_line_count=1gitls-files-uoriginal&&+test_stdout_line_count=0gitls-files-oelse-test5-eq"$(gitls-files-s|wc-l)"&&-test3-eq"$(gitls-files-u|wc-l)"&&-test1-eq"$(gitls-files-uone|wc-l)"&&-test1-eq"$(gitls-files-utwo|wc-l)"&&-test1-eq"$(gitls-files-uoriginal|wc-l)"&&-test2-eq"$(gitls-files-o|wc-l)"+test_stdout_line_count=5gitls-files-s&&+test_stdout_line_count=3gitls-files-u&&+test_stdout_line_count=1gitls-files-uone&&+test_stdout_line_count=1gitls-files-utwo&&+test_stdout_line_count=1gitls-files-uoriginal&&+test_stdout_line_count=2gitls-files-ofi&&test_path_is_fileone/file&&
@@ -679,11 +673,11 @@ test_expect_success 'check handling of differently renamed file with D/F conflicgitcheckout-qfirst-rename-redo^0&&test_must_failgitmerge--strategy=recursivesecond-rename-redo&&-test3-eq"$(gitls-files-u|wc-l)"&&-test1-eq"$(gitls-files-uone|wc-l)"&&-test1-eq"$(gitls-files-utwo|wc-l)"&&-test1-eq"$(gitls-files-uoriginal|wc-l)"&&-test0-eq"$(gitls-files-o|wc-l)"&&+test_stdout_line_count=3gitls-files-u&&+test_stdout_line_count=1gitls-files-uone&&+test_stdout_line_count=1gitls-files-utwo&&+test_stdout_line_count=1gitls-files-uoriginal&&+test_stdout_line_count=0gitls-files-o&&test_path_is_fileone&&test_path_is_filetwo&&
@@ -861,9 +855,11 @@ test_expect_success 'setup merge of rename + small change' ' test_expect_success'merge rename + small change''gitmergerename_branch&&-test1-eq$(gitls-files-s|wc-l)&&-test0-eq$(gitls-files-o|wc-l)&&-test$(gitrev-parseHEAD:renamed_file)=$(gitrev-parseHEAD~1:file)+test_stdout_line_count=1gitls-files-s&&+test_stdout_line_count=0gitls-files-o&&+newhash=$(gitrev-parseHEAD:renamed_file)&&+oldhash=$(gitrev-parseHEAD~1:file)&&+test$newhash=$oldhash' test_expect_success'setup for use of extended merge markers''
From: Eric Sunshine <hidden> Date: 2021-07-04 05:57:59
On Sun, Jul 4, 2021 at 1:46 AM Đoàn Trần Công Danh [off-list ref] wrote:
quoted hunk
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 <redacted>
---
@@ -845,6 +845,32 @@ test_line_count () {+# 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 () {
Nit: one too many blank lines after the test body.
A minor think-out-loud: I wonder if there would be value in deriving
the name of the output file from the command being run (perhaps by
using `tr` to translate oddball characters to underscore or to fold
them out). This might or might not help someone debugging a test
failure since there would be less chance of "$trashdir/output" being
repeatedly clobbered. Anyhow, it's something that could be done later
if deemed useful, not something for the present series. (I'm not
interested in seeing this series re-rolled endlessly.)