git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v6 12/14] t5520: replace $(cat ...) comparison with test_cmp

From
Denton Liu <liu.denton@gmail.com>
Date
Nov 12, 2019, 23:08 UTC
Message-ID
<67ea3f0238845f3717e85593e0f10c086df04280.1573595985.git.liu.denton@gmail.com>
In-Reply-To
<cover.1573595985.git.liu.denton@gmail.com>

We currently have many instances of `test <line> = $(cat <file>)` and `test $(cat <file>) = <line>`. In the case where this fails, it will be difficult for a developer to debug since the output will be masked. Replace these instances with invocations of test_cmp().

This change was done with the following GNU sed expressions:
	s/\(\s*\)test \([^=]*\)= "$(cat \([^)]*\))"/\1echo \2>expect \&\&\n\1test_cmp expect \3/
	s/\(\s*\)test "$(cat \([^)]*\))" = \([^&]*\)\( &&\)\?$/\1echo \3 >expect \&\&\n\1test_cmp expect \2\4/

A future patch will clean up situations where we have multiple duplicate statements within a test case. This is done to keep this patch purely mechanical.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t5520-pull.sh | 105 ++++++++++++++++++++++++++++++++----------------
 1 file changed, 70 insertions(+), 35 deletions(-)
diff --git a/t/t5520-pull.sh b/t/t5520-pull.sh
index 8ddf89e550..c9e4eec004 100755
--- a/t/t5520-pull.sh
+++ b/t/t5520-pull.sh
@@ -15,8 +15,10 @@ test_pull_autostash () {
 	git add new_file &&
 	git pull "$@" . copy &&
 	test_cmp_rev HEAD^ copy &&
-	test "$(cat new_file)" = dirty &&
-	test "$(cat file)" = "modified again"
+	echo dirty >expect &&
+	test_cmp expect new_file &&
+	echo "modified again" >expect &&
+	test_cmp expect file
 }
 
 test_pull_autostash_fail () {
@@ -110,9 +112,11 @@ test_expect_success 'test . as a remote' '
 	echo updated >file &&
 	git commit -a -m updated &&
 	git checkout copy &&
-	test "$(cat file)" = file &&
+	echo file >expect &&
+	test_cmp expect file &&
 	git pull &&
-	test "$(cat file)" = updated &&
+	echo updated >expect &&
+	test_cmp expect file &&
 	git reflog -1 >reflog.actual &&
 	sed "s/^[0-9a-f][0-9a-f]*/OBJID/" reflog.actual >reflog.fuzzy &&
 	echo "OBJID HEAD@{0}: pull: Fast-forward" >reflog.expected &&
@@ -125,9 +129,11 @@ test_expect_success 'the default remote . should not break explicit pull' '
 	git commit -a -m modified &&
 	git checkout copy &&
 	git reset --hard HEAD^ &&
-	test "$(cat file)" = file &&
+	echo file >expect &&
+	test_cmp expect file &&
 	git pull . second &&
-	test "$(cat file)" = modified &&
+	echo modified >expect &&
+	test_cmp expect file &&
 	git reflog -1 >reflog.actual &&
 	sed "s/^[0-9a-f][0-9a-f]*/OBJID/" reflog.actual >reflog.fuzzy &&
 	echo "OBJID HEAD@{0}: pull . second: Fast-forward" >reflog.expected &&
@@ -137,10 +143,12 @@ test_expect_success 'the default remote . should not break explicit pull' '
 test_expect_success 'fail if wildcard spec does not match any refs' '
 	git checkout -b test copy^ &&
 	test_when_finished "git checkout -f copy && git branch -D test" &&
-	test "$(cat file)" = file &&
+	echo file >expect &&
+	test_cmp expect file &&
 	test_must_fail git pull . "refs/nonexisting1/*:refs/nonexisting2/*" 2>err &&
 	test_i18ngrep "no candidates for merging" err &&
-	test "$(cat file)" = file
+	echo file >expect &&
+	test_cmp expect file
 '
 
 test_expect_success 'fail if no branches specified with non-default remote' '
@@ -148,11 +156,13 @@ test_expect_success 'fail if no branches specified with non-default remote' '
 	test_when_finished "git remote remove test_remote" &&
 	git checkout -b test copy^ &&
 	test_when_finished "git checkout -f copy && git branch -D test" &&
-	test "$(cat file)" = file &&
+	echo file >expect &&
+	test_cmp expect file &&
 	test_config branch.test.remote origin &&
 	test_must_fail git pull test_remote 2>err &&
 	test_i18ngrep "specify a branch on the command line" err &&
-	test "$(cat file)" = file
+	echo file >expect &&
+	test_cmp expect file
 '
 
 test_expect_success 'fail if not on a branch' '
@@ -160,10 +170,12 @@ test_expect_success 'fail if not on a branch' '
 	test_when_finished "git remote remove origin" &&
 	git checkout HEAD^ &&
 	test_when_finished "git checkout -f copy" &&
-	test "$(cat file)" = file &&
+	echo file >expect &&
+	test_cmp expect file &&
 	test_must_fail git pull 2>err &&
 	test_i18ngrep "not currently on a branch" err &&
-	test "$(cat file)" = file
+	echo file >expect &&
+	test_cmp expect file
 '
 
 test_expect_success 'fail if no configuration for current branch' '
@@ -172,10 +184,12 @@ test_expect_success 'fail if no configuration for current branch' '
 	git checkout -b test copy^ &&
 	test_when_finished "git checkout -f copy && git branch -D test" &&
 	test_config branch.test.remote test_remote &&
-	test "$(cat file)" = file &&
+	echo file >expect &&
+	test_cmp expect file &&
 	test_must_fail git pull 2>err &&
 	test_i18ngrep "no tracking information" err &&
-	test "$(cat file)" = file
+	echo file >expect &&
+	test_cmp expect file
 '
 
 test_expect_success 'pull --all: fail if no configuration for current branch' '
@@ -184,10 +198,12 @@ test_expect_success 'pull --all: fail if no configuration for current branch' '
 	git checkout -b test copy^ &&
 	test_when_finished "git checkout -f copy && git branch -D test" &&
 	test_config branch.test.remote test_remote &&
-	test "$(cat file)" = file &&
+	echo file >expect &&
+	test_cmp expect file &&
 	test_must_fail git pull --all 2>err &&
 	test_i18ngrep "There is no tracking information" err &&
-	test "$(cat file)" = file
+	echo file >expect &&
+	test_cmp expect file
 '
 
 test_expect_success 'fail if upstream branch does not exist' '
@@ -195,16 +211,19 @@ test_expect_success 'fail if upstream branch does not exist' '
 	test_when_finished "git checkout -f copy && git branch -D test" &&
 	test_config branch.test.remote . &&
 	test_config branch.test.merge refs/heads/nonexisting &&
-	test "$(cat file)" = file &&
+	echo file >expect &&
+	test_cmp expect file &&
 	test_must_fail git pull 2>err &&
 	test_i18ngrep "no such ref was fetched" err &&
-	test "$(cat file)" = file
+	echo file >expect &&
+	test_cmp expect file
 '
 
 test_expect_success 'fail if the index has unresolved entries' '
 	git checkout -b third second^ &&
 	test_when_finished "git checkout -f copy && git branch -D third" &&
-	test "$(cat file)" = file &&
+	echo file >expect &&
+	test_cmp expect file &&
 	test_commit modified2 file &&
 	git ls-files -u >unmerged &&
 	test_must_be_empty unmerged &&
@@ -226,21 +245,25 @@ test_expect_success 'fail if the index has unresolved entries' '
 test_expect_success 'fast-forwards working tree if branch head is updated' '
 	git checkout -b third second^ &&
 	test_when_finished "git checkout -f copy && git branch -D third" &&
-	test "$(cat file)" = file &&
+	echo file >expect &&
+	test_cmp expect file &&
 	git pull . second:third 2>err &&
 	test_i18ngrep "fetch updated the current branch head" err &&
-	test "$(cat file)" = modified &&
+	echo modified >expect &&
+	test_cmp expect file &&
 	test_cmp_rev third second
 '
 
 test_expect_success 'fast-forward fails with conflicting work tree' '
 	git checkout -b third second^ &&
 	test_when_finished "git checkout -f copy && git branch -D third" &&
-	test "$(cat file)" = file &&
+	echo file >expect &&
+	test_cmp expect file &&
 	echo conflict >file &&
 	test_must_fail git pull . second:third 2>err &&
 	test_i18ngrep "Cannot fast-forward your working tree" err &&
-	test "$(cat file)" = conflict &&
+	echo conflict >expect &&
+	test_cmp expect file &&
 	test_cmp_rev third second
 '
 
@@ -501,7 +524,8 @@ test_expect_success 'pull.rebase=interactive' '
 	test_set_editor "$TRASH_DIRECTORY/fake-editor" &&
 	test_when_finished "test_might_fail git rebase --abort" &&
 	test_must_fail git pull --rebase=interactive . copy &&
-	test "I was here" = "$(cat fake.out)"
+	echo "I was here" >expect &&
+	test_cmp expect fake.out
 '
 
 test_expect_success 'pull --rebase=i' '
@@ -512,7 +536,8 @@ test_expect_success 'pull --rebase=i' '
 	test_set_editor "$TRASH_DIRECTORY/fake-editor" &&
 	test_when_finished "test_might_fail git rebase --abort" &&
 	test_must_fail git pull --rebase=i . copy &&
-	test "I was here, too" = "$(cat fake.out)"
+	echo "I was here, too" >expect &&
+	test_cmp expect fake.out
 '
 
 test_expect_success 'pull.rebase=invalid fails' '
@@ -578,16 +603,20 @@ test_expect_success '--rebase with rebased upstream' '
 	git commit -m to-rebase file2 &&
 	git tag to-rebase-orig &&
 	git pull --rebase me copy &&
-	test "conflicting modification" = "$(cat file)" &&
-	test file = "$(cat file2)"
+	echo "conflicting modification" >expect &&
+	test_cmp expect file &&
+	echo file >expect &&
+	test_cmp expect file2
 '
 
 test_expect_success '--rebase -f with rebased upstream' '
 	test_when_finished "test_might_fail git rebase --abort" &&
 	git reset --hard to-rebase-orig &&
 	git pull --rebase -f me copy &&
-	test "conflicting modification" = "$(cat file)" &&
-	test file = "$(cat file2)"
+	echo "conflicting modification" >expect &&
+	test_cmp expect file &&
+	echo file >expect &&
+	test_cmp expect file2
 '
 
 test_expect_success '--rebase with rebased default upstream' '
@@ -595,8 +624,10 @@ test_expect_success '--rebase with rebased default upstream' '
 	git checkout --track -b to-rebase2 me/copy &&
 	git reset --hard to-rebase-orig &&
 	git pull --rebase &&
-	test "conflicting modification" = "$(cat file)" &&
-	test file = "$(cat file2)"
+	echo "conflicting modification" >expect &&
+	test_cmp expect file &&
+	echo file >expect &&
+	test_cmp expect file2
 '
 
 test_expect_success 'rebased upstream + fetch + pull --rebase' '
@@ -607,8 +638,10 @@ test_expect_success 'rebased upstream + fetch + pull --rebase' '
 	git reset --hard to-rebase-orig &&
 	git fetch &&
 	git pull --rebase &&
-	test "conflicting modification" = "$(cat file)" &&
-	test file = "$(cat file2)"
+	echo "conflicting modification" >expect &&
+	test_cmp expect file &&
+	echo file >expect &&
+	test_cmp expect file2
 
 '
 
@@ -744,8 +777,10 @@ test_expect_success 'git pull --rebase does not reapply old patches' '
 test_expect_success 'git pull --rebase against local branch' '
 	git checkout -b copy2 to-rebase-orig &&
 	git pull --rebase . to-rebase &&
-	test "conflicting modification" = "$(cat file)" &&
-	test file = "$(cat file2)"
+	echo "conflicting modification" >expect &&
+	test_cmp expect file &&
+	echo file >expect &&
+	test_cmp expect file2
 '
 
 test_done
-- 
2.24.0.346.gee0de6d492
Previous: Denton LiuNext: Denton Liu
Message 113 of 116 in “t5520: various test cleanup”
  1. 00/12 t5520: various test cleanupDenton Liu, Oct 17, 2019
  2. 01/12 t5520: improve test styleDenton Liu, Oct 17, 2019
  3. 02/12 t5520: use sq for test case namesDenton Liu, Oct 17, 2019
  4. 03/12 t5520: let sed open its own inputDenton Liu, Oct 17, 2019
  5. 05/12 t5520: remove spaces after redirect operatorDenton Liu, Oct 17, 2019
  6. 04/12 t5520: replace test -f with test_path_is_fileDenton Liu, Oct 17, 2019
  7. Eric SunshineOct 17, 2019
  8. 5/12 t5520: replace test -f with test-lib functionsDenton Liu, Oct 17, 2019
  9. Eric SunshineOct 18, 2019
  10. 06/12 t5520: use test_line_count where possibleDenton Liu, Oct 17, 2019
  11. 07/12 t5520: replace test -{n,z} with test-lib functionsDenton Liu, Oct 17, 2019
  12. Eric SunshineOct 17, 2019
  13. 08/12 t5520: use test_cmp_rev where possibleDenton Liu, Oct 17, 2019
  14. Eric SunshineOct 17, 2019
  15. Denton LiuOct 18, 2019
  16. Eric SunshineOct 23, 2019
  17. 09/12 t5520: test single-line files by git with test_cmpDenton Liu, Oct 17, 2019
  18. Eric SunshineOct 17, 2019
  19. 10/12 t5520: don't put git in upstream of pipeDenton Liu, Oct 17, 2019
  20. 11/12 t5520: replace subshell cat comparison with test_cmpDenton Liu, Oct 17, 2019
  21. 12/12 t5520: replace `! git` with `test_must_fail git`Denton Liu, Oct 17, 2019
  22. 00/15 t5520: various test cleanupDenton Liu, Oct 18, 2019
  23. 01/15 t7408: replace `test_must_fail test_path_is_file`Denton Liu, Oct 18, 2019
  24. Johannes SixtOct 19, 2019
  25. 09/15 t5520: replace test -{n,z} with test-lib functionsDenton Liu, Oct 18, 2019
  26. 11/15 t5520: test single-line files by git with test_cmpDenton Liu, Oct 18, 2019
  27. 06/15 t5520: replace test -f with test-lib functionsDenton Liu, Oct 18, 2019
  28. 12/15 t5520: don't put git in upstream of pipeDenton Liu, Oct 18, 2019
  29. 14/15 t5520: remove redundant lines in test casesDenton Liu, Oct 18, 2019
  30. 15/15 t5520: replace `! git` with `test_must_fail git`Denton Liu, Oct 18, 2019
  31. 13/15 t5520: replace subshell cat comparison with test_cmpDenton Liu, Oct 18, 2019
  32. 10/15 t5520: use test_cmp_rev where possibleDenton Liu, Oct 18, 2019
  33. 08/15 t5520: use test_line_count where possibleDenton Liu, Oct 18, 2019
  34. 07/15 t5520: remove spaces after redirect operatorDenton Liu, Oct 18, 2019
  35. 05/15 t5520: let sed open its own inputDenton Liu, Oct 18, 2019
  36. 04/15 t5520: use sq for test case namesDenton Liu, Oct 18, 2019
  37. 03/15 t5520: improve test styleDenton Liu, Oct 18, 2019
  38. 02/15 t: teach test_cmp_rev to accept ! for not-equalsDenton Liu, Oct 18, 2019
  39. SZEDER GáborOct 18, 2019
  40. Denton LiuOct 18, 2019
  41. 00/14 t5520: various test cleanupDenton Liu, Oct 22, 2019
  42. 01/14 t: teach test_cmp_rev to accept ! for not-equalsDenton Liu, Oct 22, 2019
  43. 02/14 t5520: improve test styleDenton Liu, Oct 22, 2019
  44. 03/14 t5520: use sq for test case namesDenton Liu, Oct 22, 2019
  45. 04/14 t5520: let sed open its own inputDenton Liu, Oct 22, 2019
  46. 05/14 t5520: replace test -f with test-lib functionsDenton Liu, Oct 22, 2019
  47. 06/14 t5520: remove spaces after redirect operatorDenton Liu, Oct 22, 2019
  48. 07/14 t5520: use test_line_count where possibleDenton Liu, Oct 22, 2019
  49. 08/14 t5520: replace test -{n,z} with test-lib functionsDenton Liu, Oct 22, 2019
  50. 09/14 t5520: use test_cmp_rev where possibleDenton Liu, Oct 22, 2019
  51. 10/14 t5520: test single-line files by git with test_cmpDenton Liu, Oct 22, 2019
  52. 11/14 t5520: don't put git in upstream of pipeDenton Liu, Oct 22, 2019
  53. 12/14 t5520: replace subshell cat comparison with test_cmpDenton Liu, Oct 22, 2019
  54. 13/14 t5520: remove redundant lines in test casesDenton Liu, Oct 22, 2019
  55. 14/14 t5520: replace `! git` with `test_must_fail git`Denton Liu, Oct 22, 2019
  56. Denton LiuOct 24, 2019
  57. Junio C HamanoOct 25, 2019
  58. Denton LiuNov 4, 2019
  59. Junio C HamanoNov 6, 2019
  60. 00/14 t5520: various test cleanupDenton Liu, Nov 7, 2019
  61. 01/14 t: teach test_cmp_rev to accept ! for not-equalsDenton Liu, Nov 7, 2019
  62. Junio C HamanoNov 8, 2019
  63. Denton LiuNov 8, 2019
  64. Junio C HamanoNov 8, 2019
  65. Denton LiuNov 8, 2019
  66. Junio C HamanoNov 10, 2019
  67. 02/14 t5520: improve test styleDenton Liu, Nov 7, 2019
  68. 03/14 t5520: use sq for test case namesDenton Liu, Nov 7, 2019
  69. 04/14 t5520: let sed open its own inputDenton Liu, Nov 7, 2019
  70. 05/14 t5520: replace test -f with test-lib functionsDenton Liu, Nov 7, 2019
  71. 06/14 t5520: remove spaces after redirect operatorDenton Liu, Nov 7, 2019
  72. 07/14 t5520: use test_line_count where possibleDenton Liu, Nov 7, 2019
  73. 08/14 t5520: replace test -{n,z} with test-lib functionsDenton Liu, Nov 7, 2019
  74. 09/14 t5520: use test_cmp_rev where possibleDenton Liu, Nov 7, 2019
  75. 10/14 t5520: test single-line files by git with test_cmpDenton Liu, Nov 7, 2019
  76. 11/14 t5520: don't put git in upstream of pipeDenton Liu, Nov 7, 2019
  77. 12/14 t5520: replace subshell cat comparison with test_cmpDenton Liu, Nov 7, 2019
  78. 13/14 t5520: remove redundant lines in test casesDenton Liu, Nov 7, 2019
  79. 14/14 t5520: replace `! git` with `test_must_fail git`Denton Liu, Nov 7, 2019
  80. 00/14 t5520: various test cleanupDenton Liu, Nov 12, 2019
  81. 01/14 t: teach test_cmp_rev to accept ! for not-equalsDenton Liu, Nov 12, 2019
  82. Junio C HamanoNov 12, 2019
  83. fixup! t: teach test_cmp_rev to accept ! for not-equalsDenton Liu, Nov 12, 2019
  84. 02/14 t5520: improve test styleDenton Liu, Nov 12, 2019
  85. 03/14 t5520: use sq for test case namesDenton Liu, Nov 12, 2019
  86. 04/14 t5520: let sed open its own inputDenton Liu, Nov 12, 2019
  87. 05/14 t5520: replace test -f with test-lib functionsDenton Liu, Nov 12, 2019
  88. 06/14 t5520: remove spaces after redirect operatorDenton Liu, Nov 12, 2019
  89. 07/14 t5520: use test_line_count where possibleDenton Liu, Nov 12, 2019
  90. 08/14 t5520: replace test -{n,z} with test-lib functionsDenton Liu, Nov 12, 2019
  91. 09/14 t5520: use test_cmp_rev where possibleDenton Liu, Nov 12, 2019
  92. 10/14 t5520: test single-line files by git with test_cmpDenton Liu, Nov 12, 2019
  93. Junio C HamanoNov 12, 2019
  94. Denton LiuNov 12, 2019
  95. 11/14 t5520: don't put git in upstream of pipeDenton Liu, Nov 12, 2019
  96. 12/14 t5520: replace subshell cat comparison with test_cmpDenton Liu, Nov 12, 2019
  97. 13/14 t5520: remove redundant lines in test casesDenton Liu, Nov 12, 2019
  98. 14/14 t5520: replace `! git` with `test_must_fail git`Denton Liu, Nov 12, 2019
  99. 00/14 t5520: various test cleanupDenton Liu, Nov 12, 2019
  100. 01/14 t: teach test_cmp_rev to accept ! for not-equalsDenton Liu, Nov 12, 2019
  101. Junio C HamanoNov 13, 2019
  102. Denton LiuNov 14, 2019
  103. 02/14 t5520: improve test styleDenton Liu, Nov 12, 2019
  104. 03/14 t5520: use sq for test case namesDenton Liu, Nov 12, 2019
  105. 04/14 t5520: let sed open its own inputDenton Liu, Nov 12, 2019
  106. 05/14 t5520: replace test -f with test-lib functionsDenton Liu, Nov 12, 2019
  107. 06/14 t5520: remove spaces after redirect operatorDenton Liu, Nov 12, 2019
  108. 07/14 t5520: use test_line_count where possibleDenton Liu, Nov 12, 2019
  109. 08/14 t5520: replace test -{n,z} with test-lib functionsDenton Liu, Nov 12, 2019
  110. 09/14 t5520: use test_cmp_rev where possibleDenton Liu, Nov 12, 2019
  111. 10/14 t5520: test single-line files by git with test_cmpDenton Liu, Nov 12, 2019
  112. 11/14 t5520: don't put git in upstream of pipeDenton Liu, Nov 12, 2019
  113. 12/14 t5520: replace $(cat ...) comparison with test_cmpDenton Liu, Nov 12, 2019
  114. 13/14 t5520: remove redundant lines in test casesDenton Liu, Nov 12, 2019
  115. 14/14 t5520: replace `! git` with `test_must_fail git`Denton Liu, Nov 12, 2019
  116. Junio C HamanoNov 13, 2019

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.