@matheusbsbs / matheus-bagliano / commits / a1a64fdd0a
Fork 0

t5520: replace $(cat ...) comparison with test_cmp

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> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Denton Liu committed Nov 12, 2019 at 15:08 UTC a1a64fdd0aa6e3fd450c06885f30225ebea6b74f
1 file changed +70 -35
t/t5520-pull.sh
+70 -35
@@ -15,8 +15,10 @@ test_pull_autostash () {
15 git add new_file &&
16 git pull "$@" . copy &&
17 test_cmp_rev HEAD^ copy &&
18 - test "$(cat new_file)" = dirty &&
19 - test "$(cat file)" = "modified again"
18 + echo dirty >expect &&
19 + test_cmp expect new_file &&
20 + echo "modified again" >expect &&
21 + test_cmp expect file
22 }
23
24 test_pull_autostash_fail () {
@@ -110,9 +112,11 @@ test_expect_success 'test . as a remote' '
112 echo updated >file &&
113 git commit -a -m updated &&
114 git checkout copy &&
113 - test "$(cat file)" = file &&
115 + echo file >expect &&
116 + test_cmp expect file &&
117 git pull &&
115 - test "$(cat file)" = updated &&
118 + echo updated >expect &&
119 + test_cmp expect file &&
120 git reflog -1 >reflog.actual &&
121 sed "s/^[0-9a-f][0-9a-f]*/OBJID/" reflog.actual >reflog.fuzzy &&
122 echo "OBJID HEAD@{0}: pull: Fast-forward" >reflog.expected &&
@@ -125,9 +129,11 @@ test_expect_success 'the default remote . should not break explicit pull' '
129 git commit -a -m modified &&
130 git checkout copy &&
131 git reset --hard HEAD^ &&
128 - test "$(cat file)" = file &&
132 + echo file >expect &&
133 + test_cmp expect file &&
134 git pull . second &&
130 - test "$(cat file)" = modified &&
135 + echo modified >expect &&
136 + test_cmp expect file &&
137 git reflog -1 >reflog.actual &&
138 sed "s/^[0-9a-f][0-9a-f]*/OBJID/" reflog.actual >reflog.fuzzy &&
139 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' '
143 test_expect_success 'fail if wildcard spec does not match any refs' '
144 git checkout -b test copy^ &&
145 test_when_finished "git checkout -f copy && git branch -D test" &&
140 - test "$(cat file)" = file &&
146 + echo file >expect &&
147 + test_cmp expect file &&
148 test_must_fail git pull . "refs/nonexisting1/*:refs/nonexisting2/*" 2>err &&
149 test_i18ngrep "no candidates for merging" err &&
143 - test "$(cat file)" = file
150 + echo file >expect &&
151 + test_cmp expect file
152 '
153
154 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' '
156 test_when_finished "git remote remove test_remote" &&
157 git checkout -b test copy^ &&
158 test_when_finished "git checkout -f copy && git branch -D test" &&
151 - test "$(cat file)" = file &&
159 + echo file >expect &&
160 + test_cmp expect file &&
161 test_config branch.test.remote origin &&
162 test_must_fail git pull test_remote 2>err &&
163 test_i18ngrep "specify a branch on the command line" err &&
155 - test "$(cat file)" = file
164 + echo file >expect &&
165 + test_cmp expect file
166 '
167
168 test_expect_success 'fail if not on a branch' '
@@ -160,10 +170,12 @@ test_expect_success 'fail if not on a branch' '
170 test_when_finished "git remote remove origin" &&
171 git checkout HEAD^ &&
172 test_when_finished "git checkout -f copy" &&
163 - test "$(cat file)" = file &&
173 + echo file >expect &&
174 + test_cmp expect file &&
175 test_must_fail git pull 2>err &&
176 test_i18ngrep "not currently on a branch" err &&
166 - test "$(cat file)" = file
177 + echo file >expect &&
178 + test_cmp expect file
179 '
180
181 test_expect_success 'fail if no configuration for current branch' '
@@ -172,10 +184,12 @@ test_expect_success 'fail if no configuration for current branch' '
184 git checkout -b test copy^ &&
185 test_when_finished "git checkout -f copy && git branch -D test" &&
186 test_config branch.test.remote test_remote &&
175 - test "$(cat file)" = file &&
187 + echo file >expect &&
188 + test_cmp expect file &&
189 test_must_fail git pull 2>err &&
190 test_i18ngrep "no tracking information" err &&
178 - test "$(cat file)" = file
191 + echo file >expect &&
192 + test_cmp expect file
193 '
194
195 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' '
198 git checkout -b test copy^ &&
199 test_when_finished "git checkout -f copy && git branch -D test" &&
200 test_config branch.test.remote test_remote &&
187 - test "$(cat file)" = file &&
201 + echo file >expect &&
202 + test_cmp expect file &&
203 test_must_fail git pull --all 2>err &&
204 test_i18ngrep "There is no tracking information" err &&
190 - test "$(cat file)" = file
205 + echo file >expect &&
206 + test_cmp expect file
207 '
208
209 test_expect_success 'fail if upstream branch does not exist' '
@@ -195,16 +211,19 @@ test_expect_success 'fail if upstream branch does not exist' '
211 test_when_finished "git checkout -f copy && git branch -D test" &&
212 test_config branch.test.remote . &&
213 test_config branch.test.merge refs/heads/nonexisting &&
198 - test "$(cat file)" = file &&
214 + echo file >expect &&
215 + test_cmp expect file &&
216 test_must_fail git pull 2>err &&
217 test_i18ngrep "no such ref was fetched" err &&
201 - test "$(cat file)" = file
218 + echo file >expect &&
219 + test_cmp expect file
220 '
221
222 test_expect_success 'fail if the index has unresolved entries' '
223 git checkout -b third second^ &&
224 test_when_finished "git checkout -f copy && git branch -D third" &&
207 - test "$(cat file)" = file &&
225 + echo file >expect &&
226 + test_cmp expect file &&
227 test_commit modified2 file &&
228 git ls-files -u >unmerged &&
229 test_must_be_empty unmerged &&
@@ -226,21 +245,25 @@ test_expect_success 'fail if the index has unresolved entries' '
245 test_expect_success 'fast-forwards working tree if branch head is updated' '
246 git checkout -b third second^ &&
247 test_when_finished "git checkout -f copy && git branch -D third" &&
229 - test "$(cat file)" = file &&
248 + echo file >expect &&
249 + test_cmp expect file &&
250 git pull . second:third 2>err &&
251 test_i18ngrep "fetch updated the current branch head" err &&
232 - test "$(cat file)" = modified &&
252 + echo modified >expect &&
253 + test_cmp expect file &&
254 test_cmp_rev third second
255 '
256
257 test_expect_success 'fast-forward fails with conflicting work tree' '
258 git checkout -b third second^ &&
259 test_when_finished "git checkout -f copy && git branch -D third" &&
239 - test "$(cat file)" = file &&
260 + echo file >expect &&
261 + test_cmp expect file &&
262 echo conflict >file &&
263 test_must_fail git pull . second:third 2>err &&
264 test_i18ngrep "Cannot fast-forward your working tree" err &&
243 - test "$(cat file)" = conflict &&
265 + echo conflict >expect &&
266 + test_cmp expect file &&
267 test_cmp_rev third second
268 '
269
@@ -501,7 +524,8 @@ test_expect_success 'pull.rebase=interactive' '
524 test_set_editor "$TRASH_DIRECTORY/fake-editor" &&
525 test_when_finished "test_might_fail git rebase --abort" &&
526 test_must_fail git pull --rebase=interactive . copy &&
504 - test "I was here" = "$(cat fake.out)"
527 + echo "I was here" >expect &&
528 + test_cmp expect fake.out
529 '
530
531 test_expect_success 'pull --rebase=i' '
@@ -512,7 +536,8 @@ test_expect_success 'pull --rebase=i' '
536 test_set_editor "$TRASH_DIRECTORY/fake-editor" &&
537 test_when_finished "test_might_fail git rebase --abort" &&
538 test_must_fail git pull --rebase=i . copy &&
515 - test "I was here, too" = "$(cat fake.out)"
539 + echo "I was here, too" >expect &&
540 + test_cmp expect fake.out
541 '
542
543 test_expect_success 'pull.rebase=invalid fails' '
@@ -578,16 +603,20 @@ test_expect_success '--rebase with rebased upstream' '
603 git commit -m to-rebase file2 &&
604 git tag to-rebase-orig &&
605 git pull --rebase me copy &&
581 - test "conflicting modification" = "$(cat file)" &&
582 - test file = "$(cat file2)"
606 + echo "conflicting modification" >expect &&
607 + test_cmp expect file &&
608 + echo file >expect &&
609 + test_cmp expect file2
610 '
611
612 test_expect_success '--rebase -f with rebased upstream' '
613 test_when_finished "test_might_fail git rebase --abort" &&
614 git reset --hard to-rebase-orig &&
615 git pull --rebase -f me copy &&
589 - test "conflicting modification" = "$(cat file)" &&
590 - test file = "$(cat file2)"
616 + echo "conflicting modification" >expect &&
617 + test_cmp expect file &&
618 + echo file >expect &&
619 + test_cmp expect file2
620 '
621
622 test_expect_success '--rebase with rebased default upstream' '
@@ -595,8 +624,10 @@ test_expect_success '--rebase with rebased default upstream' '
624 git checkout --track -b to-rebase2 me/copy &&
625 git reset --hard to-rebase-orig &&
626 git pull --rebase &&
598 - test "conflicting modification" = "$(cat file)" &&
599 - test file = "$(cat file2)"
627 + echo "conflicting modification" >expect &&
628 + test_cmp expect file &&
629 + echo file >expect &&
630 + test_cmp expect file2
631 '
632
633 test_expect_success 'rebased upstream + fetch + pull --rebase' '
@@ -607,8 +638,10 @@ test_expect_success 'rebased upstream + fetch + pull --rebase' '
638 git reset --hard to-rebase-orig &&
639 git fetch &&
640 git pull --rebase &&
610 - test "conflicting modification" = "$(cat file)" &&
611 - test file = "$(cat file2)"
641 + echo "conflicting modification" >expect &&
642 + test_cmp expect file &&
643 + echo file >expect &&
644 + test_cmp expect file2
645
646 '
647
@@ -744,8 +777,10 @@ test_expect_success 'git pull --rebase does not reapply old patches' '
777 test_expect_success 'git pull --rebase against local branch' '
778 git checkout -b copy2 to-rebase-orig &&
779 git pull --rebase . to-rebase &&
747 - test "conflicting modification" = "$(cat file)" &&
748 - test file = "$(cat file2)"
780 + echo "conflicting modification" >expect &&
781 + test_cmp expect file &&
782 + echo file >expect &&
783 + test_cmp expect file2
784 '
785
786 test_done