[PATCH 2/2] t6402: check exit status of ls-files

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



We will lose the exit status of "git ls-files" if it's being run in
anywhere-but-not-final part of a pipe.

Let's send the output of "git ls-files" to a file first,
and adjust the expected result for "git ls-files -o" since a new
untracked file will be created as a side effect.

Signed-off-by: Đoàn Trần Công Danh <congdanhqx@xxxxxxxxx>
---
 t/t6402-merge-rename.sh | 148 +++++++++++++++++++++++++++-------------
 1 file changed, 101 insertions(+), 47 deletions(-)

diff --git a/t/t6402-merge-rename.sh b/t/t6402-merge-rename.sh
index 425dad97d5..d705847f26 100755
--- a/t/t6402-merge-rename.sh
+++ b/t/t6402-merge-rename.sh
@@ -330,8 +330,10 @@ test_expect_success 'Rename+D/F conflict; renamed file merges but dir in way' '
 		test_i18ngrep "Adding as dir~HEAD instead" output
 	fi &&
 
-	test 3 -eq "$(git ls-files -u | wc -l)" &&
-	test 2 -eq "$(git ls-files -u dir/file-in-the-way | wc -l)" &&
+	git ls-files -u >output &&
+	test_line_count = 3 output &&
+	git ls-files -u dir/file-in-the-way >output &&
+	test_line_count = 2 output &&
 
 	test_must_fail git diff --quiet &&
 	test_must_fail git diff --cached --quiet &&
@@ -357,8 +359,10 @@ test_expect_success 'Same as previous, but merged other way' '
 		test_i18ngrep "Adding as dir~renamed-file-has-no-conflicts instead" output
 	fi &&
 
-	test 3 -eq "$(git ls-files -u | wc -l)" &&
-	test 2 -eq "$(git ls-files -u dir/file-in-the-way | wc -l)" &&
+	git ls-files -u >output &&
+	test_line_count = 3 output &&
+	git ls-files -u dir/file-in-the-way >output &&
+	test_line_count = 2 output &&
 
 	test_must_fail git diff --quiet &&
 	test_must_fail git diff --cached --quiet &&
@@ -374,8 +378,10 @@ test_expect_success 'Rename+D/F conflict; renamed file cannot merge, dir not in
 	git checkout -q renamed-file-has-conflicts^0 &&
 	test_must_fail git merge --strategy=recursive dir-not-in-way &&
 
-	test 3 -eq "$(git ls-files -u | wc -l)" &&
-	test 3 -eq "$(git ls-files -u dir | wc -l)" &&
+	git ls-files -u >output &&
+	test_line_count = 3 output &&
+	git ls-files -u dir >output &&
+	test_line_count = 3 output &&
 
 	test_must_fail git diff --quiet &&
 	test_must_fail git diff --cached --quiet &&
@@ -409,14 +415,19 @@ test_expect_success 'Rename+D/F conflict; renamed file cannot merge and dir in t
 	git checkout -q renamed-file-has-conflicts^0 &&
 	test_must_fail git merge --strategy=recursive dir-in-way &&
 
-	test 5 -eq "$(git ls-files -u | wc -l)" &&
+	git ls-files -u >output &&
+	test_line_count = 5 output &&
 	if test "$GIT_TEST_MERGE_ALGORITHM" = ort
 	then
-		test 3 -eq "$(git ls-files -u dir~HEAD | wc -l)"
+		git ls-files -u dir~HEAD >output &&
+		test_line_count = 3 output
 	else
-		test 3 -eq "$(git ls-files -u dir | grep -v file-in-the-way | wc -l)"
+		git ls-files -u dir >output &&
+		grep -v file-in-the-way output >filtered
+		test_line_count = 3 filtered
 	fi &&
-	test 2 -eq "$(git ls-files -u dir/file-in-the-way | wc -l)" &&
+	git ls-files -u dir/file-in-the-way >output &&
+	test_line_count = 2 output &&
 
 	test_must_fail git diff --quiet &&
 	test_must_fail git diff --cached --quiet &&
