{"thread":{"id":"55936","subject":"[PATCH v2 0/5] t: new helper test_line_count_cmd","startedAt":"2021-06-15T17:20:57Z","lastAt":"2021-07-07T03:03:46Z","messageCount":42,"participants":["Đoàn Trần Công Danh","Junio C Hamano","Felipe Contreras","Eric Sunshine","Andrei Rybak"],"isPatch":true,"patchVersion":2,"patchTotal":5},"messages":[{"id":"427507","messageId":"20210615172038.28917-1-congdanhqx@gmail.com","threadId":"55936","inReplyTo":null,"subject":"[PATCH v2 0/5] t: new helper test_line_count_cmd","fromName":"Đoàn Trần Công Danh","fromEmail":"congdanhqx@gmail.com","sentAt":"2021-06-15T17:20:33Z","receivedAt":"2021-06-15T17:20:57Z","isPatch":true,"sender":{"key":"congdanhqx@gmail.com","avatar":"https://avatars.githubusercontent.com/u/42673067?v=4"},"body":"This is a series to clear false positive when applying Junio's suggestion to\nto a series written by Ævar [1].\n\nChange since v1:\n* Documentation for test_line_count_cmd has been written in more detail\n  with examples\n* The outfile and errfile will be created only if --out and/or --err was\n  specified for better \"-v\"\n* outfile and errfile will be created in $TRASH_DIRECTORY/.git/trash\n  iff $TRASH_DIRECTORY/.git is a directory, otherwise $TRASH_DIRECTORY,\n  avoid \"git rev-parse --git-dir\" because we may want to test it, too.\n* Use test_when_finished to clean those files instead of manual \"rm -f\",\n  also for better \"-v\"\n* Merge multiple instance of \"$@\" run into one, for better auditing\n* t0041 is also converted to use new helper\n* With the change to location of outfile and errfile,\n  output of \"git ls-files -o\" has been restored.\n* Fix double space before \"&&\" in the end of test command.\n\n1: https://lore.kernel.org/git/87r1j42ffz.fsf@evledraar.gmail.com/\n\nĐoàn Trần Công Danh (5):\n  test-lib-functions: introduce test_line_count_cmd\n  t6402: use find(1) builtin to filter instead of grep\n  t0041: use test_line_count_cmd to check std{out,err}\n  t6400: use test_line_count_cmd to count # of lines in stdout\n  t6402: use test_line_count_cmd to count # of lines in stdout\n\n t/t0041-usage.sh        |  53 ++++++----------\n t/t6400-merge-df.sh     |  16 ++---\n t/t6402-merge-rename.sh | 132 +++++++++++++++++++---------------------\n t/test-lib-functions.sh | 117 +++++++++++++++++++++++++++++++++++\n 4 files changed, 204 insertions(+), 114 deletions(-)\n\nRange-diff against v1:\n1:  bdce5e51ff < -:  ---------- test-lib-functions: introduce test_line_count_cmd\n-:  ---------- > 1:  a823312b19 test-lib-functions: introduce test_line_count_cmd\n2:  09a440ed25 = 2:  6e8f2d4289 t6402: use find(1) builtin to filter instead of grep\n-:  ---------- > 3:  33daa5ee2f t0041: use test_line_count_cmd to check std{out,err}\n3:  98a335a442 ! 4:  729ebb8f50 t6400: use test_line_count_cmd to count # of lines in stdout\n    @@ t/t6400-merge-df.sh: test_expect_success 'modify/delete + directory/file conflic\n     -\ttest 5 -eq $(git ls-files -s | wc -l) &&\n     -\ttest 4 -eq $(git ls-files -u | wc -l) &&\n     +\ttest_line_count_cmd --out = 5 git ls-files -s &&\n    -+\ttest_line_count_cmd --out = 4 git ls-files -u  &&\n    ++\ttest_line_count_cmd --out = 4 git ls-files -u &&\n      \tif test \"$GIT_TEST_MERGE_ALGORITHM\" = ort\n      \tthen\n     -\t\ttest 0 -eq $(git ls-files -o | wc -l)\n    -+\t\ttest_line_count_cmd --out = 2 git ls-files -o\n    ++\t\ttest_line_count_cmd --out = 0 git ls-files -o\n      \telse\n     -\t\ttest 1 -eq $(git ls-files -o | wc -l)\n    -+\t\ttest_line_count_cmd --out = 3 git ls-files -o\n    ++\t\ttest_line_count_cmd --out = 1 git ls-files -o\n      \tfi &&\n      \n      \ttest_path_is_file letters/file &&\n    @@ t/t6400-merge-df.sh: test_expect_success 'modify/delete + directory/file conflic\n      \n     -\ttest 5 -eq $(git ls-files -s | wc -l) &&\n     -\ttest 4 -eq $(git ls-files -u | wc -l) &&\n    -+\ttest_line_count_cmd --out = 5 git ls-files -s  &&\n    -+\ttest_line_count_cmd --out = 4 git ls-files -u  &&\n    ++\ttest_line_count_cmd --out = 5 git ls-files -s &&\n    ++\ttest_line_count_cmd --out = 4 git ls-files -u &&\n      \tif test \"$GIT_TEST_MERGE_ALGORITHM\" = ort\n      \tthen\n     -\t\ttest 0 -eq $(git ls-files -o | wc -l)\n    -+\t\ttest_line_count_cmd --out = 2 git ls-files -o\n    ++\t\ttest_line_count_cmd --out = 0 git ls-files -o\n      \telse\n     -\t\ttest 1 -eq $(git ls-files -o | wc -l)\n    -+\t\ttest_line_count_cmd --out = 3 git ls-files -o\n    ++\t\ttest_line_count_cmd --out = 1 git ls-files -o\n      \tfi &&\n      \n      \ttest_path_is_file letters/file &&\n4:  69e4a0b6d7 ! 5:  1b450e4148 t6402: use test_line_count_cmd to count # of lines in stdout\n    @@ t/t6402-merge-rename.sh: test_expect_success 'Rename+D/F conflict; renamed file\n      \n     -\ttest 3 -eq \"$(git ls-files -u | wc -l)\" &&\n     -\ttest 2 -eq \"$(git ls-files -u dir/file-in-the-way | wc -l)\" &&\n    -+\ttest_line_count_cmd --out = 3 git ls-files -u  &&\n    -+\ttest_line_count_cmd --out = 2 git ls-files -u dir/file-in-the-way  &&\n    ++\ttest_line_count_cmd --out = 3 git ls-files -u &&\n    ++\ttest_line_count_cmd --out = 2 git ls-files -u dir/file-in-the-way &&\n      \n      \ttest_must_fail git diff --quiet &&\n      \ttest_must_fail git diff --cached --quiet &&\n    @@ t/t6402-merge-rename.sh: test_expect_success 'Same as previous, but merged other\n      \n     -\ttest 3 -eq \"$(git ls-files -u | wc -l)\" &&\n     -\ttest 2 -eq \"$(git ls-files -u dir/file-in-the-way | wc -l)\" &&\n    -+\ttest_line_count_cmd --out = 3 git ls-files -u  &&\n    -+\ttest_line_count_cmd --out = 2 git ls-files -u dir/file-in-the-way  &&\n    ++\ttest_line_count_cmd --out = 3 git ls-files -u &&\n    ++\ttest_line_count_cmd --out = 2 git ls-files -u dir/file-in-the-way &&\n      \n      \ttest_must_fail git diff --quiet &&\n      \ttest_must_fail git diff --cached --quiet &&\n    @@ t/t6402-merge-rename.sh: test_expect_success 'Rename+D/F conflict; renamed file\n      \n     -\ttest 3 -eq \"$(git ls-files -u | wc -l)\" &&\n     -\ttest 3 -eq \"$(git ls-files -u dir | wc -l)\" &&\n    -+\ttest_line_count_cmd --out = 3 git ls-files -u  &&\n    -+\ttest_line_count_cmd --out = 3 git ls-files -u dir  &&\n    ++\ttest_line_count_cmd --out = 3 git ls-files -u &&\n    ++\ttest_line_count_cmd --out = 3 git ls-files -u dir &&\n      \n      \ttest_must_fail git diff --quiet &&\n      \ttest_must_fail git diff --cached --quiet &&\n    @@ t/t6402-merge-rename.sh: test_expect_success 'Rename+D/F conflict; renamed file\n      \ttest_must_fail git merge --strategy=recursive dir-in-way &&\n      \n     -\ttest 5 -eq \"$(git ls-files -u | wc -l)\" &&\n    -+\ttest_line_count_cmd --out = 5 git ls-files -u  &&\n    ++\ttest_line_count_cmd --out = 5 git ls-files -u &&\n      \tif test \"$GIT_TEST_MERGE_ALGORITHM\" = ort\n      \tthen\n     -\t\ttest 3 -eq \"$(git ls-files -u dir~HEAD | wc -l)\"\n    @@ t/t6402-merge-rename.sh: test_expect_success 'Rename+D/F conflict; renamed file\n     +\t\ttest_line_count_cmd --out = 3 grep -v file-in-the-way out\n      \tfi &&\n     -\ttest 2 -eq \"$(git ls-files -u dir/file-in-the-way | wc -l)\" &&\n    -+\ttest_line_count_cmd --out = 2 git ls-files -u dir/file-in-the-way  &&\n    ++\ttest_line_count_cmd --out = 2 git ls-files -u dir/file-in-the-way &&\n      \n      \ttest_must_fail git diff --quiet &&\n      \ttest_must_fail git diff --cached --quiet &&\n    @@ t/t6402-merge-rename.sh: test_expect_success 'Same as previous, but merged other\n      \ttest_must_fail git merge --strategy=recursive renamed-file-has-conflicts &&\n      \n     -\ttest 5 -eq \"$(git ls-files -u | wc -l)\" &&\n    -+\ttest_line_count_cmd --out = 5 git ls-files -u  &&\n    ++\ttest_line_count_cmd --out = 5 git ls-files -u &&\n      \tif test \"$GIT_TEST_MERGE_ALGORITHM\" = ort\n      \tthen\n     -\t\ttest 3 -eq \"$(git ls-files -u dir~renamed-file-has-conflicts | wc -l)\"\n    @@ t/t6402-merge-rename.sh: test_expect_success 'Same as previous, but merged other\n     +\t\ttest_line_count_cmd --out = 3 grep -v file-in-the-way out\n      \tfi &&\n     -\ttest 2 -eq \"$(git ls-files -u dir/file-in-the-way | wc -l)\" &&\n    -+\ttest_line_count_cmd --out = 2 git ls-files -u dir/file-in-the-way  &&\n    ++\ttest_line_count_cmd --out = 2 git ls-files -u dir/file-in-the-way &&\n      \n      \ttest_must_fail git diff --quiet &&\n      \ttest_must_fail git diff --cached --quiet &&\n    @@ t/t6402-merge-rename.sh: then\n     -\t\ttest 4 -eq \"$(git ls-files -u | wc -l)\" &&\n     -\t\ttest 2 -eq \"$(git ls-files -u one | wc -l)\" &&\n     -\t\ttest 2 -eq \"$(git ls-files -u two | wc -l)\" &&\n    -+\t\ttest_line_count_cmd --out = 4 git ls-files -u  &&\n    -+\t\ttest_line_count_cmd --out = 2 git ls-files -u one  &&\n    -+\t\ttest_line_count_cmd --out = 2 git ls-files -u two  &&\n    ++\t\ttest_line_count_cmd --out = 4 git ls-files -u &&\n    ++\t\ttest_line_count_cmd --out = 2 git ls-files -u one &&\n    ++\t\ttest_line_count_cmd --out = 2 git ls-files -u two &&\n      \n      \t\ttest_must_fail git diff --quiet &&\n      \n    @@ t/t6402-merge-rename.sh: else\n     -\t\ttest 2 -eq \"$(git ls-files -u | wc -l)\" &&\n     -\t\ttest 1 -eq \"$(git ls-files -u one | wc -l)\" &&\n     -\t\ttest 1 -eq \"$(git ls-files -u two | wc -l)\" &&\n    -+\t\ttest_line_count_cmd --out = 2 git ls-files -u  &&\n    -+\t\ttest_line_count_cmd --out = 1 git ls-files -u one  &&\n    -+\t\ttest_line_count_cmd --out = 1 git ls-files -u two  &&\n    ++\t\ttest_line_count_cmd --out = 2 git ls-files -u &&\n    ++\t\ttest_line_count_cmd --out = 1 git ls-files -u one &&\n    ++\t\ttest_line_count_cmd --out = 1 git ls-files -u two &&\n      \n      \t\ttest_must_fail git diff --quiet &&\n      \n    @@ t/t6402-merge-rename.sh: test_expect_success 'pair rename to parent of other (D/\n     -\t\ttest 4 -eq \"$(git ls-files -u | wc -l)\" &&\n     -\t\ttest 2 -eq \"$(git ls-files -u one | wc -l)\" &&\n     -\t\ttest 2 -eq \"$(git ls-files -u two | wc -l)\"\n    -+\t\ttest_line_count_cmd --out = 4 git ls-files -u  &&\n    -+\t\ttest_line_count_cmd --out = 2 git ls-files -u one  &&\n    ++\t\ttest_line_count_cmd --out = 4 git ls-files -u &&\n    ++\t\ttest_line_count_cmd --out = 2 git ls-files -u one &&\n     +\t\ttest_line_count_cmd --out = 2 git ls-files -u two\n      \telse\n     -\t\ttest 2 -eq \"$(git ls-files -u | wc -l)\" &&\n     -\t\ttest 1 -eq \"$(git ls-files -u one | wc -l)\" &&\n     -\t\ttest 1 -eq \"$(git ls-files -u two | wc -l)\"\n    -+\t\ttest_line_count_cmd --out = 2 git ls-files -u  &&\n    -+\t\ttest_line_count_cmd --out = 1 git ls-files -u one  &&\n    ++\t\ttest_line_count_cmd --out = 2 git ls-files -u &&\n    ++\t\ttest_line_count_cmd --out = 1 git ls-files -u one &&\n     +\t\ttest_line_count_cmd --out = 1 git ls-files -u two\n      \tfi &&\n      \n    @@ t/t6402-merge-rename.sh: test_expect_success 'check handling of differently rena\n     -\t\ttest 1 -eq \"$(git ls-files -u two~second-rename | wc -l)\" &&\n     -\t\ttest 1 -eq \"$(git ls-files -u original | wc -l)\" &&\n     -\t\ttest 0 -eq \"$(git ls-files -o | wc -l)\"\n    -+\t\ttest_line_count_cmd --out = 5 git ls-files -s  &&\n    -+\t\ttest_line_count_cmd --out = 3 git ls-files -u  &&\n    -+\t\ttest_line_count_cmd --out = 1 git ls-files -u one~HEAD  &&\n    -+\t\ttest_line_count_cmd --out = 1 git ls-files -u two~second-rename  &&\n    -+\t\ttest_line_count_cmd --out = 1 git ls-files -u original  &&\n    -+\t\ttest_line_count_cmd --out = 2 git ls-files -o\n    ++\t\ttest_line_count_cmd --out = 5 git ls-files -s &&\n    ++\t\ttest_line_count_cmd --out = 3 git ls-files -u &&\n    ++\t\ttest_line_count_cmd --out = 1 git ls-files -u one~HEAD &&\n    ++\t\ttest_line_count_cmd --out = 1 git ls-files -u two~second-rename &&\n    ++\t\ttest_line_count_cmd --out = 1 git ls-files -u original &&\n    ++\t\ttest_line_count_cmd --out = 0 git ls-files -o\n      \telse\n     -\t\ttest 5 -eq \"$(git ls-files -s | wc -l)\" &&\n     -\t\ttest 3 -eq \"$(git ls-files -u | wc -l)\" &&\n    @@ t/t6402-merge-rename.sh: test_expect_success 'check handling of differently rena\n     -\t\ttest 1 -eq \"$(git ls-files -u two | wc -l)\" &&\n     -\t\ttest 1 -eq \"$(git ls-files -u original | wc -l)\" &&\n     -\t\ttest 2 -eq \"$(git ls-files -o | wc -l)\"\n    -+\t\ttest_line_count_cmd --out = 5 git ls-files -s  &&\n    -+\t\ttest_line_count_cmd --out = 3 git ls-files -u  &&\n    -+\t\ttest_line_count_cmd --out = 1 git ls-files -u one  &&\n    -+\t\ttest_line_count_cmd --out = 1 git ls-files -u two  &&\n    -+\t\ttest_line_count_cmd --out = 1 git ls-files -u original  &&\n    -+\t\ttest_line_count_cmd --out = 4 git ls-files -o\n    ++\t\ttest_line_count_cmd --out = 5 git ls-files -s &&\n    ++\t\ttest_line_count_cmd --out = 3 git ls-files -u &&\n    ++\t\ttest_line_count_cmd --out = 1 git ls-files -u one &&\n    ++\t\ttest_line_count_cmd --out = 1 git ls-files -u two &&\n    ++\t\ttest_line_count_cmd --out = 1 git ls-files -u original &&\n    ++\t\ttest_line_count_cmd --out = 2 git ls-files -o\n      \tfi &&\n      \n      \ttest_path_is_file one/file &&\n    @@ t/t6402-merge-rename.sh: test_expect_success 'check handling of differently rena\n     -\ttest 1 -eq \"$(git ls-files -u two | wc -l)\" &&\n     -\ttest 1 -eq \"$(git ls-files -u original | wc -l)\" &&\n     -\ttest 0 -eq \"$(git ls-files -o | wc -l)\" &&\n    -+\ttest_line_count_cmd --out = 3 git ls-files -u  &&\n    -+\ttest_line_count_cmd --out = 1 git ls-files -u one  &&\n    -+\ttest_line_count_cmd --out = 1 git ls-files -u two  &&\n    -+\ttest_line_count_cmd --out = 1 git ls-files -u original  &&\n    -+\ttest_line_count_cmd --out = 2 git ls-files -o  &&\n    ++\ttest_line_count_cmd --out = 3 git ls-files -u &&\n    ++\ttest_line_count_cmd --out = 1 git ls-files -u one &&\n    ++\ttest_line_count_cmd --out = 1 git ls-files -u two &&\n    ++\ttest_line_count_cmd --out = 1 git ls-files -u original &&\n    ++\ttest_line_count_cmd --out = 0 git ls-files -o &&\n      \n      \ttest_path_is_file one &&\n      \ttest_path_is_file two &&\n    @@ t/t6402-merge-rename.sh: test_expect_success 'setup merge of rename + small chan\n      \n     -\ttest 1 -eq $(git ls-files -s | wc -l) &&\n     -\ttest 0 -eq $(git ls-files -o | wc -l) &&\n    -+\ttest_line_count_cmd --out = 1 git ls-files -s  &&\n    -+\ttest_line_count_cmd --out = 2 git ls-files -o  &&\n    ++\ttest_line_count_cmd --out = 1 git ls-files -s &&\n    ++\ttest_line_count_cmd --out = 0 git ls-files -o &&\n      \ttest $(git rev-parse HEAD:renamed_file) = $(git rev-parse HEAD~1:file)\n      '\n      \n-- \n2.32.0.278.gd42b80f139\n\n"},{"id":"427508","messageId":"20210615172038.28917-2-congdanhqx@gmail.com","threadId":"55936","inReplyTo":"20210615172038.28917-1-congdanhqx@gmail.com","subject":"[PATCH v2 1/5] test-lib-functions: introduce test_line_count_cmd","fromName":"Đoàn Trần Công Danh","fromEmail":"congdanhqx@gmail.com","sentAt":"2021-06-15T17:20:34Z","receivedAt":"2021-06-15T17:20:58Z","isPatch":true,"sender":{"key":"congdanhqx@gmail.com","avatar":"https://avatars.githubusercontent.com/u/42673067?v=4"},"body":"In Git project, we have multiple occasions that requires checking number\nof lines of text in stdout and/or stderr of a command. One of such\nexample is t6400, which checks number of files in various states.\n\nSome of those commands are Git command, and we would like to check their\nexit status.  In some of those checks, we pipe the stdout of those\ncommands to \"wc -l\" to check for line count, thus loosing the exit status.\n\nIntroduce a helper function to check for number of lines in stdout and\nstderr from those commands.\n\nThis helper will create 2 temporary files in process, thus it may affect\noutput of some checks.\n\nSigned-off-by: Đoàn Trần Công Danh <congdanhqx@gmail.com>\n---\n t/test-lib-functions.sh | 117 ++++++++++++++++++++++++++++++++++++++++\n 1 file changed, 117 insertions(+)\n\ndiff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh\nindex f0448daa74..b3281409de 100644\n--- a/t/test-lib-functions.sh\n+++ b/t/test-lib-functions.sh\n@@ -845,6 +845,123 @@ test_line_count () {\n \tfi\n }\n \n+# test_line_count_cmd checks exit status, and the number of lines in\n+# captured stdout and/or stderr of a command.\n+#\n+# Usage:\n+#\n+# test_line_count_cmd [--[out|err] <binop> <value>]... [--] [!] cmd [args...]\n+#\n+# Options:\n+# --out <binop> <value>:\n+# --err <binop> <value>:\n+#\tRun sh's \"test <# of lines> <binop> <value>\" on # of lines in stdout\n+#\t(for --out) or stderr (for --err)\n+# !:\n+#\tInstead of expecting \"cmd [args...]\" succeed, expect its failure.\n+#\tNote, if command under testing is \"git\", test_must_fail should be used\n+#\tinstead of \"!\".\n+#\n+# Example:\n+#\ttest_line_count_cmd --out -ge 10 --err = 0 git tag --no-contains v1.0.0\n+#\ttest_line_count_cmd --out -le 10 ! grep some-text a-file\n+#\ttest_line_count_cmd --out = 0 test_must_fail git rev-parse --verify abcd1234\n+#\n+# NOTE:\n+# * if \"--out\" is specified, a temporary file named test_line_count_cmd_.out\n+#   will be created.\n+# * if \"--err\" is specified, a temporary file named test_line_count_cmd_.err\n+#   will be created.\n+# Those temporary files will be created under $TRASH_DIRECTORY/.git/trash\n+# if $TRASH_DIRECTORY/.git directory existed.\n+# Otherwise, they will be created in $TRASH_DIRECTORY.\n+# Those temporary files will be cleant by test_when_finished\n+test_line_count_cmd () {\n+\t{\n+\t\tlocal outop outval outfile\n+\t\tlocal errop errval errfile\n+\t\tlocal expect_failure actual_failure\n+\t\tlocal trashdir=\"$TRASH_DIRECTORY\"\n+\n+\t\tif test -d \"$TRASH_DIRECTORY/.git\"\n+\t\tthen\n+\t\t\ttrashdir=\"$TRASH_DIRECTORY/.git/trash\" &&\n+\t\t\tmkdir -p \"$trashdir\"\n+\t\tfi &&\n+\t\twhile test $# != 0\n+\t\tdo\n+\t\t\tcase \"$1\" in\n+\t\t\t--out)\n+\t\t\t\toutop=\"$2\" &&\n+\t\t\t\toutval=\"$3\" &&\n+\t\t\t\toutfile=\"$trashdir/test_line_count_cmd_.out\" &&\n+\t\t\t\tshift 3\n+\t\t\t\t;;\n+\t\t\t--err)\n+\t\t\t\terrop=\"$2\" &&\n+\t\t\t\terrval=\"$3\" &&\n+\t\t\t\terrfile=\"$trashdir/test_line_count_cmd_.err\" &&\n+\t\t\t\tshift 3\n+\t\t\t\t;;\n+\t\t\t--)\n+\t\t\t\tshift &&\n+\t\t\t\tbreak\n+\t\t\t\t;;\n+\t\t\t-*)\n+\t\t\t\tBUG \"test_line_count_cmd: unknown options: '$1'\"\n+\t\t\t\t;;\n+\t\t\t*)\n+\t\t\t\tbreak\n+\t\t\t\t;;\n+\t\t\tesac\n+\t\tdone &&\n+\t\tif test \"x$1\" = \"x!\"\n+\t\tthen\n+\t\t\tshift &&\n+\t\t\texpect_failure=yes\n+\t\tfi &&\n+\t\tif test $# = 0\n+\t\tthen\n+\t\t\tBUG \"test_line_count_cmd: no command to be run\"\n+\t\telif test -z \"$outop$errop\"\n+\t\tthen\n+\t\t\tBUG \"test_line_count_cmd: check which stream?\"\n+\t\telse\n+\t\t\tif test -n \"$outfile\"\n+\t\t\tthen\n+\t\t\t\ttest_when_finished \"rm -f '$outfile'\" &&\n+\t\t\t\texec 8>\"$outfile\"\n+\t\t\tfi &&\n+\t\t\tif test -n \"$errfile\"\n+\t\t\tthen\n+\t\t\t\ttest_when_finished \"rm -f '$errfile'\" &&\n+\t\t\t\texec 9>\"$errfile\"\n+\t\t\tfi &&\n+\t\t\tif ! \"$@\" >&8 2>&9\n+\t\t\tthen\n+\t\t\t\tactual_failure=yes\n+\t\t\tfi\n+\t\tfi 8>&1 &&\n+\t\tcase \"$expect_failure,$actual_failure\" in\n+\t\tyes,)\n+\t\t\techo >&4 \"error: '$@' succeed!\"\n+\t\t\treturn 1\n+\t\t\t;;\n+\t\t,yes)\n+\t\t\techo >&4 \"error: '$@' run into failure!\"\n+\t\t\treturn 1\n+\t\tesac &&\n+\t\tif test -n \"$outop\"\n+\t\tthen\n+\t\t\ttest_line_count \"$outop\" \"$outval\" \"$outfile\" >&4\n+\t\tfi &&\n+\t\tif test -n \"$errop\"\n+\t\tthen\n+\t\t\ttest_line_count \"$errop\" \"$errval\" \"$errfile\" >&4\n+\t\tfi\n+\t} 9>&2 2>&4\n+}\n+\n test_file_size () {\n \ttest \"$#\" -ne 1 && BUG \"1 param\"\n \ttest-tool path-utils file-size \"$1\"\n-- \n2.32.0.278.gd42b80f139\n\n"},{"id":"427509","messageId":"20210615172038.28917-3-congdanhqx@gmail.com","threadId":"55936","inReplyTo":"20210615172038.28917-1-congdanhqx@gmail.com","subject":"[PATCH v2 2/5] t6402: use find(1) builtin to filter instead of grep","fromName":"Đoàn Trần Công Danh","fromEmail":"congdanhqx@gmail.com","sentAt":"2021-06-15T17:20:35Z","receivedAt":"2021-06-15T17:21:04Z","isPatch":true,"sender":{"key":"congdanhqx@gmail.com","avatar":"https://avatars.githubusercontent.com/u/42673067?v=4"},"body":"find(1) has a builtin (-prune) to filter its output, save a bit of time\nfor invoking grep(1).\n\nIn addition, in a later change, we will try to use test_line_count_cmd\nto count number of lines in stdout and/or stderr of a command, due to\nlimitation of current implementation, it can handle pipe.\n\nLet's replace grep(1)'s usage with find(1) builtin filter.\n\nSigned-off-by: Đoàn Trần Công Danh <congdanhqx@gmail.com>\n---\n t/t6402-merge-rename.sh | 6 +++---\n 1 file changed, 3 insertions(+), 3 deletions(-)\n\ndiff --git a/t/t6402-merge-rename.sh b/t/t6402-merge-rename.sh\nindex 425dad97d5..5d76cd6414 100755\n--- a/t/t6402-merge-rename.sh\n+++ b/t/t6402-merge-rename.sh\n@@ -546,7 +546,7 @@ then\n \n \t\ttest_must_fail git diff --quiet &&\n \n-\t\ttest 3 -eq $(find . | grep -v .git | wc -l) &&\n+\t\ttest 3 -eq $(find . -name .git -prune -o -print | wc -l) &&\n \n \t\ttest_path_is_file one &&\n \t\ttest_path_is_file two &&\n@@ -565,7 +565,7 @@ else\n \n \t\ttest_must_fail git diff --quiet &&\n \n-\t\ttest 4 -eq $(find . | grep -v .git | wc -l) &&\n+\t\ttest 4 -eq $(find . -name .git -prune -o -print | wc -l) &&\n \n \t\ttest_path_is_dir one &&\n \t\ttest_path_is_file one~rename-two &&\n@@ -593,7 +593,7 @@ test_expect_success 'pair rename to parent of other (D/F conflicts) w/ clean sta\n \n \ttest_must_fail git diff --quiet &&\n \n-\ttest 3 -eq $(find . | grep -v .git | wc -l) &&\n+\ttest 3 -eq $(find . -name .git -prune -o -print | wc -l) &&\n \n \ttest_path_is_file one &&\n \ttest_path_is_file two &&\n-- \n2.32.0.278.gd42b80f139\n\n"},{"id":"427510","messageId":"20210615172038.28917-4-congdanhqx@gmail.com","threadId":"55936","inReplyTo":"20210615172038.28917-1-congdanhqx@gmail.com","subject":"[PATCH v2 3/5] t0041: use test_line_count_cmd to check std{out,err}","fromName":"Đoàn Trần Công Danh","fromEmail":"congdanhqx@gmail.com","sentAt":"2021-06-15T17:20:36Z","receivedAt":"2021-06-15T17:21:08Z","isPatch":true,"sender":{"key":"congdanhqx@gmail.com","avatar":"https://avatars.githubusercontent.com/u/42673067?v=4"},"body":"Signed-off-by: Đoàn Trần Công Danh <congdanhqx@gmail.com>\n---\n t/t0041-usage.sh | 53 ++++++++++++++++--------------------------------\n 1 file changed, 17 insertions(+), 36 deletions(-)\n\ndiff --git a/t/t0041-usage.sh b/t/t0041-usage.sh\nindex c4fc34eb18..24e24f698c 100755\n--- a/t/t0041-usage.sh\n+++ b/t/t0041-usage.sh\n@@ -12,98 +12,79 @@ test_expect_success 'setup ' '\n '\n \n test_expect_success 'tag --contains <existent_tag>' '\n-\tgit tag --contains \"v1.0\" >actual 2>actual.err &&\n-\tgrep \"v1.0\" actual &&\n-\ttest_line_count = 0 actual.err\n+\ttest_line_count_cmd --err = 0 git tag --contains v1.0 >actual &&\n+\tgrep \"v1.0\" actual\n '\n \n test_expect_success 'tag --contains <inexistent_tag>' '\n-\ttest_must_fail git tag --contains \"notag\" >actual 2>actual.err &&\n-\ttest_line_count = 0 actual &&\n+\ttest_line_count_cmd --out = 0 test_must_fail git tag --contains notag 2>actual.err &&\n \ttest_i18ngrep \"error\" actual.err &&\n \ttest_i18ngrep ! \"usage\" actual.err\n '\n \n test_expect_success 'tag --no-contains <existent_tag>' '\n-\tgit tag --no-contains \"v1.0\" >actual 2>actual.err  &&\n-\ttest_line_count = 0 actual &&\n-\ttest_line_count = 0 actual.err\n+\ttest_line_count_cmd --out = 0 --err = 0 git tag --no-contains v1.0\n '\n \n test_expect_success 'tag --no-contains <inexistent_tag>' '\n-\ttest_must_fail git tag --no-contains \"notag\" >actual 2>actual.err &&\n-\ttest_line_count = 0 actual &&\n+\ttest_line_count_cmd --out = 0 test_must_fail git tag --no-contains notag 2>actual.err &&\n \ttest_i18ngrep \"error\" actual.err &&\n \ttest_i18ngrep ! \"usage\" actual.err\n '\n \n test_expect_success 'tag usage error' '\n-\ttest_must_fail git tag --noopt >actual 2>actual.err &&\n-\ttest_line_count = 0 actual &&\n+\ttest_line_count_cmd --out = 0 test_must_fail git tag --noopt 2>actual.err &&\n \ttest_i18ngrep \"usage\" actual.err\n '\n \n test_expect_success 'branch --contains <existent_commit>' '\n-\tgit branch --contains \"main\" >actual 2>actual.err &&\n-\ttest_i18ngrep \"main\" actual &&\n-\ttest_line_count = 0 actual.err\n+\ttest_line_count_cmd --err = 0 git branch --contains main >actual &&\n+\ttest_i18ngrep \"main\" actual\n '\n \n test_expect_success 'branch --contains <inexistent_commit>' '\n-\ttest_must_fail git branch --no-contains \"nocommit\" >actual 2>actual.err &&\n-\ttest_line_count = 0 actual &&\n+\ttest_line_count_cmd --out = 0 test_must_fail git branch --no-contains \"nocommit\" 2>actual.err &&\n \ttest_i18ngrep \"error\" actual.err &&\n \ttest_i18ngrep ! \"usage\" actual.err\n '\n \n test_expect_success 'branch --no-contains <existent_commit>' '\n-\tgit branch --no-contains \"main\" >actual 2>actual.err &&\n-\ttest_line_count = 0 actual &&\n-\ttest_line_count = 0 actual.err\n+\ttest_line_count_cmd --out = 0 --err = 0 git branch --no-contains main\n '\n \n test_expect_success 'branch --no-contains <inexistent_commit>' '\n-\ttest_must_fail git branch --no-contains \"nocommit\" >actual 2>actual.err &&\n-\ttest_line_count = 0 actual &&\n+\ttest_line_count_cmd --out = 0 test_must_fail git branch --no-contains \"nocommit\" 2>actual.err &&\n \ttest_i18ngrep \"error\" actual.err &&\n \ttest_i18ngrep ! \"usage\" actual.err\n '\n \n test_expect_success 'branch usage error' '\n-\ttest_must_fail git branch --noopt >actual 2>actual.err &&\n-\ttest_line_count = 0 actual &&\n+\ttest_line_count_cmd --out = 0 test_must_fail git branch --noopt 2>actual.err &&\n \ttest_i18ngrep \"usage\" actual.err\n '\n \n test_expect_success 'for-each-ref --contains <existent_object>' '\n-\tgit for-each-ref --contains \"main\" >actual 2>actual.err &&\n-\ttest_line_count = 2 actual &&\n-\ttest_line_count = 0 actual.err\n+\ttest_line_count_cmd --out = 2 --err = 0 git for-each-ref --contains main\n '\n \n test_expect_success 'for-each-ref --contains <inexistent_object>' '\n-\ttest_must_fail git for-each-ref --no-contains \"noobject\" >actual 2>actual.err &&\n-\ttest_line_count = 0 actual &&\n+\ttest_line_count_cmd --out = 0 test_must_fail git for-each-ref --no-contains \"noobject\" 2>actual.err &&\n \ttest_i18ngrep \"error\" actual.err &&\n \ttest_i18ngrep ! \"usage\" actual.err\n '\n \n test_expect_success 'for-each-ref --no-contains <existent_object>' '\n-\tgit for-each-ref --no-contains \"main\" >actual 2>actual.err &&\n-\ttest_line_count = 0 actual &&\n-\ttest_line_count = 0 actual.err\n+\ttest_line_count_cmd --out = 0 --err = 0 git for-each-ref --no-contains \"main\"\n '\n \n test_expect_success 'for-each-ref --no-contains <inexistent_object>' '\n-\ttest_must_fail git for-each-ref --no-contains \"noobject\" >actual 2>actual.err &&\n-\ttest_line_count = 0 actual &&\n+\ttest_line_count_cmd --out = 0 test_must_fail git for-each-ref --no-contains \"noobject\" 2>actual.err &&\n \ttest_i18ngrep \"error\" actual.err &&\n \ttest_i18ngrep ! \"usage\" actual.err\n '\n \n test_expect_success 'for-each-ref usage error' '\n-\ttest_must_fail git for-each-ref --noopt >actual 2>actual.err &&\n-\ttest_line_count = 0 actual &&\n+\ttest_line_count_cmd --out = 0 test_must_fail git for-each-ref --noopt 2>actual.err &&\n \ttest_i18ngrep \"usage\" actual.err\n '\n \n-- \n2.32.0.278.gd42b80f139\n\n"},{"id":"427511","messageId":"20210615172038.28917-5-congdanhqx@gmail.com","threadId":"55936","inReplyTo":"20210615172038.28917-1-congdanhqx@gmail.com","subject":"[PATCH v2 4/5] t6400: use test_line_count_cmd to count # of lines in stdout","fromName":"Đoàn Trần Công Danh","fromEmail":"congdanhqx@gmail.com","sentAt":"2021-06-15T17:20:37Z","receivedAt":"2021-06-15T17:21:16Z","isPatch":true,"sender":{"key":"congdanhqx@gmail.com","avatar":"https://avatars.githubusercontent.com/u/42673067?v=4"},"body":"Signed-off-by: Đoàn Trần Công Danh <congdanhqx@gmail.com>\n---\n t/t6400-merge-df.sh | 16 ++++++++--------\n 1 file changed, 8 insertions(+), 8 deletions(-)\n\ndiff --git a/t/t6400-merge-df.sh b/t/t6400-merge-df.sh\nindex 38700d29b5..8cf3603a24 100755\n--- a/t/t6400-merge-df.sh\n+++ b/t/t6400-merge-df.sh\n@@ -82,13 +82,13 @@ test_expect_success 'modify/delete + directory/file conflict' '\n \tgit checkout delete^0 &&\n \ttest_must_fail git merge modify &&\n \n-\ttest 5 -eq $(git ls-files -s | wc -l) &&\n-\ttest 4 -eq $(git ls-files -u | wc -l) &&\n+\ttest_line_count_cmd --out = 5 git ls-files -s &&\n+\ttest_line_count_cmd --out = 4 git ls-files -u &&\n \tif test \"$GIT_TEST_MERGE_ALGORITHM\" = ort\n \tthen\n-\t\ttest 0 -eq $(git ls-files -o | wc -l)\n+\t\ttest_line_count_cmd --out = 0 git ls-files -o\n \telse\n-\t\ttest 1 -eq $(git ls-files -o | wc -l)\n+\t\ttest_line_count_cmd --out = 1 git ls-files -o\n \tfi &&\n \n \ttest_path_is_file letters/file &&\n@@ -103,13 +103,13 @@ test_expect_success 'modify/delete + directory/file conflict; other way' '\n \n \ttest_must_fail git merge delete &&\n \n-\ttest 5 -eq $(git ls-files -s | wc -l) &&\n-\ttest 4 -eq $(git ls-files -u | wc -l) &&\n+\ttest_line_count_cmd --out = 5 git ls-files -s &&\n+\ttest_line_count_cmd --out = 4 git ls-files -u &&\n \tif test \"$GIT_TEST_MERGE_ALGORITHM\" = ort\n \tthen\n-\t\ttest 0 -eq $(git ls-files -o | wc -l)\n+\t\ttest_line_count_cmd --out = 0 git ls-files -o\n \telse\n-\t\ttest 1 -eq $(git ls-files -o | wc -l)\n+\t\ttest_line_count_cmd --out = 1 git ls-files -o\n \tfi &&\n \n \ttest_path_is_file letters/file &&\n-- \n2.32.0.278.gd42b80f139\n\n"},{"id":"427512","messageId":"20210615172038.28917-6-congdanhqx@gmail.com","threadId":"55936","inReplyTo":"20210615172038.28917-1-congdanhqx@gmail.com","subject":"[PATCH v2 5/5] t6402: use test_line_count_cmd to count # of lines in stdout","fromName":"Đoàn Trần Công Danh","fromEmail":"congdanhqx@gmail.com","sentAt":"2021-06-15T17:20:38Z","receivedAt":"2021-06-15T17:21:16Z","isPatch":true,"sender":{"key":"congdanhqx@gmail.com","avatar":"https://avatars.githubusercontent.com/u/42673067?v=4"},"body":"Signed-off-by: Đoàn Trần Công Danh <congdanhqx@gmail.com>\n---\n t/t6402-merge-rename.sh | 126 +++++++++++++++++++---------------------\n 1 file changed, 59 insertions(+), 67 deletions(-)\n\ndiff --git a/t/t6402-merge-rename.sh b/t/t6402-merge-rename.sh\nindex 5d76cd6414..ca84588eb5 100755\n--- a/t/t6402-merge-rename.sh\n+++ b/t/t6402-merge-rename.sh\n@@ -105,10 +105,8 @@ test_expect_success 'pull renaming branch into unrenaming one' \\\n \tgit show-branch &&\n \ttest_expect_code 1 git pull . white &&\n \tgit ls-files -s &&\n-\tgit ls-files -u B >b.stages &&\n-\ttest_line_count = 3 b.stages &&\n-\tgit ls-files -s N >n.stages &&\n-\ttest_line_count = 1 n.stages &&\n+\ttest_line_count_cmd --out = 3 git ls-files -u B &&\n+\ttest_line_count_cmd --out = 1 git ls-files -s N &&\n \tsed -ne \"/^g/{\n \tp\n \tq\n@@ -122,10 +120,8 @@ test_expect_success 'pull renaming branch into another renaming one' \\\n \tgit reset --hard &&\n \tgit checkout red &&\n \ttest_expect_code 1 git pull . white &&\n-\tgit ls-files -u B >b.stages &&\n-\ttest_line_count = 3 b.stages &&\n-\tgit ls-files -s N >n.stages &&\n-\ttest_line_count = 1 n.stages &&\n+\ttest_line_count_cmd --out = 3 git ls-files -u B &&\n+\ttest_line_count_cmd --out = 1 git ls-files -s N &&\n \tsed -ne \"/^g/{\n \tp\n \tq\n@@ -138,10 +134,8 @@ test_expect_success 'pull unrenaming branch into renaming one' \\\n \tgit reset --hard &&\n \tgit show-branch &&\n \ttest_expect_code 1 git pull . main &&\n-\tgit ls-files -u B >b.stages &&\n-\ttest_line_count = 3 b.stages &&\n-\tgit ls-files -s N >n.stages &&\n-\ttest_line_count = 1 n.stages &&\n+\ttest_line_count_cmd --out = 3 git ls-files -u B &&\n+\ttest_line_count_cmd --out = 1 git ls-files -s N &&\n \tsed -ne \"/^g/{\n \tp\n \tq\n@@ -154,14 +148,10 @@ test_expect_success 'pull conflicting renames' \\\n \tgit reset --hard &&\n \tgit show-branch &&\n \ttest_expect_code 1 git pull . blue &&\n-\tgit ls-files -u A >a.stages &&\n-\ttest_line_count = 1 a.stages &&\n-\tgit ls-files -u B >b.stages &&\n-\ttest_line_count = 1 b.stages &&\n-\tgit ls-files -u C >c.stages &&\n-\ttest_line_count = 1 c.stages &&\n-\tgit ls-files -s N >n.stages &&\n-\ttest_line_count = 1 n.stages &&\n+\ttest_line_count_cmd --out = 1 git ls-files -u A &&\n+\ttest_line_count_cmd --out = 1 git ls-files -u B &&\n+\ttest_line_count_cmd --out = 1 git ls-files -u C &&\n+\ttest_line_count_cmd --out = 1 git ls-files -s N &&\n \tsed -ne \"/^g/{\n \tp\n \tq\n@@ -330,8 +320,8 @@ test_expect_success 'Rename+D/F conflict; renamed file merges but dir in way' '\n \t\ttest_i18ngrep \"Adding as dir~HEAD instead\" output\n \tfi &&\n \n-\ttest 3 -eq \"$(git ls-files -u | wc -l)\" &&\n-\ttest 2 -eq \"$(git ls-files -u dir/file-in-the-way | wc -l)\" &&\n+\ttest_line_count_cmd --out = 3 git ls-files -u &&\n+\ttest_line_count_cmd --out = 2 git ls-files -u dir/file-in-the-way &&\n \n \ttest_must_fail git diff --quiet &&\n \ttest_must_fail git diff --cached --quiet &&\n@@ -357,8 +347,8 @@ test_expect_success 'Same as previous, but merged other way' '\n \t\ttest_i18ngrep \"Adding as dir~renamed-file-has-no-conflicts instead\" output\n \tfi &&\n \n-\ttest 3 -eq \"$(git ls-files -u | wc -l)\" &&\n-\ttest 2 -eq \"$(git ls-files -u dir/file-in-the-way | wc -l)\" &&\n+\ttest_line_count_cmd --out = 3 git ls-files -u &&\n+\ttest_line_count_cmd --out = 2 git ls-files -u dir/file-in-the-way &&\n \n \ttest_must_fail git diff --quiet &&\n \ttest_must_fail git diff --cached --quiet &&\n@@ -374,8 +364,8 @@ test_expect_success 'Rename+D/F conflict; renamed file cannot merge, dir not in\n \tgit checkout -q renamed-file-has-conflicts^0 &&\n \ttest_must_fail git merge --strategy=recursive dir-not-in-way &&\n \n-\ttest 3 -eq \"$(git ls-files -u | wc -l)\" &&\n-\ttest 3 -eq \"$(git ls-files -u dir | wc -l)\" &&\n+\ttest_line_count_cmd --out = 3 git ls-files -u &&\n+\ttest_line_count_cmd --out = 3 git ls-files -u dir &&\n \n \ttest_must_fail git diff --quiet &&\n \ttest_must_fail git diff --cached --quiet &&\n@@ -409,14 +399,15 @@ test_expect_success 'Rename+D/F conflict; renamed file cannot merge and dir in t\n \tgit checkout -q renamed-file-has-conflicts^0 &&\n \ttest_must_fail git merge --strategy=recursive dir-in-way &&\n \n-\ttest 5 -eq \"$(git ls-files -u | wc -l)\" &&\n+\ttest_line_count_cmd --out = 5 git ls-files -u &&\n \tif test \"$GIT_TEST_MERGE_ALGORITHM\" = ort\n \tthen\n-\t\ttest 3 -eq \"$(git ls-files -u dir~HEAD | wc -l)\"\n+\t\ttest_line_count_cmd --out = 3 git ls-files -u dir~HEAD\n \telse\n-\t\ttest 3 -eq \"$(git ls-files -u dir | grep -v file-in-the-way | wc -l)\"\n+\t\tgit ls-files -u dir >out &&\n+\t\ttest_line_count_cmd --out = 3 grep -v file-in-the-way out\n \tfi &&\n-\ttest 2 -eq \"$(git ls-files -u dir/file-in-the-way | wc -l)\" &&\n+\ttest_line_count_cmd --out = 2 git ls-files -u dir/file-in-the-way &&\n \n \ttest_must_fail git diff --quiet &&\n \ttest_must_fail git diff --cached --quiet &&\n@@ -432,14 +423,15 @@ test_expect_success 'Same as previous, but merged other way' '\n \tgit checkout -q dir-in-way^0 &&\n \ttest_must_fail git merge --strategy=recursive renamed-file-has-conflicts &&\n \n-\ttest 5 -eq \"$(git ls-files -u | wc -l)\" &&\n+\ttest_line_count_cmd --out = 5 git ls-files -u &&\n \tif test \"$GIT_TEST_MERGE_ALGORITHM\" = ort\n \tthen\n-\t\ttest 3 -eq \"$(git ls-files -u dir~renamed-file-has-conflicts | wc -l)\"\n+\t\ttest_line_count_cmd --out = 3 git ls-files -u dir~renamed-file-has-conflicts\n \telse\n-\t\ttest 3 -eq \"$(git ls-files -u dir | grep -v file-in-the-way | wc -l)\"\n+\t\tgit ls-files -u dir >out &&\n+\t\ttest_line_count_cmd --out = 3 grep -v file-in-the-way out\n \tfi &&\n-\ttest 2 -eq \"$(git ls-files -u dir/file-in-the-way | wc -l)\" &&\n+\ttest_line_count_cmd --out = 2 git ls-files -u dir/file-in-the-way &&\n \n \ttest_must_fail git diff --quiet &&\n \ttest_must_fail git diff --cached --quiet &&\n@@ -496,9 +488,9 @@ test_expect_success 'both rename source and destination involved in D/F conflict\n \n \tif test \"$GIT_TEST_MERGE_ALGORITHM\" = ort\n \tthen\n-\t\ttest 2 -eq \"$(git ls-files -u | wc -l)\"\n+\t\ttest_line_count_cmd --out = 2 git ls-files -u\n \telse\n-\t\ttest 1 -eq \"$(git ls-files -u | wc -l)\"\n+\t\ttest_line_count_cmd --out = 1 git ls-files -u\n \tfi &&\n \n \ttest_must_fail git diff --quiet &&\n@@ -540,9 +532,9 @@ then\n \t\tmkdir one &&\n \t\ttest_must_fail git merge --strategy=recursive rename-two &&\n \n-\t\ttest 4 -eq \"$(git ls-files -u | wc -l)\" &&\n-\t\ttest 2 -eq \"$(git ls-files -u one | wc -l)\" &&\n-\t\ttest 2 -eq \"$(git ls-files -u two | wc -l)\" &&\n+\t\ttest_line_count_cmd --out = 4 git ls-files -u &&\n+\t\ttest_line_count_cmd --out = 2 git ls-files -u one &&\n+\t\ttest_line_count_cmd --out = 2 git ls-files -u two &&\n \n \t\ttest_must_fail git diff --quiet &&\n \n@@ -559,9 +551,9 @@ else\n \t\tmkdir one &&\n \t\ttest_must_fail git merge --strategy=recursive rename-two &&\n \n-\t\ttest 2 -eq \"$(git ls-files -u | wc -l)\" &&\n-\t\ttest 1 -eq \"$(git ls-files -u one | wc -l)\" &&\n-\t\ttest 1 -eq \"$(git ls-files -u two | wc -l)\" &&\n+\t\ttest_line_count_cmd --out = 2 git ls-files -u &&\n+\t\ttest_line_count_cmd --out = 1 git ls-files -u one &&\n+\t\ttest_line_count_cmd --out = 1 git ls-files -u two &&\n \n \t\ttest_must_fail git diff --quiet &&\n \n@@ -582,13 +574,13 @@ test_expect_success 'pair rename to parent of other (D/F conflicts) w/ clean sta\n \n \tif test \"$GIT_TEST_MERGE_ALGORITHM\" = ort\n \tthen\n-\t\ttest 4 -eq \"$(git ls-files -u | wc -l)\" &&\n-\t\ttest 2 -eq \"$(git ls-files -u one | wc -l)\" &&\n-\t\ttest 2 -eq \"$(git ls-files -u two | wc -l)\"\n+\t\ttest_line_count_cmd --out = 4 git ls-files -u &&\n+\t\ttest_line_count_cmd --out = 2 git ls-files -u one &&\n+\t\ttest_line_count_cmd --out = 2 git ls-files -u two\n \telse\n-\t\ttest 2 -eq \"$(git ls-files -u | wc -l)\" &&\n-\t\ttest 1 -eq \"$(git ls-files -u one | wc -l)\" &&\n-\t\ttest 1 -eq \"$(git ls-files -u two | wc -l)\"\n+\t\ttest_line_count_cmd --out = 2 git ls-files -u &&\n+\t\ttest_line_count_cmd --out = 1 git ls-files -u one &&\n+\t\ttest_line_count_cmd --out = 1 git ls-files -u two\n \tfi &&\n \n \ttest_must_fail git diff --quiet &&\n@@ -631,19 +623,19 @@ test_expect_success 'check handling of differently renamed file with D/F conflic\n \n \tif test \"$GIT_TEST_MERGE_ALGORITHM\" = ort\n \tthen\n-\t\ttest 5 -eq \"$(git ls-files -s | wc -l)\" &&\n-\t\ttest 3 -eq \"$(git ls-files -u | wc -l)\" &&\n-\t\ttest 1 -eq \"$(git ls-files -u one~HEAD | wc -l)\" &&\n-\t\ttest 1 -eq \"$(git ls-files -u two~second-rename | wc -l)\" &&\n-\t\ttest 1 -eq \"$(git ls-files -u original | wc -l)\" &&\n-\t\ttest 0 -eq \"$(git ls-files -o | wc -l)\"\n+\t\ttest_line_count_cmd --out = 5 git ls-files -s &&\n+\t\ttest_line_count_cmd --out = 3 git ls-files -u &&\n+\t\ttest_line_count_cmd --out = 1 git ls-files -u one~HEAD &&\n+\t\ttest_line_count_cmd --out = 1 git ls-files -u two~second-rename &&\n+\t\ttest_line_count_cmd --out = 1 git ls-files -u original &&\n+\t\ttest_line_count_cmd --out = 0 git ls-files -o\n \telse\n-\t\ttest 5 -eq \"$(git ls-files -s | wc -l)\" &&\n-\t\ttest 3 -eq \"$(git ls-files -u | wc -l)\" &&\n-\t\ttest 1 -eq \"$(git ls-files -u one | wc -l)\" &&\n-\t\ttest 1 -eq \"$(git ls-files -u two | wc -l)\" &&\n-\t\ttest 1 -eq \"$(git ls-files -u original | wc -l)\" &&\n-\t\ttest 2 -eq \"$(git ls-files -o | wc -l)\"\n+\t\ttest_line_count_cmd --out = 5 git ls-files -s &&\n+\t\ttest_line_count_cmd --out = 3 git ls-files -u &&\n+\t\ttest_line_count_cmd --out = 1 git ls-files -u one &&\n+\t\ttest_line_count_cmd --out = 1 git ls-files -u two &&\n+\t\ttest_line_count_cmd --out = 1 git ls-files -u original &&\n+\t\ttest_line_count_cmd --out = 2 git ls-files -o\n \tfi &&\n \n \ttest_path_is_file one/file &&\n@@ -679,11 +671,11 @@ test_expect_success 'check handling of differently renamed file with D/F conflic\n \tgit checkout -q first-rename-redo^0 &&\n \ttest_must_fail git merge --strategy=recursive second-rename-redo &&\n \n-\ttest 3 -eq \"$(git ls-files -u | wc -l)\" &&\n-\ttest 1 -eq \"$(git ls-files -u one | wc -l)\" &&\n-\ttest 1 -eq \"$(git ls-files -u two | wc -l)\" &&\n-\ttest 1 -eq \"$(git ls-files -u original | wc -l)\" &&\n-\ttest 0 -eq \"$(git ls-files -o | wc -l)\" &&\n+\ttest_line_count_cmd --out = 3 git ls-files -u &&\n+\ttest_line_count_cmd --out = 1 git ls-files -u one &&\n+\ttest_line_count_cmd --out = 1 git ls-files -u two &&\n+\ttest_line_count_cmd --out = 1 git ls-files -u original &&\n+\ttest_line_count_cmd --out = 0 git ls-files -o &&\n \n \ttest_path_is_file one &&\n \ttest_path_is_file two &&\n@@ -861,8 +853,8 @@ test_expect_success 'setup merge of rename + small change' '\n test_expect_success 'merge rename + small change' '\n \tgit merge rename_branch &&\n \n-\ttest 1 -eq $(git ls-files -s | wc -l) &&\n-\ttest 0 -eq $(git ls-files -o | wc -l) &&\n+\ttest_line_count_cmd --out = 1 git ls-files -s &&\n+\ttest_line_count_cmd --out = 0 git ls-files -o &&\n \ttest $(git rev-parse HEAD:renamed_file) = $(git rev-parse HEAD~1:file)\n '\n \n-- \n2.32.0.278.gd42b80f139\n\n"},{"id":"427567","messageId":"xmqqlf7ase3d.fsf@gitster.g","threadId":"55936","inReplyTo":"20210615172038.28917-4-congdanhqx@gmail.com","subject":"Re: [PATCH v2 3/5] t0041: use test_line_count_cmd to check std{out,err}","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2021-06-16T03:06:14Z","receivedAt":"2021-06-16T03:06:19Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Đoàn Trần Công Danh  <congdanhqx@gmail.com> writes:\n\n>  test_expect_success 'tag --contains <existent_tag>' '\n> -\tgit tag --contains \"v1.0\" >actual 2>actual.err &&\n> -\tgrep \"v1.0\" actual &&\n> -\ttest_line_count = 0 actual.err\n> +\ttest_line_count_cmd --err = 0 git tag --contains v1.0 >actual &&\n> +\tgrep \"v1.0\" actual\n\nSorry, but I am not impressed if this is a typical/prime example of\nhow the new helper helps in writing our tests.\n\nNotice that so many tests that you touched only care about 0 lines?\n\nInstead of this new helper, I think it would be a more useful\nimprovement if we check the emptyness in a more direct way, i.e.\n\n>  test_expect_success 'tag --contains <existent_tag>' '\n> \tgit tag --contains \"v1.0\" >actual 2>actual.err &&\n> \tgrep \"v1.0\" actual &&\n> -\ttest_line_count = 0 actual.err\n> +\ttest_must_be_empty actual.err\n\nI think this helper may be misnamed and test_file_is_empty would sit\nbetter with test_dir_is_empty and test_file_not_empty that already\nexist, though.\n\nBy the way, my opinion would be quite different if example like this\none ...\n\n>  test_expect_success 'tag --no-contains <existent_tag>' '\n> -\tgit tag --no-contains \"v1.0\" >actual 2>actual.err  &&\n> -\ttest_line_count = 0 actual &&\n> -\ttest_line_count = 0 actual.err\n> +\ttest_line_count_cmd --out = 0 --err = 0 git tag --no-contains v1.0\n>  '\n\n... were the majority, but I do not think that is the case.  Most\ntests that employ the new test_line_count_cmd in this patch still\ncreate either actual or actual.err in the working tree anyway, so I\ndo not see much point in adding this new helper---it is hard to\nexplain to new test writers when to use it.\n"},{"id":"427616","messageId":"YMoJAnvigwexX5b5@danh.dev","threadId":"55936","inReplyTo":"xmqqlf7ase3d.fsf@gitster.g","subject":"Re: [PATCH v2 3/5] t0041: use test_line_count_cmd to check std{out,err}","fromName":"Đoàn Trần Công Danh","fromEmail":"congdanhqx@gmail.com","sentAt":"2021-06-16T14:21:54Z","receivedAt":"2021-06-16T14:22:04Z","isPatch":true,"sender":{"key":"congdanhqx@gmail.com","avatar":"https://avatars.githubusercontent.com/u/42673067?v=4"},"body":"On 2021-06-16 12:06:14+0900, Junio C Hamano <gitster@pobox.com> wrote:\n> Đoàn Trần Công Danh  <congdanhqx@gmail.com> writes:\n> \n> >  test_expect_success 'tag --contains <existent_tag>' '\n> > -\tgit tag --contains \"v1.0\" >actual 2>actual.err &&\n> > -\tgrep \"v1.0\" actual &&\n> > -\ttest_line_count = 0 actual.err\n> > +\ttest_line_count_cmd --err = 0 git tag --contains v1.0 >actual &&\n> > +\tgrep \"v1.0\" actual\n> \n> Sorry, but I am not impressed if this is a typical/prime example of\n> how the new helper helps in writing our tests.\n\nYay, reading through the patch again, and I'm become less enthusiastic\nwith persuading --err. The only useful application of --err is t4068.\n----8<---\ndiff --git a/t/t4068-diff-symmetric-merge-base.sh b/t/t4068-diff-symmetric-merge-base.sh\nindex 2d650d8f10..33e2327072 100755\n--- a/t/t4068-diff-symmetric-merge-base.sh\n+++ b/t/t4068-diff-symmetric-merge-base.sh\n@@ -61,9 +61,7 @@ test_expect_success 'diff with one merge base' '\n # It should have one of those two, which comes out\n # to seven lines.\n test_expect_success 'diff with two merge bases' '\n-\tgit diff br1...main >tmp 2>err &&\n-\ttest_line_count = 7 tmp &&\n-\ttest_line_count = 1 err\n+\ttest_line_count_cmd --out = 7 --err = 1 git diff br1...main\n '\n \n test_expect_success 'diff with no merge bases' '\n----->8----\n\nHowever, going through all the trouble for a single application is not\nreally worth it.  I'm going to drop --err, remove --out option, too.\nSo, its prototype would be:\n\n\ttest_line_count_cmd <op> <val> [!] cmd [args...]\n\n> Notice that so many tests that you touched only care about 0 lines?\n> \n> Instead of this new helper, I think it would be a more useful\n> improvement if we check the emptyness in a more direct way, i.e.\n> \n> >  test_expect_success 'tag --contains <existent_tag>' '\n> > \tgit tag --contains \"v1.0\" >actual 2>actual.err &&\n> > \tgrep \"v1.0\" actual &&\n> > -\ttest_line_count = 0 actual.err\n> > +\ttest_must_be_empty actual.err\n> \n> I think this helper may be misnamed and test_file_is_empty would sit\n> better with test_dir_is_empty and test_file_not_empty that already\n> exist, though.\n\nThat would be an improvement, but it should be written in a different\nseries.\n\n> \n> By the way, my opinion would be quite different if example like this\n> one ...\n> \n> >  test_expect_success 'tag --no-contains <existent_tag>' '\n> > -\tgit tag --no-contains \"v1.0\" >actual 2>actual.err  &&\n> > -\ttest_line_count = 0 actual &&\n> > -\ttest_line_count = 0 actual.err\n> > +\ttest_line_count_cmd --out = 0 --err = 0 git tag --no-contains v1.0\n> >  '\n> \n> ... were the majority, but I do not think that is the case.  Most\n> tests that employ the new test_line_count_cmd in this patch still\n> create either actual or actual.err in the working tree anyway, so I\n> do not see much point in adding this new helper---it is hard to\n> explain to new test writers when to use it.\n\nI'm not sure if I get your opinion.  Did you mean you wouldn't take\nwhole helper? Or you meant you still wanted to see a new helper for\nchecking only stdout?  If it's the former, I'll send a different\nseries to only clean \"git ls-files ... | wc -l\" in t6400 and t6402,\nif it's the latter, I'll rewrite without --err.\n\n-- \nDanh\n"},{"id":"427644","messageId":"xmqqpmwlny1p.fsf@gitster.g","threadId":"55936","inReplyTo":"YMoJAnvigwexX5b5@danh.dev","subject":"Re: [PATCH v2 3/5] t0041: use test_line_count_cmd to check std{out,err}","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2021-06-17T00:18:42Z","receivedAt":"2021-06-17T00:18:45Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Đoàn Trần Công Danh  <congdanhqx@gmail.com> writes:\n\n>> By the way, my opinion would be quite different if example like this\n>> one ...\n>> \n>> >  test_expect_success 'tag --no-contains <existent_tag>' '\n>> > -\tgit tag --no-contains \"v1.0\" >actual 2>actual.err  &&\n>> > -\ttest_line_count = 0 actual &&\n>> > -\ttest_line_count = 0 actual.err\n>> > +\ttest_line_count_cmd --out = 0 --err = 0 git tag --no-contains v1.0\n>> >  '\n>> \n>> ... were the majority, but I do not think that is the case.  Most\n>> tests that employ the new test_line_count_cmd in this patch still\n>> create either actual or actual.err in the working tree anyway, so I\n>> do not see much point in adding this new helper---it is hard to\n>> explain to new test writers when to use it.\n>\n> I'm not sure if I get your opinion.  Did you mean you wouldn't take\n> whole helper? Or you meant you still wanted to see a new helper for\n> checking only stdout?  If it's the former, I'll send a different\n> series to only clean \"git ls-files ... | wc -l\" in t6400 and t6402,\n> if it's the latter, I'll rewrite without --err.\n\nI did not see much point in adding test_line_count_cmd with --out\nand/or --err options; the upside of having it was dubious after\nlooking at the users of it in the patch that we are discussing.\n\nI did not consider test_line_count_cmd that only works on the\nstandard output stream.  From the patch under discussion, it is not\nimmediately obvious how much such a simplified helper would help\nclean up the existing tests, so I have no opinion without seeing\nat least some sample uses.\n\n"},{"id":"427661","messageId":"60cad4db9200b_10448208fd@natae.notmuch","threadId":"55936","inReplyTo":"20210615172038.28917-2-congdanhqx@gmail.com","subject":"RE: [PATCH v2 1/5] test-lib-functions: introduce test_line_count_cmd","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2021-06-17T04:51:39Z","receivedAt":"2021-06-17T04:51:43Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"Đoàn Trần Công Danh wrote:\n> In Git project,\n\nIn _the_ Git project\n\n> we have multiple occasions that requires checking number\n\nmultiple instances that require checking the number\n\n> of lines of text in stdout and/or stderr of a command. One of such\n> example is t6400,\n\nOne of such examples\n\n> which checks number of files in various states.\n\nthat checks the number of files (see 'that' vs. 'which' [1]).\n\n> Some of those commands are Git command,\n\nare git commands,\n\n> and we would like to check their\n> exit status.  In some of those checks, we pipe the stdout of those\n> commands to \"wc -l\" to check for line count,\n\nfor a line count,\n\n> thus loosing the exit status.\n\nlosing\n\n> Introduce a helper function to check for number of lines in stdout and\n\nthe number of lines\n\n> stderr from those commands.\n> \n> This helper will create 2 temporary files in process,\n\nthe process\n\n> thus it may affect output of some checks.\n\nthe output\n\n> Signed-off-by: Đoàn Trần Công Danh <congdanhqx@gmail.com>\n> ---\n>  t/test-lib-functions.sh | 117 ++++++++++++++++++++++++++++++++++++++++\n>  1 file changed, 117 insertions(+)\n> \n> diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh\n> index f0448daa74..b3281409de 100644\n> --- a/t/test-lib-functions.sh\n> +++ b/t/test-lib-functions.sh\n> @@ -845,6 +845,123 @@ test_line_count () {\n>  \tfi\n>  }\n>  \n> +# test_line_count_cmd checks exit status,\n\nthe exit status\n\n> and the number of lines in\n\n> +# captured stdout and/or stderr of a command.\n\nthe captured stdout...\n\n> +#\n> +# Usage:\n> +#\n> +# test_line_count_cmd [--[out|err] <binop> <value>]... [--] [!] cmd [args...]\n> +#\n> +# Options:\n> +# --out <binop> <value>:\n> +# --err <binop> <value>:\n> +#\tRun sh's \"test <# of lines> <binop> <value>\" on # of lines in stdout\n> +#\t(for --out) or stderr (for --err)\n> +# !:\n> +#\tInstead of expecting \"cmd [args...]\" succeed, expect its failure.\n> +#\tNote, if command under testing is \"git\",\n\nthe command under...\n\n> test_must_fail should be used\n\n> +#\tinstead of \"!\".\n> +#\n> +# Example:\n> +#\ttest_line_count_cmd --out -ge 10 --err = 0 git tag --no-contains v1.0.0\n> +#\ttest_line_count_cmd --out -le 10 ! grep some-text a-file\n> +#\ttest_line_count_cmd --out = 0 test_must_fail git rev-parse --verify abcd1234\n> +#\n> +# NOTE:\n> +# * if \"--out\" is specified, a temporary file named test_line_count_cmd_.out\n> +#   will be created.\n> +# * if \"--err\" is specified, a temporary file named test_line_count_cmd_.err\n> +#   will be created.\n> +# Those temporary files will be created under $TRASH_DIRECTORY/.git/trash\n> +# if $TRASH_DIRECTORY/.git directory existed.\n\nif $TRASH_DIRECTORY/.git/ exists\n\n> +# Otherwise, they will be created in $TRASH_DIRECTORY.\n> +# Those temporary files will be cleant by test_when_finished\n\nwill be cleaned by ...\n\nCheers.\n\n[1] https://www.merriam-webster.com/words-at-play/when-to-use-that-and-which\n\n-- \nFelipe Contreras"},{"id":"427929","messageId":"20210619013035.26313-1-congdanhqx@gmail.com","threadId":"55936","inReplyTo":"20210615172038.28917-1-congdanhqx@gmail.com","subject":"[PATCH v3 0/4] t: new helper test_line_count_cmd","fromName":"Đoàn Trần Công Danh","fromEmail":"congdanhqx@gmail.com","sentAt":"2021-06-19T01:30:31Z","receivedAt":"2021-06-19T01:31:09Z","isPatch":true,"sender":{"key":"congdanhqx@gmail.com","avatar":"https://avatars.githubusercontent.com/u/42673067?v=4"},"body":"This is a series to clear false positive when applying Junio's suggestion to\nto a series written by Ævar [1].\n\nChange in v3 since v2:\n* --err was dropped entirely\n* --out is not an option anymore, <binops> and <value> is the first two\n  arguments that fed into test_line_count_cmd\n\nChange in v2 since v1:\n* Documentation for test_line_count_cmd has been written in more detail\n  with examples\n* The outfile and errfile will be created only if --out and/or --err was\n  specified for better \"-v\"\n* outfile and errfile will be created in $TRASH_DIRECTORY/.git/trash\n  iff $TRASH_DIRECTORY/.git is a directory, otherwise $TRASH_DIRECTORY,\n  avoid \"git rev-parse --git-dir\" because we may want to test it, too.\n* Use test_when_finished to clean those files instead of manual \"rm -f\",\n  also for better \"-v\"\n* Merge multiple instance of \"$@\" run into one, for better auditing\n* t0041 is also converted to use new helper\n* With the change to location of outfile and errfile,\n  output of \"git ls-files -o\" has been restored.\n* Fix double space before \"&&\" in the end of test command.\n\n1: https://lore.kernel.org/git/87r1j42ffz.fsf@evledraar.gmail.com/\n\n\nĐoàn Trần Công Danh (4):\n  test-lib-functions: introduce test_line_count_cmd\n  t6402: use find(1) builtin to filter instead of grep\n  t6400: use test_line_count_cmd to count # of lines in stdout\n  t6402: use test_line_count_cmd to count # of lines in stdout\n\n t/t6400-merge-df.sh     |  16 ++---\n t/t6402-merge-rename.sh | 132 +++++++++++++++++++---------------------\n t/test-lib-functions.sh |  80 ++++++++++++++++++++++++\n 3 files changed, 150 insertions(+), 78 deletions(-)\n\nRange-diff against v2:\n1:  a823312b19 < -:  ---------- test-lib-functions: introduce test_line_count_cmd\n-:  ---------- > 1:  255ba9b067 test-lib-functions: introduce test_line_count_cmd\n2:  6e8f2d4289 = 2:  38cd3f93a0 t6402: use find(1) builtin to filter instead of grep\n3:  33daa5ee2f < -:  ---------- t0041: use test_line_count_cmd to check std{out,err}\n4:  729ebb8f50 ! 3:  efb0905dd3 t6400: use test_line_count_cmd to count # of lines in stdout\n    @@ t/t6400-merge-df.sh: test_expect_success 'modify/delete + directory/file conflic\n      \n     -\ttest 5 -eq $(git ls-files -s | wc -l) &&\n     -\ttest 4 -eq $(git ls-files -u | wc -l) &&\n    -+\ttest_line_count_cmd --out = 5 git ls-files -s &&\n    -+\ttest_line_count_cmd --out = 4 git ls-files -u &&\n    ++\ttest_line_count_cmd = 5 git ls-files -s &&\n    ++\ttest_line_count_cmd = 4 git ls-files -u &&\n      \tif test \"$GIT_TEST_MERGE_ALGORITHM\" = ort\n      \tthen\n     -\t\ttest 0 -eq $(git ls-files -o | wc -l)\n    -+\t\ttest_line_count_cmd --out = 0 git ls-files -o\n    ++\t\ttest_line_count_cmd = 0 git ls-files -o\n      \telse\n     -\t\ttest 1 -eq $(git ls-files -o | wc -l)\n    -+\t\ttest_line_count_cmd --out = 1 git ls-files -o\n    ++\t\ttest_line_count_cmd = 1 git ls-files -o\n      \tfi &&\n      \n      \ttest_path_is_file letters/file &&\n    @@ t/t6400-merge-df.sh: test_expect_success 'modify/delete + directory/file conflic\n      \n     -\ttest 5 -eq $(git ls-files -s | wc -l) &&\n     -\ttest 4 -eq $(git ls-files -u | wc -l) &&\n    -+\ttest_line_count_cmd --out = 5 git ls-files -s &&\n    -+\ttest_line_count_cmd --out = 4 git ls-files -u &&\n    ++\ttest_line_count_cmd = 5 git ls-files -s &&\n    ++\ttest_line_count_cmd = 4 git ls-files -u &&\n      \tif test \"$GIT_TEST_MERGE_ALGORITHM\" = ort\n      \tthen\n     -\t\ttest 0 -eq $(git ls-files -o | wc -l)\n    -+\t\ttest_line_count_cmd --out = 0 git ls-files -o\n    ++\t\ttest_line_count_cmd = 0 git ls-files -o\n      \telse\n     -\t\ttest 1 -eq $(git ls-files -o | wc -l)\n    -+\t\ttest_line_count_cmd --out = 1 git ls-files -o\n    ++\t\ttest_line_count_cmd = 1 git ls-files -o\n      \tfi &&\n      \n      \ttest_path_is_file letters/file &&\n5:  1b450e4148 ! 4:  8fc0f3ffd2 t6402: use test_line_count_cmd to count # of lines in stdout\n    @@ t/t6402-merge-rename.sh: test_expect_success 'pull renaming branch into unrenami\n     -\ttest_line_count = 3 b.stages &&\n     -\tgit ls-files -s N >n.stages &&\n     -\ttest_line_count = 1 n.stages &&\n    -+\ttest_line_count_cmd --out = 3 git ls-files -u B &&\n    -+\ttest_line_count_cmd --out = 1 git ls-files -s N &&\n    ++\ttest_line_count_cmd = 3 git ls-files -u B &&\n    ++\ttest_line_count_cmd = 1 git ls-files -s N &&\n      \tsed -ne \"/^g/{\n      \tp\n      \tq\n    @@ t/t6402-merge-rename.sh: test_expect_success 'pull renaming branch into another\n     -\ttest_line_count = 3 b.stages &&\n     -\tgit ls-files -s N >n.stages &&\n     -\ttest_line_count = 1 n.stages &&\n    -+\ttest_line_count_cmd --out = 3 git ls-files -u B &&\n    -+\ttest_line_count_cmd --out = 1 git ls-files -s N &&\n    ++\ttest_line_count_cmd = 3 git ls-files -u B &&\n    ++\ttest_line_count_cmd = 1 git ls-files -s N &&\n      \tsed -ne \"/^g/{\n      \tp\n      \tq\n    @@ t/t6402-merge-rename.sh: test_expect_success 'pull unrenaming branch into renami\n     -\ttest_line_count = 3 b.stages &&\n     -\tgit ls-files -s N >n.stages &&\n     -\ttest_line_count = 1 n.stages &&\n    -+\ttest_line_count_cmd --out = 3 git ls-files -u B &&\n    -+\ttest_line_count_cmd --out = 1 git ls-files -s N &&\n    ++\ttest_line_count_cmd = 3 git ls-files -u B &&\n    ++\ttest_line_count_cmd = 1 git ls-files -s N &&\n      \tsed -ne \"/^g/{\n      \tp\n      \tq\n    @@ t/t6402-merge-rename.sh: test_expect_success 'pull conflicting renames' \\\n     -\ttest_line_count = 1 c.stages &&\n     -\tgit ls-files -s N >n.stages &&\n     -\ttest_line_count = 1 n.stages &&\n    -+\ttest_line_count_cmd --out = 1 git ls-files -u A &&\n    -+\ttest_line_count_cmd --out = 1 git ls-files -u B &&\n    -+\ttest_line_count_cmd --out = 1 git ls-files -u C &&\n    -+\ttest_line_count_cmd --out = 1 git ls-files -s N &&\n    ++\ttest_line_count_cmd = 1 git ls-files -u A &&\n    ++\ttest_line_count_cmd = 1 git ls-files -u B &&\n    ++\ttest_line_count_cmd = 1 git ls-files -u C &&\n    ++\ttest_line_count_cmd = 1 git ls-files -s N &&\n      \tsed -ne \"/^g/{\n      \tp\n      \tq\n    @@ t/t6402-merge-rename.sh: test_expect_success 'Rename+D/F conflict; renamed file\n      \n     -\ttest 3 -eq \"$(git ls-files -u | wc -l)\" &&\n     -\ttest 2 -eq \"$(git ls-files -u dir/file-in-the-way | wc -l)\" &&\n    -+\ttest_line_count_cmd --out = 3 git ls-files -u &&\n    -+\ttest_line_count_cmd --out = 2 git ls-files -u dir/file-in-the-way &&\n    ++\ttest_line_count_cmd = 3 git ls-files -u &&\n    ++\ttest_line_count_cmd = 2 git ls-files -u dir/file-in-the-way &&\n      \n      \ttest_must_fail git diff --quiet &&\n      \ttest_must_fail git diff --cached --quiet &&\n    @@ t/t6402-merge-rename.sh: test_expect_success 'Same as previous, but merged other\n      \n     -\ttest 3 -eq \"$(git ls-files -u | wc -l)\" &&\n     -\ttest 2 -eq \"$(git ls-files -u dir/file-in-the-way | wc -l)\" &&\n    -+\ttest_line_count_cmd --out = 3 git ls-files -u &&\n    -+\ttest_line_count_cmd --out = 2 git ls-files -u dir/file-in-the-way &&\n    ++\ttest_line_count_cmd = 3 git ls-files -u &&\n    ++\ttest_line_count_cmd = 2 git ls-files -u dir/file-in-the-way &&\n      \n      \ttest_must_fail git diff --quiet &&\n      \ttest_must_fail git diff --cached --quiet &&\n    @@ t/t6402-merge-rename.sh: test_expect_success 'Rename+D/F conflict; renamed file\n      \n     -\ttest 3 -eq \"$(git ls-files -u | wc -l)\" &&\n     -\ttest 3 -eq \"$(git ls-files -u dir | wc -l)\" &&\n    -+\ttest_line_count_cmd --out = 3 git ls-files -u &&\n    -+\ttest_line_count_cmd --out = 3 git ls-files -u dir &&\n    ++\ttest_line_count_cmd = 3 git ls-files -u &&\n    ++\ttest_line_count_cmd = 3 git ls-files -u dir &&\n      \n      \ttest_must_fail git diff --quiet &&\n      \ttest_must_fail git diff --cached --quiet &&\n    @@ t/t6402-merge-rename.sh: test_expect_success 'Rename+D/F conflict; renamed file\n      \ttest_must_fail git merge --strategy=recursive dir-in-way &&\n      \n     -\ttest 5 -eq \"$(git ls-files -u | wc -l)\" &&\n    -+\ttest_line_count_cmd --out = 5 git ls-files -u &&\n    ++\ttest_line_count_cmd = 5 git ls-files -u &&\n      \tif test \"$GIT_TEST_MERGE_ALGORITHM\" = ort\n      \tthen\n     -\t\ttest 3 -eq \"$(git ls-files -u dir~HEAD | wc -l)\"\n    -+\t\ttest_line_count_cmd --out = 3 git ls-files -u dir~HEAD\n    ++\t\ttest_line_count_cmd = 3 git ls-files -u dir~HEAD\n      \telse\n     -\t\ttest 3 -eq \"$(git ls-files -u dir | grep -v file-in-the-way | wc -l)\"\n     +\t\tgit ls-files -u dir >out &&\n    -+\t\ttest_line_count_cmd --out = 3 grep -v file-in-the-way out\n    ++\t\ttest_line_count_cmd = 3 grep -v file-in-the-way out\n      \tfi &&\n     -\ttest 2 -eq \"$(git ls-files -u dir/file-in-the-way | wc -l)\" &&\n    -+\ttest_line_count_cmd --out = 2 git ls-files -u dir/file-in-the-way &&\n    ++\ttest_line_count_cmd = 2 git ls-files -u dir/file-in-the-way &&\n      \n      \ttest_must_fail git diff --quiet &&\n      \ttest_must_fail git diff --cached --quiet &&\n    @@ t/t6402-merge-rename.sh: test_expect_success 'Same as previous, but merged other\n      \ttest_must_fail git merge --strategy=recursive renamed-file-has-conflicts &&\n      \n     -\ttest 5 -eq \"$(git ls-files -u | wc -l)\" &&\n    -+\ttest_line_count_cmd --out = 5 git ls-files -u &&\n    ++\ttest_line_count_cmd = 5 git ls-files -u &&\n      \tif test \"$GIT_TEST_MERGE_ALGORITHM\" = ort\n      \tthen\n     -\t\ttest 3 -eq \"$(git ls-files -u dir~renamed-file-has-conflicts | wc -l)\"\n    -+\t\ttest_line_count_cmd --out = 3 git ls-files -u dir~renamed-file-has-conflicts\n    ++\t\ttest_line_count_cmd = 3 git ls-files -u dir~renamed-file-has-conflicts\n      \telse\n     -\t\ttest 3 -eq \"$(git ls-files -u dir | grep -v file-in-the-way | wc -l)\"\n     +\t\tgit ls-files -u dir >out &&\n    -+\t\ttest_line_count_cmd --out = 3 grep -v file-in-the-way out\n    ++\t\ttest_line_count_cmd = 3 grep -v file-in-the-way out\n      \tfi &&\n     -\ttest 2 -eq \"$(git ls-files -u dir/file-in-the-way | wc -l)\" &&\n    -+\ttest_line_count_cmd --out = 2 git ls-files -u dir/file-in-the-way &&\n    ++\ttest_line_count_cmd = 2 git ls-files -u dir/file-in-the-way &&\n      \n      \ttest_must_fail git diff --quiet &&\n      \ttest_must_fail git diff --cached --quiet &&\n    @@ t/t6402-merge-rename.sh: test_expect_success 'both rename source and destination\n      \tif test \"$GIT_TEST_MERGE_ALGORITHM\" = ort\n      \tthen\n     -\t\ttest 2 -eq \"$(git ls-files -u | wc -l)\"\n    -+\t\ttest_line_count_cmd --out = 2 git ls-files -u\n    ++\t\ttest_line_count_cmd = 2 git ls-files -u\n      \telse\n     -\t\ttest 1 -eq \"$(git ls-files -u | wc -l)\"\n    -+\t\ttest_line_count_cmd --out = 1 git ls-files -u\n    ++\t\ttest_line_count_cmd = 1 git ls-files -u\n      \tfi &&\n      \n      \ttest_must_fail git diff --quiet &&\n    @@ t/t6402-merge-rename.sh: then\n     -\t\ttest 4 -eq \"$(git ls-files -u | wc -l)\" &&\n     -\t\ttest 2 -eq \"$(git ls-files -u one | wc -l)\" &&\n     -\t\ttest 2 -eq \"$(git ls-files -u two | wc -l)\" &&\n    -+\t\ttest_line_count_cmd --out = 4 git ls-files -u &&\n    -+\t\ttest_line_count_cmd --out = 2 git ls-files -u one &&\n    -+\t\ttest_line_count_cmd --out = 2 git ls-files -u two &&\n    ++\t\ttest_line_count_cmd = 4 git ls-files -u &&\n    ++\t\ttest_line_count_cmd = 2 git ls-files -u one &&\n    ++\t\ttest_line_count_cmd = 2 git ls-files -u two &&\n      \n      \t\ttest_must_fail git diff --quiet &&\n      \n    @@ t/t6402-merge-rename.sh: else\n     -\t\ttest 2 -eq \"$(git ls-files -u | wc -l)\" &&\n     -\t\ttest 1 -eq \"$(git ls-files -u one | wc -l)\" &&\n     -\t\ttest 1 -eq \"$(git ls-files -u two | wc -l)\" &&\n    -+\t\ttest_line_count_cmd --out = 2 git ls-files -u &&\n    -+\t\ttest_line_count_cmd --out = 1 git ls-files -u one &&\n    -+\t\ttest_line_count_cmd --out = 1 git ls-files -u two &&\n    ++\t\ttest_line_count_cmd = 2 git ls-files -u &&\n    ++\t\ttest_line_count_cmd = 1 git ls-files -u one &&\n    ++\t\ttest_line_count_cmd = 1 git ls-files -u two &&\n      \n      \t\ttest_must_fail git diff --quiet &&\n      \n    @@ t/t6402-merge-rename.sh: test_expect_success 'pair rename to parent of other (D/\n     -\t\ttest 4 -eq \"$(git ls-files -u | wc -l)\" &&\n     -\t\ttest 2 -eq \"$(git ls-files -u one | wc -l)\" &&\n     -\t\ttest 2 -eq \"$(git ls-files -u two | wc -l)\"\n    -+\t\ttest_line_count_cmd --out = 4 git ls-files -u &&\n    -+\t\ttest_line_count_cmd --out = 2 git ls-files -u one &&\n    -+\t\ttest_line_count_cmd --out = 2 git ls-files -u two\n    ++\t\ttest_line_count_cmd = 4 git ls-files -u &&\n    ++\t\ttest_line_count_cmd = 2 git ls-files -u one &&\n    ++\t\ttest_line_count_cmd = 2 git ls-files -u two\n      \telse\n     -\t\ttest 2 -eq \"$(git ls-files -u | wc -l)\" &&\n     -\t\ttest 1 -eq \"$(git ls-files -u one | wc -l)\" &&\n     -\t\ttest 1 -eq \"$(git ls-files -u two | wc -l)\"\n    -+\t\ttest_line_count_cmd --out = 2 git ls-files -u &&\n    -+\t\ttest_line_count_cmd --out = 1 git ls-files -u one &&\n    -+\t\ttest_line_count_cmd --out = 1 git ls-files -u two\n    ++\t\ttest_line_count_cmd = 2 git ls-files -u &&\n    ++\t\ttest_line_count_cmd = 1 git ls-files -u one &&\n    ++\t\ttest_line_count_cmd = 1 git ls-files -u two\n      \tfi &&\n      \n      \ttest_must_fail git diff --quiet &&\n    @@ t/t6402-merge-rename.sh: test_expect_success 'check handling of differently rena\n     -\t\ttest 1 -eq \"$(git ls-files -u two~second-rename | wc -l)\" &&\n     -\t\ttest 1 -eq \"$(git ls-files -u original | wc -l)\" &&\n     -\t\ttest 0 -eq \"$(git ls-files -o | wc -l)\"\n    -+\t\ttest_line_count_cmd --out = 5 git ls-files -s &&\n    -+\t\ttest_line_count_cmd --out = 3 git ls-files -u &&\n    -+\t\ttest_line_count_cmd --out = 1 git ls-files -u one~HEAD &&\n    -+\t\ttest_line_count_cmd --out = 1 git ls-files -u two~second-rename &&\n    -+\t\ttest_line_count_cmd --out = 1 git ls-files -u original &&\n    -+\t\ttest_line_count_cmd --out = 0 git ls-files -o\n    ++\t\ttest_line_count_cmd = 5 git ls-files -s &&\n    ++\t\ttest_line_count_cmd = 3 git ls-files -u &&\n    ++\t\ttest_line_count_cmd = 1 git ls-files -u one~HEAD &&\n    ++\t\ttest_line_count_cmd = 1 git ls-files -u two~second-rename &&\n    ++\t\ttest_line_count_cmd = 1 git ls-files -u original &&\n    ++\t\ttest_line_count_cmd = 0 git ls-files -o\n      \telse\n     -\t\ttest 5 -eq \"$(git ls-files -s | wc -l)\" &&\n     -\t\ttest 3 -eq \"$(git ls-files -u | wc -l)\" &&\n    @@ t/t6402-merge-rename.sh: test_expect_success 'check handling of differently rena\n     -\t\ttest 1 -eq \"$(git ls-files -u two | wc -l)\" &&\n     -\t\ttest 1 -eq \"$(git ls-files -u original | wc -l)\" &&\n     -\t\ttest 2 -eq \"$(git ls-files -o | wc -l)\"\n    -+\t\ttest_line_count_cmd --out = 5 git ls-files -s &&\n    -+\t\ttest_line_count_cmd --out = 3 git ls-files -u &&\n    -+\t\ttest_line_count_cmd --out = 1 git ls-files -u one &&\n    -+\t\ttest_line_count_cmd --out = 1 git ls-files -u two &&\n    -+\t\ttest_line_count_cmd --out = 1 git ls-files -u original &&\n    -+\t\ttest_line_count_cmd --out = 2 git ls-files -o\n    ++\t\ttest_line_count_cmd = 5 git ls-files -s &&\n    ++\t\ttest_line_count_cmd = 3 git ls-files -u &&\n    ++\t\ttest_line_count_cmd = 1 git ls-files -u one &&\n    ++\t\ttest_line_count_cmd = 1 git ls-files -u two &&\n    ++\t\ttest_line_count_cmd = 1 git ls-files -u original &&\n    ++\t\ttest_line_count_cmd = 2 git ls-files -o\n      \tfi &&\n      \n      \ttest_path_is_file one/file &&\n    @@ t/t6402-merge-rename.sh: test_expect_success 'check handling of differently rena\n     -\ttest 1 -eq \"$(git ls-files -u two | wc -l)\" &&\n     -\ttest 1 -eq \"$(git ls-files -u original | wc -l)\" &&\n     -\ttest 0 -eq \"$(git ls-files -o | wc -l)\" &&\n    -+\ttest_line_count_cmd --out = 3 git ls-files -u &&\n    -+\ttest_line_count_cmd --out = 1 git ls-files -u one &&\n    -+\ttest_line_count_cmd --out = 1 git ls-files -u two &&\n    -+\ttest_line_count_cmd --out = 1 git ls-files -u original &&\n    -+\ttest_line_count_cmd --out = 0 git ls-files -o &&\n    ++\ttest_line_count_cmd = 3 git ls-files -u &&\n    ++\ttest_line_count_cmd = 1 git ls-files -u one &&\n    ++\ttest_line_count_cmd = 1 git ls-files -u two &&\n    ++\ttest_line_count_cmd = 1 git ls-files -u original &&\n    ++\ttest_line_count_cmd = 0 git ls-files -o &&\n      \n      \ttest_path_is_file one &&\n      \ttest_path_is_file two &&\n    @@ t/t6402-merge-rename.sh: test_expect_success 'setup merge of rename + small chan\n      \n     -\ttest 1 -eq $(git ls-files -s | wc -l) &&\n     -\ttest 0 -eq $(git ls-files -o | wc -l) &&\n    -+\ttest_line_count_cmd --out = 1 git ls-files -s &&\n    -+\ttest_line_count_cmd --out = 0 git ls-files -o &&\n    ++\ttest_line_count_cmd = 1 git ls-files -s &&\n    ++\ttest_line_count_cmd = 0 git ls-files -o &&\n      \ttest $(git rev-parse HEAD:renamed_file) = $(git rev-parse HEAD~1:file)\n      '\n      \n-- \n2.32.0.278.gd42b80f139\n\n"},{"id":"427930","messageId":"20210619013035.26313-2-congdanhqx@gmail.com","threadId":"55936","inReplyTo":"20210615172038.28917-1-congdanhqx@gmail.com","subject":"[PATCH v3 1/4] test-lib-functions: introduce test_line_count_cmd","fromName":"Đoàn Trần Công Danh","fromEmail":"congdanhqx@gmail.com","sentAt":"2021-06-19T01:30:32Z","receivedAt":"2021-06-19T01:31:14Z","isPatch":true,"sender":{"key":"congdanhqx@gmail.com","avatar":"https://avatars.githubusercontent.com/u/42673067?v=4"},"body":"In the Git project, we have multiple instances that requires\nchecking number of lines of text in the stdout of a command.\nOne of such examples is t6400, that checks number of files\nin various states.\n\nSome of those commands are Git command, and we would like to check\ntheir exit status.  In some of those checks, we pipe the stdout of\nthose commands to \"wc -l\" to count the number lines, thus losing\nthe exit status.\n\nIntroduce a helper function to check for the number of lines in stdout\nfrom those commands.\n\nThis helper will create a temporary file in the process, thus it may\naffect the output of some checks.\n\nSigned-off-by: Đoàn Trần Công Danh <congdanhqx@gmail.com>\n---\n t/test-lib-functions.sh | 80 +++++++++++++++++++++++++++++++++++++++++\n 1 file changed, 80 insertions(+)\n\ndiff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh\nindex f0448daa74..e055a4f808 100644\n--- a/t/test-lib-functions.sh\n+++ b/t/test-lib-functions.sh\n@@ -845,6 +845,86 @@ test_line_count () {\n \tfi\n }\n \n+# test_line_count_cmd checks the exit status, and the number of lines in\n+# the captured stdout of a command.\n+#\n+# SYNOPSIS:\n+#\n+#\ttest_line_count_cmd <binop> <value> [!] cmd [args...]\n+#\n+# Expect succeed exit status when running\n+#\n+#\tcmd [args...]\n+#\n+# then, run sh's \"test <# of lines in stdout> <binop> <value>\"\n+#\n+# OPTIONS:\n+# !:\n+#\tInstead of expecting \"cmd [args...]\" succeed, expect its failure.\n+#\tNote, if the command under testing is \"git\",\n+#\ttest_must_fail should be used instead of \"!\".\n+#\n+# EXAMPLE:\n+#\ttest_line_count_cmd -ge 10 git tag --no-contains v1.0.0\n+#\ttest_line_count_cmd -le 10 ! grep some-text a-file\n+#\ttest_line_count_cmd = 0 test_must_fail git rev-parse --verify abcd1234\n+#\n+# NOTE:\n+# * a temporary file named test_line_count_cmd_.out will be created under\n+# $TRASH_DIRECTORY/.git/trash iff $TRASH_DIRECTORY/.git/ exists.\n+# Otherwise, created in $TRASH_DIRECTORY. This temporary file will be\n+# cleaned by test_when_finished\n+test_line_count_cmd () {\n+\t{\n+\t\tlocal outop outval outfile\n+\t\tlocal expect_failure actual_failure\n+\t\tlocal trashdir=\"$TRASH_DIRECTORY\"\n+\n+\t\tif test -d \"$TRASH_DIRECTORY/.git\"\n+\t\tthen\n+\t\t\ttrashdir=\"$TRASH_DIRECTORY/.git/trash\" &&\n+\t\t\tmkdir -p \"$trashdir\"\n+\t\tfi &&\n+\t\tif test $# -lt 3\n+\t\tthen\n+\t\t\tBUG \"missing <binary-ops> and <value>\"\n+\t\tfi &&\n+\t\toutop=\"$1\" &&\n+\t\toutval=\"$2\" &&\n+\t\tshift 2 &&\n+\t\toutfile=\"$trashdir/test_line_count_cmd_.out\" &&\n+\t\tif test \"x$1\" = \"x!\"\n+\t\tthen\n+\t\t\tshift &&\n+\t\t\texpect_failure=yes\n+\t\tfi &&\n+\t\tif test $# = 0\n+\t\tthen\n+\t\t\tBUG \"test_line_count_cmd: no command to be run\"\n+\t\telse\n+\t\t\ttest_when_finished \"rm -f '$outfile'\" &&\n+\t\t\texec 8>\"$outfile\"\n+\t\t\t# We need to redirect stderr to &9,\n+\t\t\t# and redirect this function's 9>&2\n+\t\t\t# in order to not messed with -x\n+\t\t\tif ! \"$@\" >&8 2>&9\n+\t\t\tthen\n+\t\t\t\tactual_failure=yes\n+\t\t\tfi\n+\t\tfi 8>&1 &&\n+\t\tcase \"$expect_failure,$actual_failure\" in\n+\t\tyes,)\n+\t\t\techo >&4 \"error: '$@' succeed!\" &&\n+\t\t\treturn 1\n+\t\t\t;;\n+\t\t,yes)\n+\t\t\techo >&4 \"error: '$@' run into failure!\" &&\n+\t\t\treturn 1\n+\t\tesac &&\n+\t\ttest_line_count \"$outop\" \"$outval\" \"$outfile\" >&4\n+\t} 9>&2 2>&4\n+}\n+\n test_file_size () {\n \ttest \"$#\" -ne 1 && BUG \"1 param\"\n \ttest-tool path-utils file-size \"$1\"\n-- \n2.32.0.278.gd42b80f139\n\n"},{"id":"427932","messageId":"20210619013035.26313-3-congdanhqx@gmail.com","threadId":"55936","inReplyTo":"20210615172038.28917-1-congdanhqx@gmail.com","subject":"[PATCH v3 2/4] t6402: use find(1) builtin to filter instead of grep","fromName":"Đoàn Trần Công Danh","fromEmail":"congdanhqx@gmail.com","sentAt":"2021-06-19T01:30:33Z","receivedAt":"2021-06-19T01:31:14Z","isPatch":true,"sender":{"key":"congdanhqx@gmail.com","avatar":"https://avatars.githubusercontent.com/u/42673067?v=4"},"body":"find(1) has a builtin (-prune) to filter its output, save a bit of time\nfor invoking grep(1).\n\nIn addition, in a later change, we will try to use test_line_count_cmd\nto count number of lines in stdout and/or stderr of a command, due to\nlimitation of current implementation, it can handle pipe.\n\nLet's replace grep(1)'s usage with find(1) builtin filter.\n\nSigned-off-by: Đoàn Trần Công Danh <congdanhqx@gmail.com>\n---\n t/t6402-merge-rename.sh | 6 +++---\n 1 file changed, 3 insertions(+), 3 deletions(-)\n\ndiff --git a/t/t6402-merge-rename.sh b/t/t6402-merge-rename.sh\nindex 425dad97d5..5d76cd6414 100755\n--- a/t/t6402-merge-rename.sh\n+++ b/t/t6402-merge-rename.sh\n@@ -546,7 +546,7 @@ then\n \n \t\ttest_must_fail git diff --quiet &&\n \n-\t\ttest 3 -eq $(find . | grep -v .git | wc -l) &&\n+\t\ttest 3 -eq $(find . -name .git -prune -o -print | wc -l) &&\n \n \t\ttest_path_is_file one &&\n \t\ttest_path_is_file two &&\n@@ -565,7 +565,7 @@ else\n \n \t\ttest_must_fail git diff --quiet &&\n \n-\t\ttest 4 -eq $(find . | grep -v .git | wc -l) &&\n+\t\ttest 4 -eq $(find . -name .git -prune -o -print | wc -l) &&\n \n \t\ttest_path_is_dir one &&\n \t\ttest_path_is_file one~rename-two &&\n@@ -593,7 +593,7 @@ test_expect_success 'pair rename to parent of other (D/F conflicts) w/ clean sta\n \n \ttest_must_fail git diff --quiet &&\n \n-\ttest 3 -eq $(find . | grep -v .git | wc -l) &&\n+\ttest 3 -eq $(find . -name .git -prune -o -print | wc -l) &&\n \n \ttest_path_is_file one &&\n \ttest_path_is_file two &&\n-- \n2.32.0.278.gd42b80f139\n\n"},{"id":"427931","messageId":"20210619013035.26313-4-congdanhqx@gmail.com","threadId":"55936","inReplyTo":"20210615172038.28917-1-congdanhqx@gmail.com","subject":"[PATCH v3 3/4] t6400: use test_line_count_cmd to count # of lines in stdout","fromName":"Đoàn Trần Công Danh","fromEmail":"congdanhqx@gmail.com","sentAt":"2021-06-19T01:30:34Z","receivedAt":"2021-06-19T01:31:17Z","isPatch":true,"sender":{"key":"congdanhqx@gmail.com","avatar":"https://avatars.githubusercontent.com/u/42673067?v=4"},"body":"Signed-off-by: Đoàn Trần Công Danh <congdanhqx@gmail.com>\n---\n t/t6400-merge-df.sh | 16 ++++++++--------\n 1 file changed, 8 insertions(+), 8 deletions(-)\n\ndiff --git a/t/t6400-merge-df.sh b/t/t6400-merge-df.sh\nindex 38700d29b5..e5e9e473fe 100755\n--- a/t/t6400-merge-df.sh\n+++ b/t/t6400-merge-df.sh\n@@ -82,13 +82,13 @@ test_expect_success 'modify/delete + directory/file conflict' '\n \tgit checkout delete^0 &&\n \ttest_must_fail git merge modify &&\n \n-\ttest 5 -eq $(git ls-files -s | wc -l) &&\n-\ttest 4 -eq $(git ls-files -u | wc -l) &&\n+\ttest_line_count_cmd = 5 git ls-files -s &&\n+\ttest_line_count_cmd = 4 git ls-files -u &&\n \tif test \"$GIT_TEST_MERGE_ALGORITHM\" = ort\n \tthen\n-\t\ttest 0 -eq $(git ls-files -o | wc -l)\n+\t\ttest_line_count_cmd = 0 git ls-files -o\n \telse\n-\t\ttest 1 -eq $(git ls-files -o | wc -l)\n+\t\ttest_line_count_cmd = 1 git ls-files -o\n \tfi &&\n \n \ttest_path_is_file letters/file &&\n@@ -103,13 +103,13 @@ test_expect_success 'modify/delete + directory/file conflict; other way' '\n \n \ttest_must_fail git merge delete &&\n \n-\ttest 5 -eq $(git ls-files -s | wc -l) &&\n-\ttest 4 -eq $(git ls-files -u | wc -l) &&\n+\ttest_line_count_cmd = 5 git ls-files -s &&\n+\ttest_line_count_cmd = 4 git ls-files -u &&\n \tif test \"$GIT_TEST_MERGE_ALGORITHM\" = ort\n \tthen\n-\t\ttest 0 -eq $(git ls-files -o | wc -l)\n+\t\ttest_line_count_cmd = 0 git ls-files -o\n \telse\n-\t\ttest 1 -eq $(git ls-files -o | wc -l)\n+\t\ttest_line_count_cmd = 1 git ls-files -o\n \tfi &&\n \n \ttest_path_is_file letters/file &&\n-- \n2.32.0.278.gd42b80f139\n\n"},{"id":"427933","messageId":"20210619013035.26313-5-congdanhqx@gmail.com","threadId":"55936","inReplyTo":"20210615172038.28917-1-congdanhqx@gmail.com","subject":"[PATCH v3 4/4] t6402: use test_line_count_cmd to count # of lines in stdout","fromName":"Đoàn Trần Công Danh","fromEmail":"congdanhqx@gmail.com","sentAt":"2021-06-19T01:30:35Z","receivedAt":"2021-06-19T01:31:20Z","isPatch":true,"sender":{"key":"congdanhqx@gmail.com","avatar":"https://avatars.githubusercontent.com/u/42673067?v=4"},"body":"Signed-off-by: Đoàn Trần Công Danh <congdanhqx@gmail.com>\n---\n t/t6402-merge-rename.sh | 126 +++++++++++++++++++---------------------\n 1 file changed, 59 insertions(+), 67 deletions(-)\n\ndiff --git a/t/t6402-merge-rename.sh b/t/t6402-merge-rename.sh\nindex 5d76cd6414..52bd35899e 100755\n--- a/t/t6402-merge-rename.sh\n+++ b/t/t6402-merge-rename.sh\n@@ -105,10 +105,8 @@ test_expect_success 'pull renaming branch into unrenaming one' \\\n \tgit show-branch &&\n \ttest_expect_code 1 git pull . white &&\n \tgit ls-files -s &&\n-\tgit ls-files -u B >b.stages &&\n-\ttest_line_count = 3 b.stages &&\n-\tgit ls-files -s N >n.stages &&\n-\ttest_line_count = 1 n.stages &&\n+\ttest_line_count_cmd = 3 git ls-files -u B &&\n+\ttest_line_count_cmd = 1 git ls-files -s N &&\n \tsed -ne \"/^g/{\n \tp\n \tq\n@@ -122,10 +120,8 @@ test_expect_success 'pull renaming branch into another renaming one' \\\n \tgit reset --hard &&\n \tgit checkout red &&\n \ttest_expect_code 1 git pull . white &&\n-\tgit ls-files -u B >b.stages &&\n-\ttest_line_count = 3 b.stages &&\n-\tgit ls-files -s N >n.stages &&\n-\ttest_line_count = 1 n.stages &&\n+\ttest_line_count_cmd = 3 git ls-files -u B &&\n+\ttest_line_count_cmd = 1 git ls-files -s N &&\n \tsed -ne \"/^g/{\n \tp\n \tq\n@@ -138,10 +134,8 @@ test_expect_success 'pull unrenaming branch into renaming one' \\\n \tgit reset --hard &&\n \tgit show-branch &&\n \ttest_expect_code 1 git pull . main &&\n-\tgit ls-files -u B >b.stages &&\n-\ttest_line_count = 3 b.stages &&\n-\tgit ls-files -s N >n.stages &&\n-\ttest_line_count = 1 n.stages &&\n+\ttest_line_count_cmd = 3 git ls-files -u B &&\n+\ttest_line_count_cmd = 1 git ls-files -s N &&\n \tsed -ne \"/^g/{\n \tp\n \tq\n@@ -154,14 +148,10 @@ test_expect_success 'pull conflicting renames' \\\n \tgit reset --hard &&\n \tgit show-branch &&\n \ttest_expect_code 1 git pull . blue &&\n-\tgit ls-files -u A >a.stages &&\n-\ttest_line_count = 1 a.stages &&\n-\tgit ls-files -u B >b.stages &&\n-\ttest_line_count = 1 b.stages &&\n-\tgit ls-files -u C >c.stages &&\n-\ttest_line_count = 1 c.stages &&\n-\tgit ls-files -s N >n.stages &&\n-\ttest_line_count = 1 n.stages &&\n+\ttest_line_count_cmd = 1 git ls-files -u A &&\n+\ttest_line_count_cmd = 1 git ls-files -u B &&\n+\ttest_line_count_cmd = 1 git ls-files -u C &&\n+\ttest_line_count_cmd = 1 git ls-files -s N &&\n \tsed -ne \"/^g/{\n \tp\n \tq\n@@ -330,8 +320,8 @@ test_expect_success 'Rename+D/F conflict; renamed file merges but dir in way' '\n \t\ttest_i18ngrep \"Adding as dir~HEAD instead\" output\n \tfi &&\n \n-\ttest 3 -eq \"$(git ls-files -u | wc -l)\" &&\n-\ttest 2 -eq \"$(git ls-files -u dir/file-in-the-way | wc -l)\" &&\n+\ttest_line_count_cmd = 3 git ls-files -u &&\n+\ttest_line_count_cmd = 2 git ls-files -u dir/file-in-the-way &&\n \n \ttest_must_fail git diff --quiet &&\n \ttest_must_fail git diff --cached --quiet &&\n@@ -357,8 +347,8 @@ test_expect_success 'Same as previous, but merged other way' '\n \t\ttest_i18ngrep \"Adding as dir~renamed-file-has-no-conflicts instead\" output\n \tfi &&\n \n-\ttest 3 -eq \"$(git ls-files -u | wc -l)\" &&\n-\ttest 2 -eq \"$(git ls-files -u dir/file-in-the-way | wc -l)\" &&\n+\ttest_line_count_cmd = 3 git ls-files -u &&\n+\ttest_line_count_cmd = 2 git ls-files -u dir/file-in-the-way &&\n \n \ttest_must_fail git diff --quiet &&\n \ttest_must_fail git diff --cached --quiet &&\n@@ -374,8 +364,8 @@ test_expect_success 'Rename+D/F conflict; renamed file cannot merge, dir not in\n \tgit checkout -q renamed-file-has-conflicts^0 &&\n \ttest_must_fail git merge --strategy=recursive dir-not-in-way &&\n \n-\ttest 3 -eq \"$(git ls-files -u | wc -l)\" &&\n-\ttest 3 -eq \"$(git ls-files -u dir | wc -l)\" &&\n+\ttest_line_count_cmd = 3 git ls-files -u &&\n+\ttest_line_count_cmd = 3 git ls-files -u dir &&\n \n \ttest_must_fail git diff --quiet &&\n \ttest_must_fail git diff --cached --quiet &&\n@@ -409,14 +399,15 @@ test_expect_success 'Rename+D/F conflict; renamed file cannot merge and dir in t\n \tgit checkout -q renamed-file-has-conflicts^0 &&\n \ttest_must_fail git merge --strategy=recursive dir-in-way &&\n \n-\ttest 5 -eq \"$(git ls-files -u | wc -l)\" &&\n+\ttest_line_count_cmd = 5 git ls-files -u &&\n \tif test \"$GIT_TEST_MERGE_ALGORITHM\" = ort\n \tthen\n-\t\ttest 3 -eq \"$(git ls-files -u dir~HEAD | wc -l)\"\n+\t\ttest_line_count_cmd = 3 git ls-files -u dir~HEAD\n \telse\n-\t\ttest 3 -eq \"$(git ls-files -u dir | grep -v file-in-the-way | wc -l)\"\n+\t\tgit ls-files -u dir >out &&\n+\t\ttest_line_count_cmd = 3 grep -v file-in-the-way out\n \tfi &&\n-\ttest 2 -eq \"$(git ls-files -u dir/file-in-the-way | wc -l)\" &&\n+\ttest_line_count_cmd = 2 git ls-files -u dir/file-in-the-way &&\n \n \ttest_must_fail git diff --quiet &&\n \ttest_must_fail git diff --cached --quiet &&\n@@ -432,14 +423,15 @@ test_expect_success 'Same as previous, but merged other way' '\n \tgit checkout -q dir-in-way^0 &&\n \ttest_must_fail git merge --strategy=recursive renamed-file-has-conflicts &&\n \n-\ttest 5 -eq \"$(git ls-files -u | wc -l)\" &&\n+\ttest_line_count_cmd = 5 git ls-files -u &&\n \tif test \"$GIT_TEST_MERGE_ALGORITHM\" = ort\n \tthen\n-\t\ttest 3 -eq \"$(git ls-files -u dir~renamed-file-has-conflicts | wc -l)\"\n+\t\ttest_line_count_cmd = 3 git ls-files -u dir~renamed-file-has-conflicts\n \telse\n-\t\ttest 3 -eq \"$(git ls-files -u dir | grep -v file-in-the-way | wc -l)\"\n+\t\tgit ls-files -u dir >out &&\n+\t\ttest_line_count_cmd = 3 grep -v file-in-the-way out\n \tfi &&\n-\ttest 2 -eq \"$(git ls-files -u dir/file-in-the-way | wc -l)\" &&\n+\ttest_line_count_cmd = 2 git ls-files -u dir/file-in-the-way &&\n \n \ttest_must_fail git diff --quiet &&\n \ttest_must_fail git diff --cached --quiet &&\n@@ -496,9 +488,9 @@ test_expect_success 'both rename source and destination involved in D/F conflict\n \n \tif test \"$GIT_TEST_MERGE_ALGORITHM\" = ort\n \tthen\n-\t\ttest 2 -eq \"$(git ls-files -u | wc -l)\"\n+\t\ttest_line_count_cmd = 2 git ls-files -u\n \telse\n-\t\ttest 1 -eq \"$(git ls-files -u | wc -l)\"\n+\t\ttest_line_count_cmd = 1 git ls-files -u\n \tfi &&\n \n \ttest_must_fail git diff --quiet &&\n@@ -540,9 +532,9 @@ then\n \t\tmkdir one &&\n \t\ttest_must_fail git merge --strategy=recursive rename-two &&\n \n-\t\ttest 4 -eq \"$(git ls-files -u | wc -l)\" &&\n-\t\ttest 2 -eq \"$(git ls-files -u one | wc -l)\" &&\n-\t\ttest 2 -eq \"$(git ls-files -u two | wc -l)\" &&\n+\t\ttest_line_count_cmd = 4 git ls-files -u &&\n+\t\ttest_line_count_cmd = 2 git ls-files -u one &&\n+\t\ttest_line_count_cmd = 2 git ls-files -u two &&\n \n \t\ttest_must_fail git diff --quiet &&\n \n@@ -559,9 +551,9 @@ else\n \t\tmkdir one &&\n \t\ttest_must_fail git merge --strategy=recursive rename-two &&\n \n-\t\ttest 2 -eq \"$(git ls-files -u | wc -l)\" &&\n-\t\ttest 1 -eq \"$(git ls-files -u one | wc -l)\" &&\n-\t\ttest 1 -eq \"$(git ls-files -u two | wc -l)\" &&\n+\t\ttest_line_count_cmd = 2 git ls-files -u &&\n+\t\ttest_line_count_cmd = 1 git ls-files -u one &&\n+\t\ttest_line_count_cmd = 1 git ls-files -u two &&\n \n \t\ttest_must_fail git diff --quiet &&\n \n@@ -582,13 +574,13 @@ test_expect_success 'pair rename to parent of other (D/F conflicts) w/ clean sta\n \n \tif test \"$GIT_TEST_MERGE_ALGORITHM\" = ort\n \tthen\n-\t\ttest 4 -eq \"$(git ls-files -u | wc -l)\" &&\n-\t\ttest 2 -eq \"$(git ls-files -u one | wc -l)\" &&\n-\t\ttest 2 -eq \"$(git ls-files -u two | wc -l)\"\n+\t\ttest_line_count_cmd = 4 git ls-files -u &&\n+\t\ttest_line_count_cmd = 2 git ls-files -u one &&\n+\t\ttest_line_count_cmd = 2 git ls-files -u two\n \telse\n-\t\ttest 2 -eq \"$(git ls-files -u | wc -l)\" &&\n-\t\ttest 1 -eq \"$(git ls-files -u one | wc -l)\" &&\n-\t\ttest 1 -eq \"$(git ls-files -u two | wc -l)\"\n+\t\ttest_line_count_cmd = 2 git ls-files -u &&\n+\t\ttest_line_count_cmd = 1 git ls-files -u one &&\n+\t\ttest_line_count_cmd = 1 git ls-files -u two\n \tfi &&\n \n \ttest_must_fail git diff --quiet &&\n@@ -631,19 +623,19 @@ test_expect_success 'check handling of differently renamed file with D/F conflic\n \n \tif test \"$GIT_TEST_MERGE_ALGORITHM\" = ort\n \tthen\n-\t\ttest 5 -eq \"$(git ls-files -s | wc -l)\" &&\n-\t\ttest 3 -eq \"$(git ls-files -u | wc -l)\" &&\n-\t\ttest 1 -eq \"$(git ls-files -u one~HEAD | wc -l)\" &&\n-\t\ttest 1 -eq \"$(git ls-files -u two~second-rename | wc -l)\" &&\n-\t\ttest 1 -eq \"$(git ls-files -u original | wc -l)\" &&\n-\t\ttest 0 -eq \"$(git ls-files -o | wc -l)\"\n+\t\ttest_line_count_cmd = 5 git ls-files -s &&\n+\t\ttest_line_count_cmd = 3 git ls-files -u &&\n+\t\ttest_line_count_cmd = 1 git ls-files -u one~HEAD &&\n+\t\ttest_line_count_cmd = 1 git ls-files -u two~second-rename &&\n+\t\ttest_line_count_cmd = 1 git ls-files -u original &&\n+\t\ttest_line_count_cmd = 0 git ls-files -o\n \telse\n-\t\ttest 5 -eq \"$(git ls-files -s | wc -l)\" &&\n-\t\ttest 3 -eq \"$(git ls-files -u | wc -l)\" &&\n-\t\ttest 1 -eq \"$(git ls-files -u one | wc -l)\" &&\n-\t\ttest 1 -eq \"$(git ls-files -u two | wc -l)\" &&\n-\t\ttest 1 -eq \"$(git ls-files -u original | wc -l)\" &&\n-\t\ttest 2 -eq \"$(git ls-files -o | wc -l)\"\n+\t\ttest_line_count_cmd = 5 git ls-files -s &&\n+\t\ttest_line_count_cmd = 3 git ls-files -u &&\n+\t\ttest_line_count_cmd = 1 git ls-files -u one &&\n+\t\ttest_line_count_cmd = 1 git ls-files -u two &&\n+\t\ttest_line_count_cmd = 1 git ls-files -u original &&\n+\t\ttest_line_count_cmd = 2 git ls-files -o\n \tfi &&\n \n \ttest_path_is_file one/file &&\n@@ -679,11 +671,11 @@ test_expect_success 'check handling of differently renamed file with D/F conflic\n \tgit checkout -q first-rename-redo^0 &&\n \ttest_must_fail git merge --strategy=recursive second-rename-redo &&\n \n-\ttest 3 -eq \"$(git ls-files -u | wc -l)\" &&\n-\ttest 1 -eq \"$(git ls-files -u one | wc -l)\" &&\n-\ttest 1 -eq \"$(git ls-files -u two | wc -l)\" &&\n-\ttest 1 -eq \"$(git ls-files -u original | wc -l)\" &&\n-\ttest 0 -eq \"$(git ls-files -o | wc -l)\" &&\n+\ttest_line_count_cmd = 3 git ls-files -u &&\n+\ttest_line_count_cmd = 1 git ls-files -u one &&\n+\ttest_line_count_cmd = 1 git ls-files -u two &&\n+\ttest_line_count_cmd = 1 git ls-files -u original &&\n+\ttest_line_count_cmd = 0 git ls-files -o &&\n \n \ttest_path_is_file one &&\n \ttest_path_is_file two &&\n@@ -861,8 +853,8 @@ test_expect_success 'setup merge of rename + small change' '\n test_expect_success 'merge rename + small change' '\n \tgit merge rename_branch &&\n \n-\ttest 1 -eq $(git ls-files -s | wc -l) &&\n-\ttest 0 -eq $(git ls-files -o | wc -l) &&\n+\ttest_line_count_cmd = 1 git ls-files -s &&\n+\ttest_line_count_cmd = 0 git ls-files -o &&\n \ttest $(git rev-parse HEAD:renamed_file) = $(git rev-parse HEAD~1:file)\n '\n \n-- \n2.32.0.278.gd42b80f139\n\n"},{"id":"427938","messageId":"CAPig+cR7tUXB4=j3fGHN07=tPJ-skGb_6M7SExTq5eAH7FSwOQ@mail.gmail.com","threadId":"55936","inReplyTo":"20210619013035.26313-1-congdanhqx@gmail.com","subject":"Re: [PATCH v3 0/4] t: new helper test_line_count_cmd","fromName":"Eric Sunshine","fromEmail":"sunshine@sunshineco.com","sentAt":"2021-06-19T05:50:29Z","receivedAt":"2021-06-19T05:50:45Z","isPatch":true,"sender":{"key":"sunshine@sunshineco.com","avatar":"https://avatars.githubusercontent.com/u/163641?v=4"},"body":"On Fri, Jun 18, 2021 at 9:31 PM Đoàn Trần Công Danh\n<congdanhqx@gmail.com> wrote:\n> Change in v3 since v2:\n> * --err was dropped entirely\n> * --out is not an option anymore, <binops> and <value> is the first two\n>   arguments that fed into test_line_count_cmd\n\nWhen I read the previous version of this series, I found that many of\nthe instances where test_line_count_cmd() were used became quite\nnoisy, to the point that it was difficult to see at-a-glance the\ncommand being tested. As an experiment, on top of your patch 1, I\ncrafted a patch which made `--out` and `--err` optional (defaulting to\n`--out`). That helped reduce the noise level a good deal, however, I\nstill found it too noisy. Consequently, I crafted a second patch which\nrenamed the function to test_output_count(), and only then did the\nnoise level drop sufficiently that the command being tested didn't\nentirely disappear into the background.\n\nSince you've dropped the `--out` and `--err` options entirely, I\nwonder if now would be a good time to shorten the function name, as\nwell, in order to further reduce the noise level. Since it now only\ntests stdout (and doesn't deal with stderr), a name even shorter than\nwhat I tried for the last version might be even better. So, for\ninstance, the name test_out_count() might not be too bad:\n\n    test_out_count = 0 git ls-files -o &&\n"},{"id":"427940","messageId":"xmqqfsxel6oo.fsf@gitster.g","threadId":"55936","inReplyTo":"CAPig+cR7tUXB4=j3fGHN07=tPJ-skGb_6M7SExTq5eAH7FSwOQ@mail.gmail.com","subject":"Re: [PATCH v3 0/4] t: new helper test_line_count_cmd","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2021-06-19T06:17:11Z","receivedAt":"2021-06-19T06:17:15Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Eric Sunshine <sunshine@sunshineco.com> writes:\n\n> Since you've dropped the `--out` and `--err` options entirely, I\n> wonder if now would be a good time to shorten the function name, as\n> well, in order to further reduce the noise level. Since it now only\n> tests stdout (and doesn't deal with stderr), a name even shorter than\n> what I tried for the last version might be even better. So, for\n> instance, the name test_out_count() might not be too bad:\n>\n>     test_out_count = 0 git ls-files -o &&\n\n\"Test out\" to me sound like trying something out and the part \"out\"\nin the name no longer hints it is about \"output\"; you may have\nshortened the name too much to be meaningful, I am afraid.\n\nIs the helper used to check with anything but equality?  Otherwise\nyou can lose \"= \" to make it shorter.\n\nHaving said all that, as an external interface, I wonder\n\n\ttest_line_count -e = 0 git-ls-files -o\n\nwould work better.  It usually takes <op> <num> <file>, but when\n$1 is a magic \"-e\", we shift it out and it becomes <op> <num> <cmd>...\n"},{"id":"427942","messageId":"CAPig+cQdDibt2K6jFKehaWyGdtb72pj7FQ9nGLJYEmqna3vf5w@mail.gmail.com","threadId":"55936","inReplyTo":"xmqqfsxel6oo.fsf@gitster.g","subject":"Re: [PATCH v3 0/4] t: new helper test_line_count_cmd","fromName":"Eric Sunshine","fromEmail":"sunshine@sunshineco.com","sentAt":"2021-06-19T06:26:01Z","receivedAt":"2021-06-19T06:26:17Z","isPatch":true,"sender":{"key":"sunshine@sunshineco.com","avatar":"https://avatars.githubusercontent.com/u/163641?v=4"},"body":"On Sat, Jun 19, 2021 at 2:17 AM Junio C Hamano <gitster@pobox.com> wrote:\n> Eric Sunshine <sunshine@sunshineco.com> writes:\n> > what I tried for the last version might be even better. So, for\n> > instance, the name test_out_count() might not be too bad:\n> >\n> >     test_out_count = 0 git ls-files -o &&\n>\n> \"Test out\" to me sound like trying something out and the part \"out\"\n> in the name no longer hints it is about \"output\"; you may have\n> shortened the name too much to be meaningful, I am afraid.\n>\n> Is the helper used to check with anything but equality?  Otherwise\n> you can lose \"= \" to make it shorter.\n>\n> Having said all that, as an external interface, I wonder\n>\n>         test_line_count -e = 0 git-ls-files -o\n>\n> would work better.  It usually takes <op> <num> <file>, but when\n> $1 is a magic \"-e\", we shift it out and it becomes <op> <num> <cmd>...\n\nIndeed, I have no problem seeing this as a new mode of\ntest_line_count() triggered by an option. In fact, I suggested exactly\nthat[1] when this idea first arose (except I named the option `-c`\nrather than `-e`, but the latter is fine). However, my suggestion was\npretty much shot down[2] (and I don't entirely disagree with [2],\nwhich is why I didn't pursue the idea in [1]).\n\n[1]: https://lore.kernel.org/git/CAPig+cS4tkXZLPDEWgEytzEOCR7oGrXyg1CZVKVPSXuJOifLjQ@mail.gmail.com/\n[2]: https://lore.kernel.org/git/xmqq5z0fxlgn.fsf@gitster.g/\n"},{"id":"427944","messageId":"xmqqy2b6jql2.fsf@gitster.g","threadId":"55936","inReplyTo":"CAPig+cQdDibt2K6jFKehaWyGdtb72pj7FQ9nGLJYEmqna3vf5w@mail.gmail.com","subject":"Re: [PATCH v3 0/4] t: new helper test_line_count_cmd","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2021-06-19T06:50:17Z","receivedAt":"2021-06-19T06:50:21Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Eric Sunshine <sunshine@sunshineco.com> writes:\n\n> Indeed, I have no problem seeing this as a new mode of\n> test_line_count() triggered by an option. In fact, I suggested exactly\n> that[1] when this idea first arose (except I named the option `-c`\n> rather than `-e`, but the latter is fine). However, my suggestion was\n> pretty much shot down[2] (and I don't entirely disagree with [2],\n> which is why I didn't pursue the idea in [1]).\n\n;-)  \n\nYeah, I still am skeptical that we'd gain much by hiding the\nredirection to >actual behind the helper, so as I said in response\nto the v2 series, I am fine without this new helper or an enhanced\ntest_line_count, but go with more use of test_must_be_empty etc.\n\n"},{"id":"428022","messageId":"d4082001-6c70-ae02-c448-e038923c840e@gmail.com","threadId":"55936","inReplyTo":"20210619013035.26313-3-congdanhqx@gmail.com","subject":"Re: [PATCH v3 2/4] t6402: use find(1) builtin to filter instead of grep","fromName":"Andrei Rybak","fromEmail":"rybak.a.v@gmail.com","sentAt":"2021-06-21T08:17:52Z","receivedAt":"2021-06-21T08:18:02Z","isPatch":true,"sender":{"key":"rybak.a.v@gmail.com","avatar":"https://avatars.githubusercontent.com/u/624072?v=4"},"body":"On 19/06/2021 03:30, Đoàn Trần Công Danh wrote:\n> find(1) has a builtin (-prune) to filter its output, save a bit of time\n> for invoking grep(1).\n> \n> In addition, in a later change, we will try to use test_line_count_cmd\n> to count number of lines in stdout and/or stderr of a command, due to\n\nLooking at [PATCH v3 1/4] of this series, mention of \"stderr\" here is no\nlonger relevant.\n\n> limitation of current implementation, it can handle pipe.\n\nSeems like a typo s/can/can't/ ?\n\n> Let's replace grep(1)'s usage with find(1) builtin filter.\n> \n> Signed-off-by: Đoàn Trần Công Danh <congdanhqx@gmail.com>\n> ---\n>   t/t6402-merge-rename.sh | 6 +++---\n>   1 file changed, 3 insertions(+), 3 deletions(-)\n> \n> diff --git a/t/t6402-merge-rename.sh b/t/t6402-merge-rename.sh\n> index 425dad97d5..5d76cd6414 100755\n> --- a/t/t6402-merge-rename.sh\n> +++ b/t/t6402-merge-rename.sh\n> @@ -546,7 +546,7 @@ then\n>   \n>   \t\ttest_must_fail git diff --quiet &&\n>   \n> -\t\ttest 3 -eq $(find . | grep -v .git | wc -l) &&\n> +\t\ttest 3 -eq $(find . -name .git -prune -o -print | wc -l) &&\n>   \n>   \t\ttest_path_is_file one &&\n>   \t\ttest_path_is_file two &&\n> @@ -565,7 +565,7 @@ else\n>   \n>   \t\ttest_must_fail git diff --quiet &&\n>   \n> -\t\ttest 4 -eq $(find . | grep -v .git | wc -l) &&\n> +\t\ttest 4 -eq $(find . -name .git -prune -o -print | wc -l) &&\n>   \n>   \t\ttest_path_is_dir one &&\n>   \t\ttest_path_is_file one~rename-two &&\n> @@ -593,7 +593,7 @@ test_expect_success 'pair rename to parent of other (D/F conflicts) w/ clean sta\n>   \n>   \ttest_must_fail git diff --quiet &&\n>   \n> -\ttest 3 -eq $(find . | grep -v .git | wc -l) &&\n> +\ttest 3 -eq $(find . -name .git -prune -o -print | wc -l) &&\n\nBecause in the original `grep` wasn't invoked with `-F` it means that\n\".git\" is a regex which would match any path which contains the word\n\"git\" in it, because \".\" matches any character, including the leading\nslash that `find` outputs.  Such narrowing of what we intend to filter\nout is a good change.\n\nThis semantic change in filtering doesn't affect tests in t6402, as the\ntest directory doesn't have paths with the word \"git\" except for the\n\".git\" directory.  It might be worth mentioning in the commit message.\n\n>   \n>   \ttest_path_is_file one &&\n>   \ttest_path_is_file two &&\n>\n"},{"id":"428024","messageId":"54bf7756-5578-4fe4-dbe5-f63b368c4d63@gmail.com","threadId":"55936","inReplyTo":"20210619013035.26313-2-congdanhqx@gmail.com","subject":"Re: [PATCH v3 1/4] test-lib-functions: introduce test_line_count_cmd","fromName":"Andrei Rybak","fromEmail":"rybak.a.v@gmail.com","sentAt":"2021-06-21T09:08:07Z","receivedAt":"2021-06-21T09:08:15Z","isPatch":true,"sender":{"key":"rybak.a.v@gmail.com","avatar":"https://avatars.githubusercontent.com/u/624072?v=4"},"body":"On 19/06/2021 03:30, Đoàn Trần Công Danh wrote:\n> In the Git project, we have multiple instances that requires\n\ns/requires/require/\n\n> checking number of lines of text in the stdout of a command.\n> One of such examples is t6400, that checks number of files\n> in various states.\n> \n> Some of those commands are Git command, and we would like to check\n> their exit status.  In some of those checks, we pipe the stdout of\n> those commands to \"wc -l\" to count the number lines, thus losing\n> the exit status.\n> \n> Introduce a helper function to check for the number of lines in stdout\n> from those commands.\n> \n> This helper will create a temporary file in the process, thus it may\n> affect the output of some checks.\n> \n> Signed-off-by: Đoàn Trần Công Danh <congdanhqx@gmail.com>\n> ---\n>   t/test-lib-functions.sh | 80 +++++++++++++++++++++++++++++++++++++++++\n>   1 file changed, 80 insertions(+)\n> \n> diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh\n> index f0448daa74..e055a4f808 100644\n> --- a/t/test-lib-functions.sh\n> +++ b/t/test-lib-functions.sh\n> @@ -845,6 +845,86 @@ test_line_count () {\n>   \tfi\n>   }\n>   \n> +# test_line_count_cmd checks the exit status, and the number of lines in\n> +# the captured stdout of a command.\n> +#\n> +# SYNOPSIS:\n> +#\n> +#\ttest_line_count_cmd <binop> <value> [!] cmd [args...]\n> +#\n> +# Expect succeed exit status when running\n> +#\n> +#\tcmd [args...]\n> +#\n> +# then, run sh's \"test <# of lines in stdout> <binop> <value>\"\n> +#\n> +# OPTIONS:\n> +# !:\n> +#\tInstead of expecting \"cmd [args...]\" succeed, expect its failure.\n> +#\tNote, if the command under testing is \"git\",\n> +#\ttest_must_fail should be used instead of \"!\".\n> +#\n> +# EXAMPLE:\n> +#\ttest_line_count_cmd -ge 10 git tag --no-contains v1.0.0\n> +#\ttest_line_count_cmd -le 10 ! grep some-text a-file\n> +#\ttest_line_count_cmd = 0 test_must_fail git rev-parse --verify abcd1234\n> +#\n> +# NOTE:\n> +# * a temporary file named test_line_count_cmd_.out will be created under\n> +# $TRASH_DIRECTORY/.git/trash iff $TRASH_DIRECTORY/.git/ exists.\n> +# Otherwise, created in $TRASH_DIRECTORY. This temporary file will be\n> +# cleaned by test_when_finished\n> +test_line_count_cmd () {\n> +\t{\n> +\t\tlocal outop outval outfile\n> +\t\tlocal expect_failure actual_failure\n> +\t\tlocal trashdir=\"$TRASH_DIRECTORY\"\n> +\n> +\t\tif test -d \"$TRASH_DIRECTORY/.git\"\n> +\t\tthen\n> +\t\t\ttrashdir=\"$TRASH_DIRECTORY/.git/trash\" &&\n> +\t\t\tmkdir -p \"$trashdir\"\n> +\t\tfi &&\n> +\t\tif test $# -lt 3\n> +\t\tthen\n> +\t\t\tBUG \"missing <binary-ops> and <value>\"\n\nNit: s/binary-ops/binop/ for consistency with documentation comment\nabove.  Also, technically the invocation of test_line_count_cmd could be\nmissing any of its required three parameters, including \"cmd\".  How\nabout something similar to the call to BUG in test_i18ngrep:\n\n\tBUG \"too few parameters to test_line_count_cmd\"\n\n?\n\n> +\t\tfi &&\n> +\t\toutop=\"$1\" &&\n> +\t\toutval=\"$2\" &&\n> +\t\tshift 2 &&\n> +\t\toutfile=\"$trashdir/test_line_count_cmd_.out\" &&\n> +\t\tif test \"x$1\" = \"x!\"\n> +\t\tthen\n> +\t\t\tshift &&\n> +\t\t\texpect_failure=yes\n> +\t\tfi &&\n> +\t\tif test $# = 0\n> +\t\tthen\n> +\t\t\tBUG \"test_line_count_cmd: no command to be run\"\n> +\t\telse\n> +\t\t\ttest_when_finished \"rm -f '$outfile'\" &&\n> +\t\t\texec 8>\"$outfile\"\n> +\t\t\t# We need to redirect stderr to &9,\n> +\t\t\t# and redirect this function's 9>&2\n> +\t\t\t# in order to not messed with -x\n> +\t\t\tif ! \"$@\" >&8 2>&9\n> +\t\t\tthen\n> +\t\t\t\tactual_failure=yes\n> +\t\t\tfi\n> +\t\tfi 8>&1 &&\n> +\t\tcase \"$expect_failure,$actual_failure\" in\n> +\t\tyes,)\n> +\t\t\techo >&4 \"error: '$@' succeed!\" &&\n\nIt seems that function error() could be used here and below instead of\n\"echo >&4\".\n\ns/succeed/succeeded/ --- it might be worth borrowing wording from\ntest_must_fail().  Something like:\n\n\terror \"test_line_count_cmd: command succeeded: '$@'\"\n\n> +\t\t\treturn 1\n> +\t\t\t;;\n> +\t\t,yes)\n> +\t\t\techo >&4 \"error: '$@' run into failure!\" &&\n> +\t\t\treturn 1\n> +\t\tesac &&\n\nMissing \";;\" in the last branch of `case`.\n\n> +\t\ttest_line_count \"$outop\" \"$outval\" \"$outfile\" >&4\n> +\t} 9>&2 2>&4\n> +}\n> +\n>   test_file_size () {\n>   \ttest \"$#\" -ne 1 && BUG \"1 param\"\n>   \ttest-tool path-utils file-size \"$1\"\n> \n\n"},{"id":"428144","messageId":"YNEmN0HmQbiCMuaU@danh.dev","threadId":"55936","inReplyTo":"xmqqy2b6jql2.fsf@gitster.g","subject":"Re: [PATCH v3 0/4] t: new helper test_line_count_cmd","fromName":"Đoàn Trần Công Danh","fromEmail":"congdanhqx@gmail.com","sentAt":"2021-06-21T23:52:23Z","receivedAt":"2021-06-21T23:52:30Z","isPatch":true,"sender":{"key":"congdanhqx@gmail.com","avatar":"https://avatars.githubusercontent.com/u/42673067?v=4"},"body":"On 2021-06-19 15:50:17+0900, Junio C Hamano <gitster@pobox.com> wrote:\n> Eric Sunshine <sunshine@sunshineco.com> writes:\n> \n> > Indeed, I have no problem seeing this as a new mode of\n> > test_line_count() triggered by an option. In fact, I suggested exactly\n> > that[1] when this idea first arose (except I named the option `-c`\n> > rather than `-e`, but the latter is fine). However, my suggestion was\n> > pretty much shot down[2] (and I don't entirely disagree with [2],\n> > which is why I didn't pursue the idea in [1]).\n> \n> ;-)  \n> \n> Yeah, I still am skeptical that we'd gain much by hiding the\n> redirection to >actual behind the helper, so as I said in response\n> to the v2 series, I am fine without this new helper or an enhanced\n> test_line_count, but go with more use of test_must_be_empty etc.\n\nI guess the overall feedback for this new helper is negative.\nI think the consensus here is a local helper in t640{0,2} for counting\nls-files?\n\n-- \nDanh\n"},{"id":"428145","messageId":"YNEms6638tIKnBDC@danh.dev","threadId":"55936","inReplyTo":"d4082001-6c70-ae02-c448-e038923c840e@gmail.com","subject":"Re: [PATCH v3 2/4] t6402: use find(1) builtin to filter instead of grep","fromName":"Đoàn Trần Công Danh","fromEmail":"congdanhqx@gmail.com","sentAt":"2021-06-21T23:54:27Z","receivedAt":"2021-06-21T23:54:32Z","isPatch":true,"sender":{"key":"congdanhqx@gmail.com","avatar":"https://avatars.githubusercontent.com/u/42673067?v=4"},"body":"On 2021-06-21 10:17:52+0200, Andrei Rybak <rybak.a.v@gmail.com> wrote:\n> On 19/06/2021 03:30, Đoàn Trần Công Danh wrote:\n> > find(1) has a builtin (-prune) to filter its output, save a bit of time\n> > for invoking grep(1).\n> > \n> > In addition, in a later change, we will try to use test_line_count_cmd\n> > to count number of lines in stdout and/or stderr of a command, due to\n> \n> Looking at [PATCH v3 1/4] of this series, mention of \"stderr\" here is no\n> longer relevant.\n\nYes, you're correct.\n\n> > limitation of current implementation, it can handle pipe.\n> \n> Seems like a typo s/can/can't/ ?\n\nThis is correct, too.\n\n> > Let's replace grep(1)'s usage with find(1) builtin filter.\n> > \n> > Signed-off-by: Đoàn Trần Công Danh <congdanhqx@gmail.com>\n> > ---\n> >   t/t6402-merge-rename.sh | 6 +++---\n> >   1 file changed, 3 insertions(+), 3 deletions(-)\n> > \n> > diff --git a/t/t6402-merge-rename.sh b/t/t6402-merge-rename.sh\n> > index 425dad97d5..5d76cd6414 100755\n> > --- a/t/t6402-merge-rename.sh\n> > +++ b/t/t6402-merge-rename.sh\n> > @@ -546,7 +546,7 @@ then\n> >   \t\ttest_must_fail git diff --quiet &&\n> > -\t\ttest 3 -eq $(find . | grep -v .git | wc -l) &&\n> > +\t\ttest 3 -eq $(find . -name .git -prune -o -print | wc -l) &&\n> >   \t\ttest_path_is_file one &&\n> >   \t\ttest_path_is_file two &&\n> > @@ -565,7 +565,7 @@ else\n> >   \t\ttest_must_fail git diff --quiet &&\n> > -\t\ttest 4 -eq $(find . | grep -v .git | wc -l) &&\n> > +\t\ttest 4 -eq $(find . -name .git -prune -o -print | wc -l) &&\n> >   \t\ttest_path_is_dir one &&\n> >   \t\ttest_path_is_file one~rename-two &&\n> > @@ -593,7 +593,7 @@ test_expect_success 'pair rename to parent of other (D/F conflicts) w/ clean sta\n> >   \ttest_must_fail git diff --quiet &&\n> > -\ttest 3 -eq $(find . | grep -v .git | wc -l) &&\n> > +\ttest 3 -eq $(find . -name .git -prune -o -print | wc -l) &&\n> \n> Because in the original `grep` wasn't invoked with `-F` it means that\n> \".git\" is a regex which would match any path which contains the word\n> \"git\" in it, because \".\" matches any character, including the leading\n> slash that `find` outputs.  Such narrowing of what we intend to filter\n> out is a good change.\n\nI think the original intention is using \"grep -F\". I'll add that\ninformation into the commit message.\n\n> This semantic change in filtering doesn't affect tests in t6402, as the\n> test directory doesn't have paths with the word \"git\" except for the\n> \".git\" directory.  It might be worth mentioning in the commit message.\n\nThanks.\n\n-- \nDanh\n"},{"id":"428155","messageId":"CAPig+cSmzCJB3LUwFT0YC4uMJ20nysPue7rUAutyvKVB4uyMbg@mail.gmail.com","threadId":"55936","inReplyTo":"YNEmN0HmQbiCMuaU@danh.dev","subject":"Re: [PATCH v3 0/4] t: new helper test_line_count_cmd","fromName":"Eric Sunshine","fromEmail":"sunshine@sunshineco.com","sentAt":"2021-06-22T00:43:22Z","receivedAt":"2021-06-22T00:43:36Z","isPatch":true,"sender":{"key":"sunshine@sunshineco.com","avatar":"https://avatars.githubusercontent.com/u/163641?v=4"},"body":"On Mon, Jun 21, 2021 at 7:52 PM Đoàn Trần Công Danh\n<congdanhqx@gmail.com> wrote:\n> On 2021-06-19 15:50:17+0900, Junio C Hamano <gitster@pobox.com> wrote:\n> > Eric Sunshine <sunshine@sunshineco.com> writes:\n> > > Indeed, I have no problem seeing this as a new mode of\n> > > test_line_count() triggered by an option. In fact, I suggested exactly\n> > > that[1] when this idea first arose (except I named the option `-c`\n> > > rather than `-e`, but the latter is fine). However, my suggestion was\n> > > pretty much shot down[2] (and I don't entirely disagree with [2],\n> > > which is why I didn't pursue the idea in [1]).\n> >\n> > Yeah, I still am skeptical that we'd gain much by hiding the\n> > redirection to >actual behind the helper, so as I said in response\n> > to the v2 series, I am fine without this new helper or an enhanced\n> > test_line_count, but go with more use of test_must_be_empty etc.\n>\n> I guess the overall feedback for this new helper is negative.\n> I think the consensus here is a local helper in t640{0,2} for counting\n> ls-files?\n\nA local specialized function makes sense to me.\n"},{"id":"428398","messageId":"6ad6ac5a-18ac-102e-29dc-3c0987de08e7@gmail.com","threadId":"55936","inReplyTo":"54bf7756-5578-4fe4-dbe5-f63b368c4d63@gmail.com","subject":"Re: [PATCH v3 1/4] test-lib-functions: introduce test_line_count_cmd","fromName":"Andrei Rybak","fromEmail":"rybak.a.v@gmail.com","sentAt":"2021-06-24T19:23:14Z","receivedAt":"2021-06-24T19:23:30Z","isPatch":true,"sender":{"key":"rybak.a.v@gmail.com","avatar":"https://avatars.githubusercontent.com/u/624072?v=4"},"body":"On 21/06/2021 11:08, Andrei Rybak wrote:\n> On 19/06/2021 03:30, Đoàn Trần Công Danh wrote:\n>> diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh\n>> index f0448daa74..e055a4f808 100644\n>> --- a/t/test-lib-functions.sh\n>> +++ b/t/test-lib-functions.sh\n>> @@ -845,6 +845,86 @@ test_line_count () {\n>>       fi\n>>   }\n>> +# test_line_count_cmd checks the exit status, and the number of lines in\n>> +# the captured stdout of a command.\n>> +#\n>> +# SYNOPSIS:\n>> +#\n>> +#    test_line_count_cmd <binop> <value> [!] cmd [args...]\n>> +#\n>> +# Expect succeed exit status when running\n>> +#\n>> +#    cmd [args...]\n>> +#\n>> +# then, run sh's \"test <# of lines in stdout> <binop> <value>\"\n>> +#\n>> +# OPTIONS:\n>> +# !:\n>> +#    Instead of expecting \"cmd [args...]\" succeed, expect its failure.\n>> +#    Note, if the command under testing is \"git\",\n>> +#    test_must_fail should be used instead of \"!\".\n>> +#\n>> +# EXAMPLE:\n>> +#    test_line_count_cmd -ge 10 git tag --no-contains v1.0.0\n>> +#    test_line_count_cmd -le 10 ! grep some-text a-file\n>> +#    test_line_count_cmd = 0 test_must_fail git rev-parse --verify \n>> abcd1234\n>> +#\n>> +# NOTE:\n>> +# * a temporary file named test_line_count_cmd_.out will be created \n>> under\n>> +# $TRASH_DIRECTORY/.git/trash iff $TRASH_DIRECTORY/.git/ exists.\n>> +# Otherwise, created in $TRASH_DIRECTORY. This temporary file will be\n>> +# cleaned by test_when_finished\n>> +test_line_count_cmd () {\n>> +    {\n>> +        local outop outval outfile\n>> +        local expect_failure actual_failure\n>> +        local trashdir=\"$TRASH_DIRECTORY\"\n>> +\n>> +        if test -d \"$TRASH_DIRECTORY/.git\"\n>> +        then\n>> +            trashdir=\"$TRASH_DIRECTORY/.git/trash\" &&\n>> +            mkdir -p \"$trashdir\"\n>> +        fi &&\n>> +        if test $# -lt 3\n>> +        then\n>> +            BUG \"missing <binary-ops> and <value>\"\n> \n> Nit: s/binary-ops/binop/ for consistency with documentation comment\n> above.  Also, technically the invocation of test_line_count_cmd could be\n> missing any of its required three parameters, including \"cmd\".  How\n> about something similar to the call to BUG in test_i18ngrep:\n> \n>      BUG \"too few parameters to test_line_count_cmd\"\n> \n> ?\n> \n>> +        fi &&\n>> +        outop=\"$1\" &&\n>> +        outval=\"$2\" &&\n>> +        shift 2 &&\n>> +        outfile=\"$trashdir/test_line_count_cmd_.out\" &&\n>> +        if test \"x$1\" = \"x!\"\n>> +        then\n>> +            shift &&\n>> +            expect_failure=yes\n>> +        fi &&\n>> +        if test $# = 0\n>> +        then\n>> +            BUG \"test_line_count_cmd: no command to be run\"\n>> +        else\n>> +            test_when_finished \"rm -f '$outfile'\" &&\n>> +            exec 8>\"$outfile\"\n>> +            # We need to redirect stderr to &9,\n>> +            # and redirect this function's 9>&2\n>> +            # in order to not messed with -x\n>> +            if ! \"$@\" >&8 2>&9\n>> +            then\n>> +                actual_failure=yes\n>> +            fi\n>> +        fi 8>&1 &&\n>> +        case \"$expect_failure,$actual_failure\" in\n>> +        yes,)\n>> +            echo >&4 \"error: '$@' succeed!\" &&\n> \n> It seems that function error() could be used here and below instead of\n> \"echo >&4\".\n\nAfter spending some time reading t/test-lib-functions.sh, now I don't\nthink that using error() is a good suggestion.  Closest relatives of\ntest_line_count_cmd -- test_line_count and test_must_be_empty -- both\njust use \"echo\".  Other usages of error() in t/test-lib.sh and\nt/test-lib-functions.sh suggest that error() is not meant to be used\nfor reporting test failure messages, but internal failures. For example:\n\n\terror \"You haven't built things yet, have you?\"\n\nand\n\n\terror \"Internal error: $stderr disappeared.\"\n\n> s/succeed/succeeded/ --- it might be worth borrowing wording from\n> test_must_fail().  Something like:\n> \n>      error \"test_line_count_cmd: command succeeded: '$@'\"\n"},{"id":"428749","messageId":"cover.1624974969.git.congdanhqx@gmail.com","threadId":"55936","inReplyTo":"20210615172038.28917-1-congdanhqx@gmail.com","subject":"[PATCH v4 0/2] t640{0,2}: preserve ls-files exit status code","fromName":"Đoàn Trần Công Danh","fromEmail":"congdanhqx@gmail.com","sentAt":"2021-06-29T13:57:42Z","receivedAt":"2021-06-29T13:57:56Z","isPatch":true,"sender":{"key":"congdanhqx@gmail.com","avatar":"https://avatars.githubusercontent.com/u/42673067?v=4"},"body":"This is a series to clear false positive when applying Junio's suggestion to\nto a series written by Ævar [1].\n\nNot that we have any conclusion on that suggestion, just to clear the way out.\n\nIn v4, I dropped the test_line_count_cmd completely.\nA local to t640{0,2} helper was written instead.\n\nHence, the changelog and range-diff for v2 and v3 is dropped.\n\n1: https://lore.kernel.org/git/87r1j42ffz.fsf@evledraar.gmail.com/\n\nĐoàn Trần Công Danh (2):\n  t6400: preserve git ls-files exit status code\n  t6402: preserve git exit status code\n\n t/t6400-merge-df.sh     |  30 ++++++---\n t/t6402-merge-rename.sh | 146 +++++++++++++++++++++-------------------\n 2 files changed, 100 insertions(+), 76 deletions(-)\n\n-- \n2.32.0.278.gd42b80f139\n\n"},{"id":"428750","messageId":"49104273b8b801fc61811347120c5f4c42a3700b.1624974969.git.congdanhqx@gmail.com","threadId":"55936","inReplyTo":"cover.1624974969.git.congdanhqx@gmail.com","subject":"[PATCH v4 1/2] t6400: preserve git ls-files exit status code","fromName":"Đoàn Trần Công Danh","fromEmail":"congdanhqx@gmail.com","sentAt":"2021-06-29T13:57:43Z","receivedAt":"2021-06-29T13:58:00Z","isPatch":true,"sender":{"key":"congdanhqx@gmail.com","avatar":"https://avatars.githubusercontent.com/u/42673067?v=4"},"body":"In t6400, we're checking number of files in the index and the working\ntree by piping the output of \"git ls-files\" to \"wc -l\", thus losing the\nexit status code of git.\n\nLet's write the output of \"git ls-files\" to a temporary file, in order\nto check exit status code of \"git ls-files\" properly.\n\nSigned-off-by: Đoàn Trần Công Danh <congdanhqx@gmail.com>\n---\n t/t6400-merge-df.sh | 30 ++++++++++++++++++++++--------\n 1 file changed, 22 insertions(+), 8 deletions(-)\n\ndiff --git a/t/t6400-merge-df.sh b/t/t6400-merge-df.sh\nindex 38700d29b5..c2888323c1 100755\n--- a/t/t6400-merge-df.sh\n+++ b/t/t6400-merge-df.sh\n@@ -9,6 +9,20 @@ export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME\n \n . ./test-lib.sh\n \n+check_ls_files_count() {\n+\tlocal ops val\n+\tif test \"$#\" -le 2\n+\tthen\n+\t\tBUG \"Expect 2 or more arguments\"\n+\tfi &&\n+\tops=\"$1\" &&\n+\tval=\"$2\" &&\n+\tshift 2 &&\n+\tmkdir -p .git/trash &&\n+\tgit ls-files \"$@\" >.git/trash/output &&\n+\ttest_line_count \"$ops\" \"$val\" .git/trash/output\n+}\n+\n test_expect_success 'prepare repository' '\n \techo Hello >init &&\n \tgit add init &&\n@@ -82,13 +96,13 @@ test_expect_success 'modify/delete + directory/file conflict' '\n \tgit checkout delete^0 &&\n \ttest_must_fail git merge modify &&\n \n-\ttest 5 -eq $(git ls-files -s | wc -l) &&\n-\ttest 4 -eq $(git ls-files -u | wc -l) &&\n+\tcheck_ls_files_count = 5 -s &&\n+\tcheck_ls_files_count = 4 -u &&\n \tif test \"$GIT_TEST_MERGE_ALGORITHM\" = ort\n \tthen\n-\t\ttest 0 -eq $(git ls-files -o | wc -l)\n+\t\tcheck_ls_files_count = 0 -o\n \telse\n-\t\ttest 1 -eq $(git ls-files -o | wc -l)\n+\t\tcheck_ls_files_count = 1 -o\n \tfi &&\n \n \ttest_path_is_file letters/file &&\n@@ -103,13 +117,13 @@ test_expect_success 'modify/delete + directory/file conflict; other way' '\n \n \ttest_must_fail git merge delete &&\n \n-\ttest 5 -eq $(git ls-files -s | wc -l) &&\n-\ttest 4 -eq $(git ls-files -u | wc -l) &&\n+\tcheck_ls_files_count = 5 -s &&\n+\tcheck_ls_files_count = 4 -u &&\n \tif test \"$GIT_TEST_MERGE_ALGORITHM\" = ort\n \tthen\n-\t\ttest 0 -eq $(git ls-files -o | wc -l)\n+\t\tcheck_ls_files_count = 0 -o\n \telse\n-\t\ttest 1 -eq $(git ls-files -o | wc -l)\n+\t\tcheck_ls_files_count = 1 -o\n \tfi &&\n \n \ttest_path_is_file letters/file &&\n-- \n2.32.0.278.gd42b80f139\n\n"},{"id":"428751","messageId":"6d3ebcb255769f22011c69936dbfea7b1d98dae1.1624974969.git.congdanhqx@gmail.com","threadId":"55936","inReplyTo":"cover.1624974969.git.congdanhqx@gmail.com","subject":"[PATCH v4 2/2] t6402: preserve git exit status code","fromName":"Đoàn Trần Công Danh","fromEmail":"congdanhqx@gmail.com","sentAt":"2021-06-29T13:57:44Z","receivedAt":"2021-06-29T13:58:06Z","isPatch":true,"sender":{"key":"congdanhqx@gmail.com","avatar":"https://avatars.githubusercontent.com/u/42673067?v=4"},"body":"In t6402, we're checking number of files in the index and the working\ntree by piping the output of \"git ls-files\" to \"wc -l\", thus losing the\nexit status code of git.\n\nLet's write the output of \"git ls-files\" to a temporary file, in order\nto check exit status code of \"git ls-files\" properly.\n\nWhile we're at it, also check exit status code of an invocation of\ngit-rev-parse, too.\n\nSigned-off-by: Đoàn Trần Công Danh <congdanhqx@gmail.com>\n---\n t/t6402-merge-rename.sh | 146 +++++++++++++++++++++-------------------\n 1 file changed, 78 insertions(+), 68 deletions(-)\n\ndiff --git a/t/t6402-merge-rename.sh b/t/t6402-merge-rename.sh\nindex 425dad97d5..fbfa8967b0 100755\n--- a/t/t6402-merge-rename.sh\n+++ b/t/t6402-merge-rename.sh\n@@ -11,6 +11,20 @@ modify () {\n \tmv \"$2.x\" \"$2\"\n }\n \n+check_ls_files_count() {\n+\tlocal ops val\n+\tif test \"$#\" -le 2\n+\tthen\n+\t\tBUG \"Expect 2 or more arguments\"\n+\tfi &&\n+\tops=\"$1\" &&\n+\tval=\"$2\" &&\n+\tshift 2 &&\n+\tmkdir -p .git/trash &&\n+\tgit ls-files \"$@\" >.git/trash/output &&\n+\ttest_line_count \"$ops\" \"$val\" .git/trash/output\n+}\n+\n test_expect_success 'setup' '\n \tcat >A <<-\\EOF &&\n \ta aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n@@ -105,10 +119,8 @@ test_expect_success 'pull renaming branch into unrenaming one' \\\n \tgit show-branch &&\n \ttest_expect_code 1 git pull . white &&\n \tgit ls-files -s &&\n-\tgit ls-files -u B >b.stages &&\n-\ttest_line_count = 3 b.stages &&\n-\tgit ls-files -s N >n.stages &&\n-\ttest_line_count = 1 n.stages &&\n+\tcheck_ls_files_count = 3 -u B &&\n+\tcheck_ls_files_count = 1 -s N &&\n \tsed -ne \"/^g/{\n \tp\n \tq\n@@ -122,10 +134,8 @@ test_expect_success 'pull renaming branch into another renaming one' \\\n \tgit reset --hard &&\n \tgit checkout red &&\n \ttest_expect_code 1 git pull . white &&\n-\tgit ls-files -u B >b.stages &&\n-\ttest_line_count = 3 b.stages &&\n-\tgit ls-files -s N >n.stages &&\n-\ttest_line_count = 1 n.stages &&\n+\tcheck_ls_files_count = 3 -u B &&\n+\tcheck_ls_files_count = 1 -s N &&\n \tsed -ne \"/^g/{\n \tp\n \tq\n@@ -138,10 +148,8 @@ test_expect_success 'pull unrenaming branch into renaming one' \\\n \tgit reset --hard &&\n \tgit show-branch &&\n \ttest_expect_code 1 git pull . main &&\n-\tgit ls-files -u B >b.stages &&\n-\ttest_line_count = 3 b.stages &&\n-\tgit ls-files -s N >n.stages &&\n-\ttest_line_count = 1 n.stages &&\n+\tcheck_ls_files_count = 3 -u B &&\n+\tcheck_ls_files_count = 1 -s N &&\n \tsed -ne \"/^g/{\n \tp\n \tq\n@@ -154,14 +162,10 @@ test_expect_success 'pull conflicting renames' \\\n \tgit reset --hard &&\n \tgit show-branch &&\n \ttest_expect_code 1 git pull . blue &&\n-\tgit ls-files -u A >a.stages &&\n-\ttest_line_count = 1 a.stages &&\n-\tgit ls-files -u B >b.stages &&\n-\ttest_line_count = 1 b.stages &&\n-\tgit ls-files -u C >c.stages &&\n-\ttest_line_count = 1 c.stages &&\n-\tgit ls-files -s N >n.stages &&\n-\ttest_line_count = 1 n.stages &&\n+\tcheck_ls_files_count = 1 -u A &&\n+\tcheck_ls_files_count = 1 -u B &&\n+\tcheck_ls_files_count = 1 -u C &&\n+\tcheck_ls_files_count = 1 -s N &&\n \tsed -ne \"/^g/{\n \tp\n \tq\n@@ -330,8 +334,8 @@ test_expect_success 'Rename+D/F conflict; renamed file merges but dir in way' '\n \t\ttest_i18ngrep \"Adding as dir~HEAD instead\" output\n \tfi &&\n \n-\ttest 3 -eq \"$(git ls-files -u | wc -l)\" &&\n-\ttest 2 -eq \"$(git ls-files -u dir/file-in-the-way | wc -l)\" &&\n+\tcheck_ls_files_count = 3 -u &&\n+\tcheck_ls_files_count = 2 -u dir/file-in-the-way &&\n \n \ttest_must_fail git diff --quiet &&\n \ttest_must_fail git diff --cached --quiet &&\n@@ -357,8 +361,8 @@ test_expect_success 'Same as previous, but merged other way' '\n \t\ttest_i18ngrep \"Adding as dir~renamed-file-has-no-conflicts instead\" output\n \tfi &&\n \n-\ttest 3 -eq \"$(git ls-files -u | wc -l)\" &&\n-\ttest 2 -eq \"$(git ls-files -u dir/file-in-the-way | wc -l)\" &&\n+\tcheck_ls_files_count = 3 -u &&\n+\tcheck_ls_files_count = 2 -u dir/file-in-the-way &&\n \n \ttest_must_fail git diff --quiet &&\n \ttest_must_fail git diff --cached --quiet &&\n@@ -374,8 +378,8 @@ test_expect_success 'Rename+D/F conflict; renamed file cannot merge, dir not in\n \tgit checkout -q renamed-file-has-conflicts^0 &&\n \ttest_must_fail git merge --strategy=recursive dir-not-in-way &&\n \n-\ttest 3 -eq \"$(git ls-files -u | wc -l)\" &&\n-\ttest 3 -eq \"$(git ls-files -u dir | wc -l)\" &&\n+\tcheck_ls_files_count = 3 -u &&\n+\tcheck_ls_files_count = 3 -u dir &&\n \n \ttest_must_fail git diff --quiet &&\n \ttest_must_fail git diff --cached --quiet &&\n@@ -409,14 +413,16 @@ test_expect_success 'Rename+D/F conflict; renamed file cannot merge and dir in t\n \tgit checkout -q renamed-file-has-conflicts^0 &&\n \ttest_must_fail git merge --strategy=recursive dir-in-way &&\n \n-\ttest 5 -eq \"$(git ls-files -u | wc -l)\" &&\n+\tcheck_ls_files_count = 5 -u &&\n \tif test \"$GIT_TEST_MERGE_ALGORITHM\" = ort\n \tthen\n-\t\ttest 3 -eq \"$(git ls-files -u dir~HEAD | wc -l)\"\n+\t\tcheck_ls_files_count = 3 -u dir~HEAD\n \telse\n-\t\ttest 3 -eq \"$(git ls-files -u dir | grep -v file-in-the-way | wc -l)\"\n+\t\tgit ls-files -u dir >out &&\n+\t\ttest 3 -eq $(grep -v file-in-the-way out | wc -l) &&\n+\t\trm -f out\n \tfi &&\n-\ttest 2 -eq \"$(git ls-files -u dir/file-in-the-way | wc -l)\" &&\n+\tcheck_ls_files_count = 2 -u dir/file-in-the-way &&\n \n \ttest_must_fail git diff --quiet &&\n \ttest_must_fail git diff --cached --quiet &&\n@@ -432,14 +438,16 @@ test_expect_success 'Same as previous, but merged other way' '\n \tgit checkout -q dir-in-way^0 &&\n \ttest_must_fail git merge --strategy=recursive renamed-file-has-conflicts &&\n \n-\ttest 5 -eq \"$(git ls-files -u | wc -l)\" &&\n+\tcheck_ls_files_count = 5 -u &&\n \tif test \"$GIT_TEST_MERGE_ALGORITHM\" = ort\n \tthen\n-\t\ttest 3 -eq \"$(git ls-files -u dir~renamed-file-has-conflicts | wc -l)\"\n+\t\tcheck_ls_files_count = 3 -u dir~renamed-file-has-conflicts\n \telse\n-\t\ttest 3 -eq \"$(git ls-files -u dir | grep -v file-in-the-way | wc -l)\"\n+\t\tgit ls-files -u dir >out &&\n+\t\ttest 3 -eq $(grep -v file-in-the-way out | wc -l) &&\n+\t\trm -f out\n \tfi &&\n-\ttest 2 -eq \"$(git ls-files -u dir/file-in-the-way | wc -l)\" &&\n+\tcheck_ls_files_count = 2 -u dir/file-in-the-way &&\n \n \ttest_must_fail git diff --quiet &&\n \ttest_must_fail git diff --cached --quiet &&\n@@ -496,9 +504,9 @@ test_expect_success 'both rename source and destination involved in D/F conflict\n \n \tif test \"$GIT_TEST_MERGE_ALGORITHM\" = ort\n \tthen\n-\t\ttest 2 -eq \"$(git ls-files -u | wc -l)\"\n+\t\tcheck_ls_files_count = 2 -u\n \telse\n-\t\ttest 1 -eq \"$(git ls-files -u | wc -l)\"\n+\t\tcheck_ls_files_count = 1 -u\n \tfi &&\n \n \ttest_must_fail git diff --quiet &&\n@@ -540,9 +548,9 @@ then\n \t\tmkdir one &&\n \t\ttest_must_fail git merge --strategy=recursive rename-two &&\n \n-\t\ttest 4 -eq \"$(git ls-files -u | wc -l)\" &&\n-\t\ttest 2 -eq \"$(git ls-files -u one | wc -l)\" &&\n-\t\ttest 2 -eq \"$(git ls-files -u two | wc -l)\" &&\n+\t\tcheck_ls_files_count = 4 -u &&\n+\t\tcheck_ls_files_count = 2 -u one &&\n+\t\tcheck_ls_files_count = 2 -u two &&\n \n \t\ttest_must_fail git diff --quiet &&\n \n@@ -559,9 +567,9 @@ else\n \t\tmkdir one &&\n \t\ttest_must_fail git merge --strategy=recursive rename-two &&\n \n-\t\ttest 2 -eq \"$(git ls-files -u | wc -l)\" &&\n-\t\ttest 1 -eq \"$(git ls-files -u one | wc -l)\" &&\n-\t\ttest 1 -eq \"$(git ls-files -u two | wc -l)\" &&\n+\t\tcheck_ls_files_count = 2 -u &&\n+\t\tcheck_ls_files_count = 1 -u one &&\n+\t\tcheck_ls_files_count = 1 -u two &&\n \n \t\ttest_must_fail git diff --quiet &&\n \n@@ -582,13 +590,13 @@ test_expect_success 'pair rename to parent of other (D/F conflicts) w/ clean sta\n \n \tif test \"$GIT_TEST_MERGE_ALGORITHM\" = ort\n \tthen\n-\t\ttest 4 -eq \"$(git ls-files -u | wc -l)\" &&\n-\t\ttest 2 -eq \"$(git ls-files -u one | wc -l)\" &&\n-\t\ttest 2 -eq \"$(git ls-files -u two | wc -l)\"\n+\t\tcheck_ls_files_count = 4 -u &&\n+\t\tcheck_ls_files_count = 2 -u one &&\n+\t\tcheck_ls_files_count = 2 -u two\n \telse\n-\t\ttest 2 -eq \"$(git ls-files -u | wc -l)\" &&\n-\t\ttest 1 -eq \"$(git ls-files -u one | wc -l)\" &&\n-\t\ttest 1 -eq \"$(git ls-files -u two | wc -l)\"\n+\t\tcheck_ls_files_count = 2 -u &&\n+\t\tcheck_ls_files_count = 1 -u one &&\n+\t\tcheck_ls_files_count = 1 -u two\n \tfi &&\n \n \ttest_must_fail git diff --quiet &&\n@@ -631,19 +639,19 @@ test_expect_success 'check handling of differently renamed file with D/F conflic\n \n \tif test \"$GIT_TEST_MERGE_ALGORITHM\" = ort\n \tthen\n-\t\ttest 5 -eq \"$(git ls-files -s | wc -l)\" &&\n-\t\ttest 3 -eq \"$(git ls-files -u | wc -l)\" &&\n-\t\ttest 1 -eq \"$(git ls-files -u one~HEAD | wc -l)\" &&\n-\t\ttest 1 -eq \"$(git ls-files -u two~second-rename | wc -l)\" &&\n-\t\ttest 1 -eq \"$(git ls-files -u original | wc -l)\" &&\n-\t\ttest 0 -eq \"$(git ls-files -o | wc -l)\"\n+\t\tcheck_ls_files_count = 5 -s &&\n+\t\tcheck_ls_files_count = 3 -u &&\n+\t\tcheck_ls_files_count = 1 -u one~HEAD &&\n+\t\tcheck_ls_files_count = 1 -u two~second-rename &&\n+\t\tcheck_ls_files_count = 1 -u original &&\n+\t\tcheck_ls_files_count = 0 -o\n \telse\n-\t\ttest 5 -eq \"$(git ls-files -s | wc -l)\" &&\n-\t\ttest 3 -eq \"$(git ls-files -u | wc -l)\" &&\n-\t\ttest 1 -eq \"$(git ls-files -u one | wc -l)\" &&\n-\t\ttest 1 -eq \"$(git ls-files -u two | wc -l)\" &&\n-\t\ttest 1 -eq \"$(git ls-files -u original | wc -l)\" &&\n-\t\ttest 2 -eq \"$(git ls-files -o | wc -l)\"\n+\t\tcheck_ls_files_count = 5 -s &&\n+\t\tcheck_ls_files_count = 3 -u &&\n+\t\tcheck_ls_files_count = 1 -u one &&\n+\t\tcheck_ls_files_count = 1 -u two &&\n+\t\tcheck_ls_files_count = 1 -u original &&\n+\t\tcheck_ls_files_count = 2 -o\n \tfi &&\n \n \ttest_path_is_file one/file &&\n@@ -679,11 +687,11 @@ test_expect_success 'check handling of differently renamed file with D/F conflic\n \tgit checkout -q first-rename-redo^0 &&\n \ttest_must_fail git merge --strategy=recursive second-rename-redo &&\n \n-\ttest 3 -eq \"$(git ls-files -u | wc -l)\" &&\n-\ttest 1 -eq \"$(git ls-files -u one | wc -l)\" &&\n-\ttest 1 -eq \"$(git ls-files -u two | wc -l)\" &&\n-\ttest 1 -eq \"$(git ls-files -u original | wc -l)\" &&\n-\ttest 0 -eq \"$(git ls-files -o | wc -l)\" &&\n+\tcheck_ls_files_count = 3 -u &&\n+\tcheck_ls_files_count = 1 -u one &&\n+\tcheck_ls_files_count = 1 -u two &&\n+\tcheck_ls_files_count = 1 -u original &&\n+\tcheck_ls_files_count = 0 -o &&\n \n \ttest_path_is_file one &&\n \ttest_path_is_file two &&\n@@ -861,9 +869,11 @@ test_expect_success 'setup merge of rename + small change' '\n test_expect_success 'merge rename + small change' '\n \tgit merge rename_branch &&\n \n-\ttest 1 -eq $(git ls-files -s | wc -l) &&\n-\ttest 0 -eq $(git ls-files -o | wc -l) &&\n-\ttest $(git rev-parse HEAD:renamed_file) = $(git rev-parse HEAD~1:file)\n+\tcheck_ls_files_count = 1 -s &&\n+\tcheck_ls_files_count = 0 -o &&\n+\tnewhash=$(git rev-parse HEAD:renamed_file) &&\n+\toldhash=$(git rev-parse HEAD~1:file) &&\n+\ttest $newhash = $oldhash\n '\n \n test_expect_success 'setup for use of extended merge markers' '\n-- \n2.32.0.278.gd42b80f139\n\n"},{"id":"428752","messageId":"CAPig+cSKOzebGRyoytUGORhq56P0rijYrKO6uu7q7fWnzwiQkw@mail.gmail.com","threadId":"55936","inReplyTo":"49104273b8b801fc61811347120c5f4c42a3700b.1624974969.git.congdanhqx@gmail.com","subject":"Re: [PATCH v4 1/2] t6400: preserve git ls-files exit status code","fromName":"Eric Sunshine","fromEmail":"sunshine@sunshineco.com","sentAt":"2021-06-29T14:11:20Z","receivedAt":"2021-06-29T14:11:37Z","isPatch":true,"sender":{"key":"sunshine@sunshineco.com","avatar":"https://avatars.githubusercontent.com/u/163641?v=4"},"body":"On Tue, Jun 29, 2021 at 9:57 AM Đoàn Trần Công Danh\n<congdanhqx@gmail.com> wrote:\n> In t6400, we're checking number of files in the index and the working\n> tree by piping the output of \"git ls-files\" to \"wc -l\", thus losing the\n> exit status code of git.\n>\n> Let's write the output of \"git ls-files\" to a temporary file, in order\n> to check exit status code of \"git ls-files\" properly.\n\nThanks, the simplicity of this version over the previous attempts is appealing.\n\nJust a few extremely minor style nits below; don't know if any of them\nare worth a re-roll.\n\n> Signed-off-by: Đoàn Trần Công Danh <congdanhqx@gmail.com>\n> ---\n> diff --git a/t/t6400-merge-df.sh b/t/t6400-merge-df.sh\n> @@ -9,6 +9,20 @@ export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME\n>\n>  . ./test-lib.sh\n>\n> +check_ls_files_count() {\n\nstyle: funcname () {\n\n> +       local ops val\n> +       if test \"$#\" -le 2\n\nI also &&-chain the `local` declaration:\n\n    local ops val &&\n    if test \"$#\" -le 2\n\nBy making it easy to see the `&&` upfront, when new code is inserted,\nthere is a better chance that the &&-chain will be kept intact:\n\n    local ops val &&\n    my new code &&\n    if test \"$#\" -le 2\n\n> +       then\n> +               BUG \"Expect 2 or more arguments\"\n> +       fi &&\n\nA quick grep of the tests indicates that they are consistent about\nusing lowercase for the first word in a BUG():\n\n    BUG \"expect 2 or more arguments\"\n\n> +       ops=\"$1\" &&\n> +       val=\"$2\" &&\n> +       shift 2 &&\n> +       mkdir -p .git/trash &&\n> +       git ls-files \"$@\" >.git/trash/output &&\n> +       test_line_count \"$ops\" \"$val\" .git/trash/output\n> +}\n"},{"id":"428775","messageId":"xmqqim1wwg4u.fsf@gitster.g","threadId":"55936","inReplyTo":"cover.1624974969.git.congdanhqx@gmail.com","subject":"Re: [PATCH v4 0/2] t640{0,2}: preserve ls-files exit status code","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2021-06-29T20:49:21Z","receivedAt":"2021-06-29T20:49:24Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Đoàn Trần Công Danh  <congdanhqx@gmail.com> writes:\n\n> This is a series to clear false positive when applying Junio's suggestion to\n> to a series written by Ævar [1].\n>\n> Not that we have any conclusion on that suggestion, just to clear the way out.\n\nI do not think the careless and loose pattern I suggested in the old\nthread has much value, so any change whose purpose is to reduce\nfalse positive from the pattern is not needed.\n\nBut if these two patches are genuine improvement for other reasons\n(like \"we avoid feeding output from 'git' into pipe\"), they are very\nmuch welcome.\n\nThanks.\n"},{"id":"428788","messageId":"xmqqk0mcuw0e.fsf@gitster.g","threadId":"55936","inReplyTo":"CAPig+cSKOzebGRyoytUGORhq56P0rijYrKO6uu7q7fWnzwiQkw@mail.gmail.com","subject":"Re: [PATCH v4 1/2] t6400: preserve git ls-files exit status code","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2021-06-29T22:49:21Z","receivedAt":"2021-06-29T22:49:30Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Eric Sunshine <sunshine@sunshineco.com> writes:\n\n>> +check_ls_files_count() {\n>\n> style: funcname () {\n> ...\n> I also &&-chain the `local` declaration:\n>\n>     local ops val &&\n>     if test \"$#\" -le 2\n> ...\n> A quick grep of the tests indicates that they are consistent about\n> using lowercase for the first word in a BUG():\n\nThanks for a pair of sharp eyes, Eric, in your review.\n\n> -\ttest 5 -eq $(git ls-files -s | wc -l) &&\n> -\ttest 4 -eq $(git ls-files -u | wc -l) &&\n> +\tcheck_ls_files_count = 5 -s &&\n> +\tcheck_ls_files_count = 4 -u &&\n\nI have one more comment on the main part of the patch.  It is easy\nto see that this conversion is correctly done in this particular\npatch from the way 5/4 and -s/u are reproduced from the preimage to\nthe postimage, but I doubt that readers in the future, who long have\nforgotten that the \"-s\" came from \"ls-files -s\", would find the new\nform easy to read and understand.\n\nDo we have the same helper duplicated across two test scripts?\n\nI wonder if it is worth adding a single copy that forces the callers\nto spell out the command name in test-lib.sh and make the above into\nsomething like\n\n\ttest_output_wc_l = 5 ls-files -s\n\nor even\n\n\ttest_output_wc_l = 5 git ls-files -s\n\nThat way, it is easier to see what command is being run (yes, I know\nyou have _ls_files_ in the middle of the name of the custom helper,\nbut the thing is that \"-s\" and \"_ls_files_\" in the middle of the\nhelper are so far apart that it is not immediately obvious what the\nargument \"-s\" is about), and by not having two identical copies, we\nhave less risk of them drifting apart.\n\nHmm?\n"},{"id":"428795","messageId":"CAPig+cRu9Sh7gKi37Hj9nj+A0zZvmrrJgaVZepsD0Y-618tmvw@mail.gmail.com","threadId":"55936","inReplyTo":"xmqqk0mcuw0e.fsf@gitster.g","subject":"Re: [PATCH v4 1/2] t6400: preserve git ls-files exit status code","fromName":"Eric Sunshine","fromEmail":"sunshine@sunshineco.com","sentAt":"2021-06-30T01:57:58Z","receivedAt":"2021-06-30T01:58:13Z","isPatch":true,"sender":{"key":"sunshine@sunshineco.com","avatar":"https://avatars.githubusercontent.com/u/163641?v=4"},"body":"On Tue, Jun 29, 2021 at 6:49 PM Junio C Hamano <gitster@pobox.com> wrote:\n> I wonder if it is worth adding a single copy that forces the callers\n> to spell out the command name in test-lib.sh and make the above into\n> something like\n>\n>         test_output_wc_l = 5 ls-files -s\n>\n> or even\n>\n>         test_output_wc_l = 5 git ls-files -s\n>\n> That way, it is easier to see what command is being run (yes, I know\n> you have _ls_files_ in the middle of the name of the custom helper,\n> but the thing is that \"-s\" and \"_ls_files_\" in the middle of the\n> helper are so far apart that it is not immediately obvious what the\n> argument \"-s\" is about), and by not having two identical copies, we\n> have less risk of them drifting apart.\n>\n> Hmm?\n\nI may be misunderstanding your suggestion, but isn't the proposed\ntest_output_wc_l() function the same as what Danh had originally\nimplemented several re-rolls back (though he named it\ntest_line_count_cmd())?\n"},{"id":"428803","messageId":"xmqqa6n8uipn.fsf@gitster.g","threadId":"55936","inReplyTo":"CAPig+cRu9Sh7gKi37Hj9nj+A0zZvmrrJgaVZepsD0Y-618tmvw@mail.gmail.com","subject":"Re: [PATCH v4 1/2] t6400: preserve git ls-files exit status code","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2021-06-30T03:36:36Z","receivedAt":"2021-06-30T03:36:46Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Eric Sunshine <sunshine@sunshineco.com> writes:\n\n> I may be misunderstanding your suggestion, but isn't the proposed\n> test_output_wc_l() function the same as what Danh had originally\n> implemented several re-rolls back (though he named it\n> test_line_count_cmd())?\n\nCould be, except that I recall we saw extra noises like --out/--err\nthat weren't used and contaminating the current working directory,\nwhich are gone from the latest iteration.  The simplification\ncompared to that iteration is quite welcome---it made the resulting\ncode that uses the helper easier to follow compared to the earlier\nattempts.  But this round simplifies it too much and the results got\nharder to follow by burying the command name in the helper and made\nit less obvious that the last part of the helper's parameters are\narguments given to ls-files, I would think.\n"},{"id":"428819","messageId":"YNxPEb4V3SIqGRl9@danh.dev","threadId":"55936","inReplyTo":"xmqqa6n8uipn.fsf@gitster.g","subject":"Re: [PATCH v4 1/2] t6400: preserve git ls-files exit status code","fromName":"Đoàn Trần Công Danh","fromEmail":"congdanhqx@gmail.com","sentAt":"2021-06-30T11:01:37Z","receivedAt":"2021-06-30T11:01:44Z","isPatch":true,"sender":{"key":"congdanhqx@gmail.com","avatar":"https://avatars.githubusercontent.com/u/42673067?v=4"},"body":"On 2021-06-29 20:36:36-0700, Junio C Hamano <gitster@pobox.com> wrote:\n> Eric Sunshine <sunshine@sunshineco.com> writes:\n> \n> > I may be misunderstanding your suggestion, but isn't the proposed\n> > test_output_wc_l() function the same as what Danh had originally\n> > implemented several re-rolls back (though he named it\n> > test_line_count_cmd())?\n> \n> Could be, except that I recall we saw extra noises like --out/--err\n> that weren't used and contaminating the current working directory,\n> which are gone from the latest iteration.\n\nYes, in v{1,2}, there's the extra noises of --out and --err,\nbut it's gone in v3.\n\nI guess you're thinking about the contamination of $PWD iff it's not\na git worktree. That could be simplified by BUG-ging if $PWD is not\na git worktree.\n\nMaybe, you're thinking about the extra noises to handle the failure run\nof command under check? That could be dropped, too.\n\nWould you mind looking at v3 1/4 again to see what is your opinion\nthere? I don't mind re-roll a same or simplified version of v3,\nwith s/test_line_count_cmd/test_output_wc_l/ if you see fit.\n\n> The simplification\n> compared to that iteration is quite welcome---it made the resulting\n> code that uses the helper easier to follow compared to the earlier\n> attempts.  But this round simplifies it too much and the results got\n> harder to follow by burying the command name in the helper and made\n> it less obvious that the last part of the helper's parameters are\n> arguments given to ls-files, I would think.\n\n-- \nDanh\n"},{"id":"428852","messageId":"xmqqzgv7t757.fsf@gitster.g","threadId":"55936","inReplyTo":"YNxPEb4V3SIqGRl9@danh.dev","subject":"Re: [PATCH v4 1/2] t6400: preserve git ls-files exit status code","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2021-06-30T20:44:04Z","receivedAt":"2021-06-30T20:44:08Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Đoàn Trần Công Danh  <congdanhqx@gmail.com> writes:\n\n>> Could be, except that I recall we saw extra noises like --out/--err\n>> that weren't used and contaminating the current working directory,\n>> which are gone from the latest iteration.\n>\n> Yes, in v{1,2}, there's the extra noises of --out and --err,\n> but it's gone in v3.\n>\n> I guess you're thinking about the contamination of $PWD iff it's not\n> a git worktree. That could be simplified by BUG-ging if $PWD is not\n> a git worktree.\n\nNo.  I am not thinking about that.  I do not think it is a big loss\nif the helper cannot be used in non-repository.\n\n> Maybe, you're thinking about the extra noises to handle the failure run\n> of command under check? That could be dropped, too.\n\nNo.  I am not thinking about that, either.\n\n> Would you mind looking at v3 1/4 again to see what is your opinion\n> there? I don't mind re-roll a same or simplified version of v3,\n> with s/test_line_count_cmd/test_output_wc_l/ if you see fit.\n\nLet's not go back that far.  This is taken from v4 (t/t6400) ...\n\n\tlocal ops val &&\n\tif test \"$#\" -le 2\n\tthen\n\t\tBUG \"Expect 2 or more arguments\"\n\tfi &&\n\tops=\"$1\" &&\n\tval=\"$2\" &&\n\tshift 2 &&\n\tmkdir -p .git/trash &&\n\t\"$@\" >.git/trash/output &&\n\ttest_line_count \"$ops\" \"$val\" .git/trash/output\n\n... except that it runs '\"$@\"' instead of 'git ls-files \"$@\"', so\nthat we could try running things other than ls-files, and that would\nbe mostly good enough.  We may want to be prepared for a caller who\nwants to use the helper from within a subdirectory by not hardcoding\n\".git/trash\", though.  Something along the lines of ...\n\n\tlocal ops val &&\n+\tlocal trashdir=$(git rev-parse --git-dir)/trash &&\n\tif test ...\n\t...\n-\tmkdir -p .git/trash &&\n-\t\"$@\" >\".git/trash/output\" &&\n-\ttest_line_count \"$ops\" \"$val\" .git/trash/output\n+\tmkdir -p \"$trashdir\" &&\n+\t\"$@\" >\"$trashdir/output\" &&\n+\ttest_line_count \"$ops\" \"$val\" \"$trashdir/output\"\n"},{"id":"429144","messageId":"cover.1625362488.git.congdanhqx@gmail.com","threadId":"55936","inReplyTo":"20210615172038.28917-1-congdanhqx@gmail.com","subject":"[PATCH v5 0/3] new test-libs-function: test_stdout_line_count","fromName":"Đoàn Trần Công Danh","fromEmail":"congdanhqx@gmail.com","sentAt":"2021-07-04T05:46:09Z","receivedAt":"2021-07-04T05:46:22Z","isPatch":true,"sender":{"key":"congdanhqx@gmail.com","avatar":"https://avatars.githubusercontent.com/u/42673067?v=4"},"body":"This series was started to clear false positive when applying\nJunio's suggestion to to a series written by Ævar [1].\n\nDespite, we don't have much interest in that direction.\nI think it's still an improvement with this series, namely,\nwe're able to always check Git's exit status code.\n\nA naive: \"git grep -l  'git.* | wc -l' t????-* |wc -l\" reveals\n38 other tests also have that pattern.\nThose tests could be cleaned up later on\n\nChange in v5:\n- restore (albeit with new name and simplified) test_stdout_line_count\n- trash files will be written in $(git rev-parse --git-dir)/trash\n\nIn v4, I dropped the test_line_count_cmd completely.\nA local to t640{0,2} helper was written instead.\n\nĐoàn Trần Công Danh (3):\n  test-lib-functions: introduce test_stdout_line_count\n  t6400: preserve git ls-files exit status code\n  t6402: preserve git exit status code\n\n t/t6400-merge-df.sh     |  16 ++---\n t/t6402-merge-rename.sh | 132 +++++++++++++++++++---------------------\n t/test-lib-functions.sh |  26 ++++++++\n 3 files changed, 98 insertions(+), 76 deletions(-)\n\nRange-diff against v4:\n1:  49104273b8 < -:  ---------- t6400: preserve git ls-files exit status code\n-:  ---------- > 1:  ab542ae9aa test-lib-functions: introduce test_stdout_line_count\n-:  ---------- > 2:  f7a06994cd t6400: preserve git ls-files exit status code\n2:  6d3ebcb255 ! 3:  f8ed19f858 t6402: preserve git exit status code\n    @@ Commit message\n         t6402: preserve git exit status code\n     \n         In t6402, we're checking number of files in the index and the working\n    -    tree by piping the output of \"git ls-files\" to \"wc -l\", thus losing the\n    +    tree by piping the output of Git's command to \"wc -l\", thus losing the\n         exit status code of git.\n     \n    -    Let's write the output of \"git ls-files\" to a temporary file, in order\n    -    to check exit status code of \"git ls-files\" properly.\n    -\n    -    While we're at it, also check exit status code of an invocation of\n    -    git-rev-parse, too.\n    +    Let's use the new helper test_stdout_line_count in order to preserve\n    +    Git's exit status code.\n     \n         Signed-off-by: Đoàn Trần Công Danh <congdanhqx@gmail.com>\n     \n      ## t/t6402-merge-rename.sh ##\n    -@@ t/t6402-merge-rename.sh: modify () {\n    - \tmv \"$2.x\" \"$2\"\n    - }\n    - \n    -+check_ls_files_count() {\n    -+\tlocal ops val\n    -+\tif test \"$#\" -le 2\n    -+\tthen\n    -+\t\tBUG \"Expect 2 or more arguments\"\n    -+\tfi &&\n    -+\tops=\"$1\" &&\n    -+\tval=\"$2\" &&\n    -+\tshift 2 &&\n    -+\tmkdir -p .git/trash &&\n    -+\tgit ls-files \"$@\" >.git/trash/output &&\n    -+\ttest_line_count \"$ops\" \"$val\" .git/trash/output\n    -+}\n    -+\n    - test_expect_success 'setup' '\n    - \tcat >A <<-\\EOF &&\n    - \ta aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n     @@ t/t6402-merge-rename.sh: test_expect_success 'pull renaming branch into unrenaming one' \\\n      \tgit show-branch &&\n      \ttest_expect_code 1 git pull . white &&\n    @@ t/t6402-merge-rename.sh: test_expect_success 'pull renaming branch into unrenami\n     -\ttest_line_count = 3 b.stages &&\n     -\tgit ls-files -s N >n.stages &&\n     -\ttest_line_count = 1 n.stages &&\n    -+\tcheck_ls_files_count = 3 -u B &&\n    -+\tcheck_ls_files_count = 1 -s N &&\n    ++\ttest_stdout_line_count = 3 git ls-files -u B &&\n    ++\ttest_stdout_line_count = 1 git ls-files -s N &&\n      \tsed -ne \"/^g/{\n      \tp\n      \tq\n    @@ t/t6402-merge-rename.sh: test_expect_success 'pull renaming branch into another\n     -\ttest_line_count = 3 b.stages &&\n     -\tgit ls-files -s N >n.stages &&\n     -\ttest_line_count = 1 n.stages &&\n    -+\tcheck_ls_files_count = 3 -u B &&\n    -+\tcheck_ls_files_count = 1 -s N &&\n    ++\ttest_stdout_line_count = 3 git ls-files -u B &&\n    ++\ttest_stdout_line_count = 1 git ls-files -s N &&\n      \tsed -ne \"/^g/{\n      \tp\n      \tq\n    @@ t/t6402-merge-rename.sh: test_expect_success 'pull unrenaming branch into renami\n     -\ttest_line_count = 3 b.stages &&\n     -\tgit ls-files -s N >n.stages &&\n     -\ttest_line_count = 1 n.stages &&\n    -+\tcheck_ls_files_count = 3 -u B &&\n    -+\tcheck_ls_files_count = 1 -s N &&\n    ++\ttest_stdout_line_count = 3 git ls-files -u B &&\n    ++\ttest_stdout_line_count = 1 git ls-files -s N &&\n      \tsed -ne \"/^g/{\n      \tp\n      \tq\n    @@ t/t6402-merge-rename.sh: test_expect_success 'pull conflicting renames' \\\n     -\ttest_line_count = 1 c.stages &&\n     -\tgit ls-files -s N >n.stages &&\n     -\ttest_line_count = 1 n.stages &&\n    -+\tcheck_ls_files_count = 1 -u A &&\n    -+\tcheck_ls_files_count = 1 -u B &&\n    -+\tcheck_ls_files_count = 1 -u C &&\n    -+\tcheck_ls_files_count = 1 -s N &&\n    ++\ttest_stdout_line_count = 1 git ls-files -u A &&\n    ++\ttest_stdout_line_count = 1 git ls-files -u B &&\n    ++\ttest_stdout_line_count = 1 git ls-files -u C &&\n    ++\ttest_stdout_line_count = 1 git ls-files -s N &&\n      \tsed -ne \"/^g/{\n      \tp\n      \tq\n    @@ t/t6402-merge-rename.sh: test_expect_success 'Rename+D/F conflict; renamed file\n      \n     -\ttest 3 -eq \"$(git ls-files -u | wc -l)\" &&\n     -\ttest 2 -eq \"$(git ls-files -u dir/file-in-the-way | wc -l)\" &&\n    -+\tcheck_ls_files_count = 3 -u &&\n    -+\tcheck_ls_files_count = 2 -u dir/file-in-the-way &&\n    ++\ttest_stdout_line_count = 3 git ls-files -u &&\n    ++\ttest_stdout_line_count = 2 git ls-files -u dir/file-in-the-way &&\n      \n      \ttest_must_fail git diff --quiet &&\n      \ttest_must_fail git diff --cached --quiet &&\n    @@ t/t6402-merge-rename.sh: test_expect_success 'Same as previous, but merged other\n      \n     -\ttest 3 -eq \"$(git ls-files -u | wc -l)\" &&\n     -\ttest 2 -eq \"$(git ls-files -u dir/file-in-the-way | wc -l)\" &&\n    -+\tcheck_ls_files_count = 3 -u &&\n    -+\tcheck_ls_files_count = 2 -u dir/file-in-the-way &&\n    ++\ttest_stdout_line_count = 3 git ls-files -u &&\n    ++\ttest_stdout_line_count = 2 git ls-files -u dir/file-in-the-way &&\n      \n      \ttest_must_fail git diff --quiet &&\n      \ttest_must_fail git diff --cached --quiet &&\n    @@ t/t6402-merge-rename.sh: test_expect_success 'Rename+D/F conflict; renamed file\n      \n     -\ttest 3 -eq \"$(git ls-files -u | wc -l)\" &&\n     -\ttest 3 -eq \"$(git ls-files -u dir | wc -l)\" &&\n    -+\tcheck_ls_files_count = 3 -u &&\n    -+\tcheck_ls_files_count = 3 -u dir &&\n    ++\ttest_stdout_line_count = 3 git ls-files -u &&\n    ++\ttest_stdout_line_count = 3 git ls-files -u dir &&\n      \n      \ttest_must_fail git diff --quiet &&\n      \ttest_must_fail git diff --cached --quiet &&\n    @@ t/t6402-merge-rename.sh: test_expect_success 'Rename+D/F conflict; renamed file\n      \ttest_must_fail git merge --strategy=recursive dir-in-way &&\n      \n     -\ttest 5 -eq \"$(git ls-files -u | wc -l)\" &&\n    -+\tcheck_ls_files_count = 5 -u &&\n    ++\ttest_stdout_line_count = 5 git ls-files -u &&\n      \tif test \"$GIT_TEST_MERGE_ALGORITHM\" = ort\n      \tthen\n     -\t\ttest 3 -eq \"$(git ls-files -u dir~HEAD | wc -l)\"\n    -+\t\tcheck_ls_files_count = 3 -u dir~HEAD\n    ++\t\ttest_stdout_line_count = 3 git ls-files -u dir~HEAD\n      \telse\n     -\t\ttest 3 -eq \"$(git ls-files -u dir | grep -v file-in-the-way | wc -l)\"\n     +\t\tgit ls-files -u dir >out &&\n    @@ t/t6402-merge-rename.sh: test_expect_success 'Rename+D/F conflict; renamed file\n     +\t\trm -f out\n      \tfi &&\n     -\ttest 2 -eq \"$(git ls-files -u dir/file-in-the-way | wc -l)\" &&\n    -+\tcheck_ls_files_count = 2 -u dir/file-in-the-way &&\n    ++\ttest_stdout_line_count = 2 git ls-files -u dir/file-in-the-way &&\n      \n      \ttest_must_fail git diff --quiet &&\n      \ttest_must_fail git diff --cached --quiet &&\n    @@ t/t6402-merge-rename.sh: test_expect_success 'Same as previous, but merged other\n      \ttest_must_fail git merge --strategy=recursive renamed-file-has-conflicts &&\n      \n     -\ttest 5 -eq \"$(git ls-files -u | wc -l)\" &&\n    -+\tcheck_ls_files_count = 5 -u &&\n    ++\ttest_stdout_line_count = 5 git ls-files -u &&\n      \tif test \"$GIT_TEST_MERGE_ALGORITHM\" = ort\n      \tthen\n     -\t\ttest 3 -eq \"$(git ls-files -u dir~renamed-file-has-conflicts | wc -l)\"\n    -+\t\tcheck_ls_files_count = 3 -u dir~renamed-file-has-conflicts\n    ++\t\ttest_stdout_line_count = 3 git ls-files -u dir~renamed-file-has-conflicts\n      \telse\n     -\t\ttest 3 -eq \"$(git ls-files -u dir | grep -v file-in-the-way | wc -l)\"\n     +\t\tgit ls-files -u dir >out &&\n    @@ t/t6402-merge-rename.sh: test_expect_success 'Same as previous, but merged other\n     +\t\trm -f out\n      \tfi &&\n     -\ttest 2 -eq \"$(git ls-files -u dir/file-in-the-way | wc -l)\" &&\n    -+\tcheck_ls_files_count = 2 -u dir/file-in-the-way &&\n    ++\ttest_stdout_line_count = 2 git ls-files -u dir/file-in-the-way &&\n      \n      \ttest_must_fail git diff --quiet &&\n      \ttest_must_fail git diff --cached --quiet &&\n    @@ t/t6402-merge-rename.sh: test_expect_success 'both rename source and destination\n      \tif test \"$GIT_TEST_MERGE_ALGORITHM\" = ort\n      \tthen\n     -\t\ttest 2 -eq \"$(git ls-files -u | wc -l)\"\n    -+\t\tcheck_ls_files_count = 2 -u\n    ++\t\ttest_stdout_line_count = 2 git ls-files -u\n      \telse\n     -\t\ttest 1 -eq \"$(git ls-files -u | wc -l)\"\n    -+\t\tcheck_ls_files_count = 1 -u\n    ++\t\ttest_stdout_line_count = 1 git ls-files -u\n      \tfi &&\n      \n      \ttest_must_fail git diff --quiet &&\n    @@ t/t6402-merge-rename.sh: then\n     -\t\ttest 4 -eq \"$(git ls-files -u | wc -l)\" &&\n     -\t\ttest 2 -eq \"$(git ls-files -u one | wc -l)\" &&\n     -\t\ttest 2 -eq \"$(git ls-files -u two | wc -l)\" &&\n    -+\t\tcheck_ls_files_count = 4 -u &&\n    -+\t\tcheck_ls_files_count = 2 -u one &&\n    -+\t\tcheck_ls_files_count = 2 -u two &&\n    ++\t\ttest_stdout_line_count = 4 git ls-files -u &&\n    ++\t\ttest_stdout_line_count = 2 git ls-files -u one &&\n    ++\t\ttest_stdout_line_count = 2 git ls-files -u two &&\n      \n      \t\ttest_must_fail git diff --quiet &&\n      \n    @@ t/t6402-merge-rename.sh: else\n     -\t\ttest 2 -eq \"$(git ls-files -u | wc -l)\" &&\n     -\t\ttest 1 -eq \"$(git ls-files -u one | wc -l)\" &&\n     -\t\ttest 1 -eq \"$(git ls-files -u two | wc -l)\" &&\n    -+\t\tcheck_ls_files_count = 2 -u &&\n    -+\t\tcheck_ls_files_count = 1 -u one &&\n    -+\t\tcheck_ls_files_count = 1 -u two &&\n    ++\t\ttest_stdout_line_count = 2 git ls-files -u &&\n    ++\t\ttest_stdout_line_count = 1 git ls-files -u one &&\n    ++\t\ttest_stdout_line_count = 1 git ls-files -u two &&\n      \n      \t\ttest_must_fail git diff --quiet &&\n      \n    @@ t/t6402-merge-rename.sh: test_expect_success 'pair rename to parent of other (D/\n     -\t\ttest 4 -eq \"$(git ls-files -u | wc -l)\" &&\n     -\t\ttest 2 -eq \"$(git ls-files -u one | wc -l)\" &&\n     -\t\ttest 2 -eq \"$(git ls-files -u two | wc -l)\"\n    -+\t\tcheck_ls_files_count = 4 -u &&\n    -+\t\tcheck_ls_files_count = 2 -u one &&\n    -+\t\tcheck_ls_files_count = 2 -u two\n    ++\t\ttest_stdout_line_count = 4 git ls-files -u &&\n    ++\t\ttest_stdout_line_count = 2 git ls-files -u one &&\n    ++\t\ttest_stdout_line_count = 2 git ls-files -u two\n      \telse\n     -\t\ttest 2 -eq \"$(git ls-files -u | wc -l)\" &&\n     -\t\ttest 1 -eq \"$(git ls-files -u one | wc -l)\" &&\n     -\t\ttest 1 -eq \"$(git ls-files -u two | wc -l)\"\n    -+\t\tcheck_ls_files_count = 2 -u &&\n    -+\t\tcheck_ls_files_count = 1 -u one &&\n    -+\t\tcheck_ls_files_count = 1 -u two\n    ++\t\ttest_stdout_line_count = 2 git ls-files -u &&\n    ++\t\ttest_stdout_line_count = 1 git ls-files -u one &&\n    ++\t\ttest_stdout_line_count = 1 git ls-files -u two\n      \tfi &&\n      \n      \ttest_must_fail git diff --quiet &&\n    @@ t/t6402-merge-rename.sh: test_expect_success 'check handling of differently rena\n     -\t\ttest 1 -eq \"$(git ls-files -u two~second-rename | wc -l)\" &&\n     -\t\ttest 1 -eq \"$(git ls-files -u original | wc -l)\" &&\n     -\t\ttest 0 -eq \"$(git ls-files -o | wc -l)\"\n    -+\t\tcheck_ls_files_count = 5 -s &&\n    -+\t\tcheck_ls_files_count = 3 -u &&\n    -+\t\tcheck_ls_files_count = 1 -u one~HEAD &&\n    -+\t\tcheck_ls_files_count = 1 -u two~second-rename &&\n    -+\t\tcheck_ls_files_count = 1 -u original &&\n    -+\t\tcheck_ls_files_count = 0 -o\n    ++\t\ttest_stdout_line_count = 5 git ls-files -s &&\n    ++\t\ttest_stdout_line_count = 3 git ls-files -u &&\n    ++\t\ttest_stdout_line_count = 1 git ls-files -u one~HEAD &&\n    ++\t\ttest_stdout_line_count = 1 git ls-files -u two~second-rename &&\n    ++\t\ttest_stdout_line_count = 1 git ls-files -u original &&\n    ++\t\ttest_stdout_line_count = 0 git ls-files -o\n      \telse\n     -\t\ttest 5 -eq \"$(git ls-files -s | wc -l)\" &&\n     -\t\ttest 3 -eq \"$(git ls-files -u | wc -l)\" &&\n    @@ t/t6402-merge-rename.sh: test_expect_success 'check handling of differently rena\n     -\t\ttest 1 -eq \"$(git ls-files -u two | wc -l)\" &&\n     -\t\ttest 1 -eq \"$(git ls-files -u original | wc -l)\" &&\n     -\t\ttest 2 -eq \"$(git ls-files -o | wc -l)\"\n    -+\t\tcheck_ls_files_count = 5 -s &&\n    -+\t\tcheck_ls_files_count = 3 -u &&\n    -+\t\tcheck_ls_files_count = 1 -u one &&\n    -+\t\tcheck_ls_files_count = 1 -u two &&\n    -+\t\tcheck_ls_files_count = 1 -u original &&\n    -+\t\tcheck_ls_files_count = 2 -o\n    ++\t\ttest_stdout_line_count = 5 git ls-files -s &&\n    ++\t\ttest_stdout_line_count = 3 git ls-files -u &&\n    ++\t\ttest_stdout_line_count = 1 git ls-files -u one &&\n    ++\t\ttest_stdout_line_count = 1 git ls-files -u two &&\n    ++\t\ttest_stdout_line_count = 1 git ls-files -u original &&\n    ++\t\ttest_stdout_line_count = 2 git ls-files -o\n      \tfi &&\n      \n      \ttest_path_is_file one/file &&\n    @@ t/t6402-merge-rename.sh: test_expect_success 'check handling of differently rena\n     -\ttest 1 -eq \"$(git ls-files -u two | wc -l)\" &&\n     -\ttest 1 -eq \"$(git ls-files -u original | wc -l)\" &&\n     -\ttest 0 -eq \"$(git ls-files -o | wc -l)\" &&\n    -+\tcheck_ls_files_count = 3 -u &&\n    -+\tcheck_ls_files_count = 1 -u one &&\n    -+\tcheck_ls_files_count = 1 -u two &&\n    -+\tcheck_ls_files_count = 1 -u original &&\n    -+\tcheck_ls_files_count = 0 -o &&\n    ++\ttest_stdout_line_count = 3 git ls-files -u &&\n    ++\ttest_stdout_line_count = 1 git ls-files -u one &&\n    ++\ttest_stdout_line_count = 1 git ls-files -u two &&\n    ++\ttest_stdout_line_count = 1 git ls-files -u original &&\n    ++\ttest_stdout_line_count = 0 git ls-files -o &&\n      \n      \ttest_path_is_file one &&\n      \ttest_path_is_file two &&\n    @@ t/t6402-merge-rename.sh: test_expect_success 'setup merge of rename + small chan\n     -\ttest 1 -eq $(git ls-files -s | wc -l) &&\n     -\ttest 0 -eq $(git ls-files -o | wc -l) &&\n     -\ttest $(git rev-parse HEAD:renamed_file) = $(git rev-parse HEAD~1:file)\n    -+\tcheck_ls_files_count = 1 -s &&\n    -+\tcheck_ls_files_count = 0 -o &&\n    ++\ttest_stdout_line_count = 1 git ls-files -s &&\n    ++\ttest_stdout_line_count = 0 git ls-files -o &&\n     +\tnewhash=$(git rev-parse HEAD:renamed_file) &&\n     +\toldhash=$(git rev-parse HEAD~1:file) &&\n     +\ttest $newhash = $oldhash\n-- \n2.32.0.278.gd42b80f139\n\n"},{"id":"429145","messageId":"ab542ae9aa35decd2bc55561c5ba8f5653fa07a2.1625362489.git.congdanhqx@gmail.com","threadId":"55936","inReplyTo":"cover.1625362488.git.congdanhqx@gmail.com","subject":"[PATCH v5 1/3] test-lib-functions: introduce test_stdout_line_count","fromName":"Đoàn Trần Công Danh","fromEmail":"congdanhqx@gmail.com","sentAt":"2021-07-04T05:46:10Z","receivedAt":"2021-07-04T05:46:27Z","isPatch":true,"sender":{"key":"congdanhqx@gmail.com","avatar":"https://avatars.githubusercontent.com/u/42673067?v=4"},"body":"In some tests, we're checking the number of lines in output of some\ncommands, including but not limited to Git's command.\n\nWe're doing the check by running those commands in the left side of\na pipe, thus losing the exit status code of those commands. Meanwhile,\nwe really want to check the exit status code of Git's command.\n\nLet's write the output of those commands to a temporary file, and use\ntest_line_count separately in order to check exit status code of\nthose commands properly.\n\nSigned-off-by: Đoàn Trần Công Danh <congdanhqx@gmail.com>\n---\n t/test-lib-functions.sh | 26 ++++++++++++++++++++++++++\n 1 file changed, 26 insertions(+)\n\ndiff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh\nindex f0448daa74..f9505be8fe 100644\n--- a/t/test-lib-functions.sh\n+++ b/t/test-lib-functions.sh\n@@ -845,6 +845,32 @@ test_line_count () {\n \tfi\n }\n \n+# SYNOPSIS:\n+# \ttest_stdout_line_count <bin-ops> <value> <cmd> [<args>...]\n+#\n+# test_stdout_line_count checks that the output of a command has the number\n+# of lines it ought to. For example:\n+# \n+# test_stdout_line_count = 3 git ls-files -u\n+# test_stdout_line_count -gt 10 ls\n+test_stdout_line_count () {\n+\tlocal ops val trashdir &&\n+\tif test \"$#\" -le 3\n+\tthen\n+\t\tBUG \"expect 3 or more arguments\"\n+\tfi &&\n+\tops=\"$1\" &&\n+\tval=\"$2\" &&\n+\tshift 2 &&\n+\tif ! trashdir=\"$(git rev-parse --git-dir)/trash\"; then\n+\t\tBUG \"expect to be run inside a worktree\"\n+\tfi &&\n+\tmkdir -p \"$trashdir\" &&\n+\t\"$@\" >\"$trashdir/output\" &&\n+\ttest_line_count \"$ops\" \"$val\" \"$trashdir/output\"\n+}\n+\n+\n test_file_size () {\n \ttest \"$#\" -ne 1 && BUG \"1 param\"\n \ttest-tool path-utils file-size \"$1\"\n-- \n2.32.0.278.gd42b80f139\n\n"},{"id":"429146","messageId":"f7a06994cd57d4a8c0f70a0d1e5f48f8ac2e2561.1625362489.git.congdanhqx@gmail.com","threadId":"55936","inReplyTo":"cover.1625362488.git.congdanhqx@gmail.com","subject":"[PATCH v5 2/3] t6400: preserve git ls-files exit status code","fromName":"Đoàn Trần Công Danh","fromEmail":"congdanhqx@gmail.com","sentAt":"2021-07-04T05:46:11Z","receivedAt":"2021-07-04T05:46:28Z","isPatch":true,"sender":{"key":"congdanhqx@gmail.com","avatar":"https://avatars.githubusercontent.com/u/42673067?v=4"},"body":"In t6400, we're checking number of files in the index and the working\ntree by piping the output of \"git ls-files\" to \"wc -l\", thus losing the\nexit status code of git.\n\nLet's use the newly introduced test_stdout_line_count in order to check\nthe exit status code of Git's command.\n\nSigned-off-by: Đoàn Trần Công Danh <congdanhqx@gmail.com>\n---\n t/t6400-merge-df.sh | 16 ++++++++--------\n 1 file changed, 8 insertions(+), 8 deletions(-)\n\ndiff --git a/t/t6400-merge-df.sh b/t/t6400-merge-df.sh\nindex 38700d29b5..57a67cf362 100755\n--- a/t/t6400-merge-df.sh\n+++ b/t/t6400-merge-df.sh\n@@ -82,13 +82,13 @@ test_expect_success 'modify/delete + directory/file conflict' '\n \tgit checkout delete^0 &&\n \ttest_must_fail git merge modify &&\n \n-\ttest 5 -eq $(git ls-files -s | wc -l) &&\n-\ttest 4 -eq $(git ls-files -u | wc -l) &&\n+\ttest_stdout_line_count = 5 git ls-files -s &&\n+\ttest_stdout_line_count = 4 git ls-files -u &&\n \tif test \"$GIT_TEST_MERGE_ALGORITHM\" = ort\n \tthen\n-\t\ttest 0 -eq $(git ls-files -o | wc -l)\n+\t\ttest_stdout_line_count = 0 git ls-files -o\n \telse\n-\t\ttest 1 -eq $(git ls-files -o | wc -l)\n+\t\ttest_stdout_line_count = 1 git ls-files -o\n \tfi &&\n \n \ttest_path_is_file letters/file &&\n@@ -103,13 +103,13 @@ test_expect_success 'modify/delete + directory/file conflict; other way' '\n \n \ttest_must_fail git merge delete &&\n \n-\ttest 5 -eq $(git ls-files -s | wc -l) &&\n-\ttest 4 -eq $(git ls-files -u | wc -l) &&\n+\ttest_stdout_line_count = 5 git ls-files -s &&\n+\ttest_stdout_line_count = 4 git ls-files -u &&\n \tif test \"$GIT_TEST_MERGE_ALGORITHM\" = ort\n \tthen\n-\t\ttest 0 -eq $(git ls-files -o | wc -l)\n+\t\ttest_stdout_line_count = 0 git ls-files -o\n \telse\n-\t\ttest 1 -eq $(git ls-files -o | wc -l)\n+\t\ttest_stdout_line_count = 1 git ls-files -o\n \tfi &&\n \n \ttest_path_is_file letters/file &&\n-- \n2.32.0.278.gd42b80f139\n\n"},{"id":"429147","messageId":"f8ed19f858283e18ff4ae2d6ece199c82b624c30.1625362489.git.congdanhqx@gmail.com","threadId":"55936","inReplyTo":"cover.1625362488.git.congdanhqx@gmail.com","subject":"[PATCH v5 3/3] t6402: preserve git exit status code","fromName":"Đoàn Trần Công Danh","fromEmail":"congdanhqx@gmail.com","sentAt":"2021-07-04T05:46:12Z","receivedAt":"2021-07-04T05:46:30Z","isPatch":true,"sender":{"key":"congdanhqx@gmail.com","avatar":"https://avatars.githubusercontent.com/u/42673067?v=4"},"body":"In t6402, we're checking number of files in the index and the working\ntree by piping the output of Git's command to \"wc -l\", thus losing the\nexit status code of git.\n\nLet's use the new helper test_stdout_line_count in order to preserve\nGit's exit status code.\n\nSigned-off-by: Đoàn Trần Công Danh <congdanhqx@gmail.com>\n---\n t/t6402-merge-rename.sh | 132 +++++++++++++++++++---------------------\n 1 file changed, 64 insertions(+), 68 deletions(-)\n\ndiff --git a/t/t6402-merge-rename.sh b/t/t6402-merge-rename.sh\nindex 425dad97d5..3da2896e3b 100755\n--- a/t/t6402-merge-rename.sh\n+++ b/t/t6402-merge-rename.sh\n@@ -105,10 +105,8 @@ test_expect_success 'pull renaming branch into unrenaming one' \\\n \tgit show-branch &&\n \ttest_expect_code 1 git pull . white &&\n \tgit ls-files -s &&\n-\tgit ls-files -u B >b.stages &&\n-\ttest_line_count = 3 b.stages &&\n-\tgit ls-files -s N >n.stages &&\n-\ttest_line_count = 1 n.stages &&\n+\ttest_stdout_line_count = 3 git ls-files -u B &&\n+\ttest_stdout_line_count = 1 git ls-files -s N &&\n \tsed -ne \"/^g/{\n \tp\n \tq\n@@ -122,10 +120,8 @@ test_expect_success 'pull renaming branch into another renaming one' \\\n \tgit reset --hard &&\n \tgit checkout red &&\n \ttest_expect_code 1 git pull . white &&\n-\tgit ls-files -u B >b.stages &&\n-\ttest_line_count = 3 b.stages &&\n-\tgit ls-files -s N >n.stages &&\n-\ttest_line_count = 1 n.stages &&\n+\ttest_stdout_line_count = 3 git ls-files -u B &&\n+\ttest_stdout_line_count = 1 git ls-files -s N &&\n \tsed -ne \"/^g/{\n \tp\n \tq\n@@ -138,10 +134,8 @@ test_expect_success 'pull unrenaming branch into renaming one' \\\n \tgit reset --hard &&\n \tgit show-branch &&\n \ttest_expect_code 1 git pull . main &&\n-\tgit ls-files -u B >b.stages &&\n-\ttest_line_count = 3 b.stages &&\n-\tgit ls-files -s N >n.stages &&\n-\ttest_line_count = 1 n.stages &&\n+\ttest_stdout_line_count = 3 git ls-files -u B &&\n+\ttest_stdout_line_count = 1 git ls-files -s N &&\n \tsed -ne \"/^g/{\n \tp\n \tq\n@@ -154,14 +148,10 @@ test_expect_success 'pull conflicting renames' \\\n \tgit reset --hard &&\n \tgit show-branch &&\n \ttest_expect_code 1 git pull . blue &&\n-\tgit ls-files -u A >a.stages &&\n-\ttest_line_count = 1 a.stages &&\n-\tgit ls-files -u B >b.stages &&\n-\ttest_line_count = 1 b.stages &&\n-\tgit ls-files -u C >c.stages &&\n-\ttest_line_count = 1 c.stages &&\n-\tgit ls-files -s N >n.stages &&\n-\ttest_line_count = 1 n.stages &&\n+\ttest_stdout_line_count = 1 git ls-files -u A &&\n+\ttest_stdout_line_count = 1 git ls-files -u B &&\n+\ttest_stdout_line_count = 1 git ls-files -u C &&\n+\ttest_stdout_line_count = 1 git ls-files -s N &&\n \tsed -ne \"/^g/{\n \tp\n \tq\n@@ -330,8 +320,8 @@ test_expect_success 'Rename+D/F conflict; renamed file merges but dir in way' '\n \t\ttest_i18ngrep \"Adding as dir~HEAD instead\" output\n \tfi &&\n \n-\ttest 3 -eq \"$(git ls-files -u | wc -l)\" &&\n-\ttest 2 -eq \"$(git ls-files -u dir/file-in-the-way | wc -l)\" &&\n+\ttest_stdout_line_count = 3 git ls-files -u &&\n+\ttest_stdout_line_count = 2 git ls-files -u dir/file-in-the-way &&\n \n \ttest_must_fail git diff --quiet &&\n \ttest_must_fail git diff --cached --quiet &&\n@@ -357,8 +347,8 @@ test_expect_success 'Same as previous, but merged other way' '\n \t\ttest_i18ngrep \"Adding as dir~renamed-file-has-no-conflicts instead\" output\n \tfi &&\n \n-\ttest 3 -eq \"$(git ls-files -u | wc -l)\" &&\n-\ttest 2 -eq \"$(git ls-files -u dir/file-in-the-way | wc -l)\" &&\n+\ttest_stdout_line_count = 3 git ls-files -u &&\n+\ttest_stdout_line_count = 2 git ls-files -u dir/file-in-the-way &&\n \n \ttest_must_fail git diff --quiet &&\n \ttest_must_fail git diff --cached --quiet &&\n@@ -374,8 +364,8 @@ test_expect_success 'Rename+D/F conflict; renamed file cannot merge, dir not in\n \tgit checkout -q renamed-file-has-conflicts^0 &&\n \ttest_must_fail git merge --strategy=recursive dir-not-in-way &&\n \n-\ttest 3 -eq \"$(git ls-files -u | wc -l)\" &&\n-\ttest 3 -eq \"$(git ls-files -u dir | wc -l)\" &&\n+\ttest_stdout_line_count = 3 git ls-files -u &&\n+\ttest_stdout_line_count = 3 git ls-files -u dir &&\n \n \ttest_must_fail git diff --quiet &&\n \ttest_must_fail git diff --cached --quiet &&\n@@ -409,14 +399,16 @@ test_expect_success 'Rename+D/F conflict; renamed file cannot merge and dir in t\n \tgit checkout -q renamed-file-has-conflicts^0 &&\n \ttest_must_fail git merge --strategy=recursive dir-in-way &&\n \n-\ttest 5 -eq \"$(git ls-files -u | wc -l)\" &&\n+\ttest_stdout_line_count = 5 git ls-files -u &&\n \tif test \"$GIT_TEST_MERGE_ALGORITHM\" = ort\n \tthen\n-\t\ttest 3 -eq \"$(git ls-files -u dir~HEAD | wc -l)\"\n+\t\ttest_stdout_line_count = 3 git ls-files -u dir~HEAD\n \telse\n-\t\ttest 3 -eq \"$(git ls-files -u dir | grep -v file-in-the-way | wc -l)\"\n+\t\tgit ls-files -u dir >out &&\n+\t\ttest 3 -eq $(grep -v file-in-the-way out | wc -l) &&\n+\t\trm -f out\n \tfi &&\n-\ttest 2 -eq \"$(git ls-files -u dir/file-in-the-way | wc -l)\" &&\n+\ttest_stdout_line_count = 2 git ls-files -u dir/file-in-the-way &&\n \n \ttest_must_fail git diff --quiet &&\n \ttest_must_fail git diff --cached --quiet &&\n@@ -432,14 +424,16 @@ test_expect_success 'Same as previous, but merged other way' '\n \tgit checkout -q dir-in-way^0 &&\n \ttest_must_fail git merge --strategy=recursive renamed-file-has-conflicts &&\n \n-\ttest 5 -eq \"$(git ls-files -u | wc -l)\" &&\n+\ttest_stdout_line_count = 5 git ls-files -u &&\n \tif test \"$GIT_TEST_MERGE_ALGORITHM\" = ort\n \tthen\n-\t\ttest 3 -eq \"$(git ls-files -u dir~renamed-file-has-conflicts | wc -l)\"\n+\t\ttest_stdout_line_count = 3 git ls-files -u dir~renamed-file-has-conflicts\n \telse\n-\t\ttest 3 -eq \"$(git ls-files -u dir | grep -v file-in-the-way | wc -l)\"\n+\t\tgit ls-files -u dir >out &&\n+\t\ttest 3 -eq $(grep -v file-in-the-way out | wc -l) &&\n+\t\trm -f out\n \tfi &&\n-\ttest 2 -eq \"$(git ls-files -u dir/file-in-the-way | wc -l)\" &&\n+\ttest_stdout_line_count = 2 git ls-files -u dir/file-in-the-way &&\n \n \ttest_must_fail git diff --quiet &&\n \ttest_must_fail git diff --cached --quiet &&\n@@ -496,9 +490,9 @@ test_expect_success 'both rename source and destination involved in D/F conflict\n \n \tif test \"$GIT_TEST_MERGE_ALGORITHM\" = ort\n \tthen\n-\t\ttest 2 -eq \"$(git ls-files -u | wc -l)\"\n+\t\ttest_stdout_line_count = 2 git ls-files -u\n \telse\n-\t\ttest 1 -eq \"$(git ls-files -u | wc -l)\"\n+\t\ttest_stdout_line_count = 1 git ls-files -u\n \tfi &&\n \n \ttest_must_fail git diff --quiet &&\n@@ -540,9 +534,9 @@ then\n \t\tmkdir one &&\n \t\ttest_must_fail git merge --strategy=recursive rename-two &&\n \n-\t\ttest 4 -eq \"$(git ls-files -u | wc -l)\" &&\n-\t\ttest 2 -eq \"$(git ls-files -u one | wc -l)\" &&\n-\t\ttest 2 -eq \"$(git ls-files -u two | wc -l)\" &&\n+\t\ttest_stdout_line_count = 4 git ls-files -u &&\n+\t\ttest_stdout_line_count = 2 git ls-files -u one &&\n+\t\ttest_stdout_line_count = 2 git ls-files -u two &&\n \n \t\ttest_must_fail git diff --quiet &&\n \n@@ -559,9 +553,9 @@ else\n \t\tmkdir one &&\n \t\ttest_must_fail git merge --strategy=recursive rename-two &&\n \n-\t\ttest 2 -eq \"$(git ls-files -u | wc -l)\" &&\n-\t\ttest 1 -eq \"$(git ls-files -u one | wc -l)\" &&\n-\t\ttest 1 -eq \"$(git ls-files -u two | wc -l)\" &&\n+\t\ttest_stdout_line_count = 2 git ls-files -u &&\n+\t\ttest_stdout_line_count = 1 git ls-files -u one &&\n+\t\ttest_stdout_line_count = 1 git ls-files -u two &&\n \n \t\ttest_must_fail git diff --quiet &&\n \n@@ -582,13 +576,13 @@ test_expect_success 'pair rename to parent of other (D/F conflicts) w/ clean sta\n \n \tif test \"$GIT_TEST_MERGE_ALGORITHM\" = ort\n \tthen\n-\t\ttest 4 -eq \"$(git ls-files -u | wc -l)\" &&\n-\t\ttest 2 -eq \"$(git ls-files -u one | wc -l)\" &&\n-\t\ttest 2 -eq \"$(git ls-files -u two | wc -l)\"\n+\t\ttest_stdout_line_count = 4 git ls-files -u &&\n+\t\ttest_stdout_line_count = 2 git ls-files -u one &&\n+\t\ttest_stdout_line_count = 2 git ls-files -u two\n \telse\n-\t\ttest 2 -eq \"$(git ls-files -u | wc -l)\" &&\n-\t\ttest 1 -eq \"$(git ls-files -u one | wc -l)\" &&\n-\t\ttest 1 -eq \"$(git ls-files -u two | wc -l)\"\n+\t\ttest_stdout_line_count = 2 git ls-files -u &&\n+\t\ttest_stdout_line_count = 1 git ls-files -u one &&\n+\t\ttest_stdout_line_count = 1 git ls-files -u two\n \tfi &&\n \n \ttest_must_fail git diff --quiet &&\n@@ -631,19 +625,19 @@ test_expect_success 'check handling of differently renamed file with D/F conflic\n \n \tif test \"$GIT_TEST_MERGE_ALGORITHM\" = ort\n \tthen\n-\t\ttest 5 -eq \"$(git ls-files -s | wc -l)\" &&\n-\t\ttest 3 -eq \"$(git ls-files -u | wc -l)\" &&\n-\t\ttest 1 -eq \"$(git ls-files -u one~HEAD | wc -l)\" &&\n-\t\ttest 1 -eq \"$(git ls-files -u two~second-rename | wc -l)\" &&\n-\t\ttest 1 -eq \"$(git ls-files -u original | wc -l)\" &&\n-\t\ttest 0 -eq \"$(git ls-files -o | wc -l)\"\n+\t\ttest_stdout_line_count = 5 git ls-files -s &&\n+\t\ttest_stdout_line_count = 3 git ls-files -u &&\n+\t\ttest_stdout_line_count = 1 git ls-files -u one~HEAD &&\n+\t\ttest_stdout_line_count = 1 git ls-files -u two~second-rename &&\n+\t\ttest_stdout_line_count = 1 git ls-files -u original &&\n+\t\ttest_stdout_line_count = 0 git ls-files -o\n \telse\n-\t\ttest 5 -eq \"$(git ls-files -s | wc -l)\" &&\n-\t\ttest 3 -eq \"$(git ls-files -u | wc -l)\" &&\n-\t\ttest 1 -eq \"$(git ls-files -u one | wc -l)\" &&\n-\t\ttest 1 -eq \"$(git ls-files -u two | wc -l)\" &&\n-\t\ttest 1 -eq \"$(git ls-files -u original | wc -l)\" &&\n-\t\ttest 2 -eq \"$(git ls-files -o | wc -l)\"\n+\t\ttest_stdout_line_count = 5 git ls-files -s &&\n+\t\ttest_stdout_line_count = 3 git ls-files -u &&\n+\t\ttest_stdout_line_count = 1 git ls-files -u one &&\n+\t\ttest_stdout_line_count = 1 git ls-files -u two &&\n+\t\ttest_stdout_line_count = 1 git ls-files -u original &&\n+\t\ttest_stdout_line_count = 2 git ls-files -o\n \tfi &&\n \n \ttest_path_is_file one/file &&\n@@ -679,11 +673,11 @@ test_expect_success 'check handling of differently renamed file with D/F conflic\n \tgit checkout -q first-rename-redo^0 &&\n \ttest_must_fail git merge --strategy=recursive second-rename-redo &&\n \n-\ttest 3 -eq \"$(git ls-files -u | wc -l)\" &&\n-\ttest 1 -eq \"$(git ls-files -u one | wc -l)\" &&\n-\ttest 1 -eq \"$(git ls-files -u two | wc -l)\" &&\n-\ttest 1 -eq \"$(git ls-files -u original | wc -l)\" &&\n-\ttest 0 -eq \"$(git ls-files -o | wc -l)\" &&\n+\ttest_stdout_line_count = 3 git ls-files -u &&\n+\ttest_stdout_line_count = 1 git ls-files -u one &&\n+\ttest_stdout_line_count = 1 git ls-files -u two &&\n+\ttest_stdout_line_count = 1 git ls-files -u original &&\n+\ttest_stdout_line_count = 0 git ls-files -o &&\n \n \ttest_path_is_file one &&\n \ttest_path_is_file two &&\n@@ -861,9 +855,11 @@ test_expect_success 'setup merge of rename + small change' '\n test_expect_success 'merge rename + small change' '\n \tgit merge rename_branch &&\n \n-\ttest 1 -eq $(git ls-files -s | wc -l) &&\n-\ttest 0 -eq $(git ls-files -o | wc -l) &&\n-\ttest $(git rev-parse HEAD:renamed_file) = $(git rev-parse HEAD~1:file)\n+\ttest_stdout_line_count = 1 git ls-files -s &&\n+\ttest_stdout_line_count = 0 git ls-files -o &&\n+\tnewhash=$(git rev-parse HEAD:renamed_file) &&\n+\toldhash=$(git rev-parse HEAD~1:file) &&\n+\ttest $newhash = $oldhash\n '\n \n test_expect_success 'setup for use of extended merge markers' '\n-- \n2.32.0.278.gd42b80f139\n\n"},{"id":"429148","messageId":"CAPig+cRNw_RVx3CCXN-Usz0Jmi0iphDv2Vqg1cZFqa+QricuJw@mail.gmail.com","threadId":"55936","inReplyTo":"ab542ae9aa35decd2bc55561c5ba8f5653fa07a2.1625362489.git.congdanhqx@gmail.com","subject":"Re: [PATCH v5 1/3] test-lib-functions: introduce test_stdout_line_count","fromName":"Eric Sunshine","fromEmail":"sunshine@sunshineco.com","sentAt":"2021-07-04T05:56:41Z","receivedAt":"2021-07-04T05:57:59Z","isPatch":true,"sender":{"key":"sunshine@sunshineco.com","avatar":"https://avatars.githubusercontent.com/u/163641?v=4"},"body":"On Sun, Jul 4, 2021 at 1:46 AM Đoàn Trần Công Danh <congdanhqx@gmail.com> wrote:\n> In some tests, we're checking the number of lines in output of some\n> commands, including but not limited to Git's command.\n>\n> We're doing the check by running those commands in the left side of\n> a pipe, thus losing the exit status code of those commands. Meanwhile,\n> we really want to check the exit status code of Git's command.\n>\n> Let's write the output of those commands to a temporary file, and use\n> test_line_count separately in order to check exit status code of\n> those commands properly.\n>\n> Signed-off-by: Đoàn Trần Công Danh <congdanhqx@gmail.com>\n> ---\n> diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh\n> @@ -845,6 +845,32 @@ test_line_count () {\n> +# SYNOPSIS:\n> +#      test_stdout_line_count <bin-ops> <value> <cmd> [<args>...]\n> +#\n> +# test_stdout_line_count checks that the output of a command has the number\n> +# of lines it ought to. For example:\n> +#\n> +# test_stdout_line_count = 3 git ls-files -u\n> +# test_stdout_line_count -gt 10 ls\n> +test_stdout_line_count () {\n> +       local ops val trashdir &&\n> +       if test \"$#\" -le 3\n> +       then\n> +               BUG \"expect 3 or more arguments\"\n> +       fi &&\n> +       ops=\"$1\" &&\n> +       val=\"$2\" &&\n> +       shift 2 &&\n> +       if ! trashdir=\"$(git rev-parse --git-dir)/trash\"; then\n> +               BUG \"expect to be run inside a worktree\"\n> +       fi &&\n> +       mkdir -p \"$trashdir\" &&\n> +       \"$@\" >\"$trashdir/output\" &&\n> +       test_line_count \"$ops\" \"$val\" \"$trashdir/output\"\n> +}\n> +\n> +\n>  test_file_size () {\n\nNit: one too many blank lines after the test body.\n\nA minor think-out-loud: I wonder if there would be value in deriving\nthe name of the output file from the command being run (perhaps by\nusing `tr` to translate oddball characters to underscore or to fold\nthem out). This might or might not help someone debugging a test\nfailure since there would be less chance of \"$trashdir/output\" being\nrepeatedly clobbered. Anyhow, it's something that could be done later\nif deemed useful, not something for the present series. (I'm not\ninterested in seeing this series re-rolled endlessly.)\n"},{"id":"429324","messageId":"xmqqo8bfjley.fsf@gitster.g","threadId":"55936","inReplyTo":"CAPig+cRNw_RVx3CCXN-Usz0Jmi0iphDv2Vqg1cZFqa+QricuJw@mail.gmail.com","subject":"Re: [PATCH v5 1/3] test-lib-functions: introduce test_stdout_line_count","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2021-07-06T19:24:05Z","receivedAt":"2021-07-06T19:24:11Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Eric Sunshine <sunshine@sunshineco.com> writes:\n\n> A minor think-out-loud: I wonder if there would be value in deriving\n> the name of the output file from the command being run (perhaps by\n> using `tr` to translate oddball characters to underscore or to fold\n> them out). This might or might not help someone debugging a test\n> failure since there would be less chance of \"$trashdir/output\" being\n> repeatedly clobbered.\n\nProbably not.\n\nThe iterations of output that are clobbered are all from the passing\ncall to test_stdout_count_lines helper we made previously.\n\n"},{"id":"429398","messageId":"YOUZi+Ueg5MIl6DF@danh.dev","threadId":"55936","inReplyTo":"xmqqo8bfjley.fsf@gitster.g","subject":"Re: [PATCH v5 1/3] test-lib-functions: introduce test_stdout_line_count","fromName":"Đoàn Trần Công Danh","fromEmail":"congdanhqx@gmail.com","sentAt":"2021-07-07T03:03:39Z","receivedAt":"2021-07-07T03:03:46Z","isPatch":true,"sender":{"key":"congdanhqx@gmail.com","avatar":"https://avatars.githubusercontent.com/u/42673067?v=4"},"body":"On 2021-07-06 12:24:05-0700, Junio C Hamano <gitster@pobox.com> wrote:\n> Eric Sunshine <sunshine@sunshineco.com> writes:\n> \n> > A minor think-out-loud: I wonder if there would be value in deriving\n> > the name of the output file from the command being run (perhaps by\n> > using `tr` to translate oddball characters to underscore or to fold\n> > them out). This might or might not help someone debugging a test\n> > failure since there would be less chance of \"$trashdir/output\" being\n> > repeatedly clobbered.\n> \n> Probably not.\n> \n> The iterations of output that are clobbered are all from the passing\n> call to test_stdout_count_lines helper we made previously.\n\nYay, I also think it doesn't add much value. Since we're chaining\ncommand in a single test-case.\n\nI think most people with try to debug with \"-i\", which exits\nimmediately.\n\nThe only place it would help is debugging test failures with GitHub\nActions, where developers could download artifarts for test failures\nfrom GitHub Actions.\n\n-- \nDanh\n"}]}