@@ -432,14 +443,19 @@ test_expect_success 'Same as previous, but merged other way' '
 	git checkout -q dir-in-way^0 &&
 	test_must_fail git merge --strategy=recursive renamed-file-has-conflicts &&
 
-	test 5 -eq "$(git ls-files -u | wc -l)" &&
+	git ls-files -u >output &&
+	test_line_count = 5 output &&
 	if test "$GIT_TEST_MERGE_ALGORITHM" = ort
 	then
-		test 3 -eq "$(git ls-files -u dir~renamed-file-has-conflicts | wc -l)"
+		git ls-files -u dir~renamed-file-has-conflicts >output &&
+		test_line_count = 3 output
 	else
-		test 3 -eq "$(git ls-files -u dir | grep -v file-in-the-way | wc -l)"
+		git ls-files -u dir >output &&
+		grep -v file-in-the-way output >filtered
+		test_line_count = 3 filtered
 	fi &&
-	test 2 -eq "$(git ls-files -u dir/file-in-the-way | wc -l)" &&
+	git ls-files -u dir/file-in-the-way >output &&
+	test_line_count = 2 output &&
 
 	test_must_fail git diff --quiet &&
 	test_must_fail git diff --cached --quiet &&
@@ -494,11 +510,12 @@ test_expect_success 'both rename source and destination involved in D/F conflict
 	git checkout -q rename-dest^0 &&
 	test_must_fail git merge --strategy=recursive source-conflict &&
 
+	git ls-files -u >output &&
 	if test "$GIT_TEST_MERGE_ALGORITHM" = ort
 	then
-		test 2 -eq "$(git ls-files -u | wc -l)"
+		test_line_count = 2 output
 	else
-		test 1 -eq "$(git ls-files -u | wc -l)"
+		test_line_count = 1 output
 	fi &&
 
 	test_must_fail git diff --quiet &&
@@ -540,9 +557,13 @@ then
 		mkdir one &&
 		test_must_fail git merge --strategy=recursive rename-two &&
 
-		test 4 -eq "$(git ls-files -u | wc -l)" &&
-		test 2 -eq "$(git ls-files -u one | wc -l)" &&
-		test 2 -eq "$(git ls-files -u two | wc -l)" &&
+		git ls-files -u >output &&
+		test_line_count = 4 output &&
+		git ls-files -u one >output &&
+		test_line_count = 2 output &&
+		git ls-files -u two >output &&
+		test_line_count = 2 output &&
+		rm -f output &&
 
 		test_must_fail git diff --quiet &&
 
@@ -559,9 +580,13 @@ else
 		mkdir one &&
 		test_must_fail git merge --strategy=recursive rename-two &&
 
-		test 2 -eq "$(git ls-files -u | wc -l)" &&
-		test 1 -eq "$(git ls-files -u one | wc -l)" &&
-		test 1 -eq "$(git ls-files -u two | wc -l)" &&
+		git ls-files -u >output &&
+		test_line_count = 2 output &&
+		git ls-files -u one >output &&
+		test_line_count = 1 output &&
+		git ls-files -u two >output &&
+		test_line_count = 1 output &&
+		rm -f output &&
 
 		test_must_fail git diff --quiet &&
 
@@ -582,14 +607,21 @@ test_expect_success 'pair rename to parent of other (D/F conflicts) w/ clean sta
 
 	if test "$GIT_TEST_MERGE_ALGORITHM" = ort
 	then
-		test 4 -eq "$(git ls-files -u | wc -l)" &&
-		test 2 -eq "$(git ls-files -u one | wc -l)" &&
-		test 2 -eq "$(git ls-files -u two | wc -l)"
+		git ls-files -u >output &&
+		test_line_count = 4 output &&
+		git ls-files -u one >output &&
+		test_line_count = 2 output &&
+		git ls-files -u two >output &&
+		test_line_count = 2 output
 	else
-		test 2 -eq "$(git ls-files -u | wc -l)" &&
-		test 1 -eq "$(git ls-files -u one | wc -l)" &&
-		test 1 -eq "$(git ls-files -u two | wc -l)"
+		git ls-files -u >output &&
+		test_line_count = 2 output &&
+		git ls-files -u one >output &&
+		test_line_count = 1 output &&
+		git ls-files -u two >output &&
+		test_line_count = 1 output
 	fi &&
+	rm -f output &&
 
 	test_must_fail git diff --quiet &&
 
@@ -631,20 +663,33 @@ test_expect_success 'check handling of differently renamed file with D/F conflic
 
 	if test "$GIT_TEST_MERGE_ALGORITHM" = ort
 	then
-		test 5 -eq "$(git ls-files -s | wc -l)" &&
-		test 3 -eq "$(git ls-files -u | wc -l)" &&
-		test 1 -eq "$(git ls-files -u one~HEAD | wc -l)" &&
-		test 1 -eq "$(git ls-files -u two~second-rename | wc -l)" &&
-		test 1 -eq "$(git ls-files -u original | wc -l)" &&
-		test 0 -eq "$(git ls-files -o | wc -l)"
+		git ls-files -s >output &&
+		test_line_count = 5 output &&
+		git ls-files -u >output &&
+		test_line_count = 3 output &&
+		git ls-files -u one~HEAD >output &&
+		test_line_count = 1 output &&
+		git ls-files -u two~second-rename >output &&
+		test_line_count = 1 output &&
+		git ls-files -u original >output &&
+		test_line_count = 1 output &&
+		git ls-files -o >output &&
+		test_line_count = 1 output
 	else
-		test 5 -eq "$(git ls-files -s | wc -l)" &&
-		test 3 -eq "$(git ls-files -u | wc -l)" &&
-		test 1 -eq "$(git ls-files -u one | wc -l)" &&
-		test 1 -eq "$(git ls-files -u two | wc -l)" &&
-		test 1 -eq "$(git ls-files -u original | wc -l)" &&
-		test 2 -eq "$(git ls-files -o | wc -l)"
+		git ls-files -s >output &&
+		test_line_count = 5 output &&
+		git ls-files -u >output &&
+		test_line_count = 3 output &&
+		git ls-files -u one >output &&
+		test_line_count = 1 output &&
+		git ls-files -u two >output &&
+		test_line_count = 1 output &&
+		git ls-files -u original >output &&
+		test_line_count = 1 output &&
+		git ls-files -o >output &&
+		test_line_count = 3 output
 	fi &&
+	rm -f output &&
 
 	test_path_is_file one/file &&
 	test_path_is_file two/file &&
@@ -679,11 +724,17 @@ test_expect_success 'check handling of differently renamed file with D/F conflic
 	git checkout -q first-rename-redo^0 &&
 	test_must_fail git merge --strategy=recursive second-rename-redo &&
 
-	test 3 -eq "$(git ls-files -u | wc -l)" &&
-	test 1 -eq "$(git ls-files -u one | wc -l)" &&
-	test 1 -eq "$(git ls-files -u two | wc -l)" &&
-	test 1 -eq "$(git ls-files -u original | wc -l)" &&
-	test 0 -eq "$(git ls-files -o | wc -l)" &&
+	git ls-files -u >output &&
+	test_line_count = 3 output &&
+	git ls-files -u one >output &&
+	test_line_count = 1 output &&
+	git ls-files -u two >output &&
+	test_line_count = 1 output &&
+	git ls-files -u original >output &&
+	test_line_count = 1 output &&
+	git ls-files -o >output &&
+	test_line_count = 1 output &&
+	rm -f output &&
 
 	test_path_is_file one &&
 	test_path_is_file two &&
@@ -861,8 +912,11 @@ test_expect_success 'setup merge of rename + small change' '
 test_expect_success 'merge rename + small change' '
 	git merge rename_branch &&
 
-	test 1 -eq $(git ls-files -s | wc -l) &&
-	test 0 -eq $(git ls-files -o | wc -l) &&
+	git ls-files -s >output &&
+	test_line_count = 1 output &&
+	git ls-files -o >output &&
+	test_line_count = 1 output &&
+	rm -f output &&
 	test $(git rev-parse HEAD:renamed_file) = $(git rev-parse HEAD~1:file)
 '
 
-- 
2.31.1.192.g0881477623




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux