@matheusbsbs / matheus-bagliano / commits / 9291e6329e
Fork 0

t1507: run commands within test_expect_success

The expected test style is to have all commands tested within a test_expect_success block. Move the generation of the 'expect' text into their corresponding blocks. While we're at it, insert a second `commit=$(git rev-parse HEAD)` into the next test case so that it's clear where $commit is coming from. The biggest advantage of doing this is that we now check the return code of `git rev-parse HEAD` so we can catch it in case it fails. This patch is best viewed with `--color-moved --ignore-all-space`. Signed-off-by: Denton Liu <liu.denton@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Denton Liu committed Dec 20, 2019 at 10:16 UTC 9291e6329ef3333f9447b0b4cdec0607e00c39cf
1 file changed +20 -20
t/t1507-rev-parse-upstream.sh
+20 -20
@@ -225,32 +225,32 @@ test_expect_success '@{u} works when tracking a local branch' '
225 test_cmp expect actual
226 '
227
228 -commit=$(git rev-parse HEAD)
229 -cat >expect <<EOF
230 -commit $commit
231 -Reflog: master@{0} (C O Mitter <committer@example.com>)
232 -Reflog message: branch: Created from HEAD
233 -Author: A U Thor <author@example.com>
234 -Date: Thu Apr 7 15:15:13 2005 -0700
235 -
236 - 3
237 -EOF
228 test_expect_success 'log -g other@{u}' '
229 + commit=$(git rev-parse HEAD) &&
230 + cat >expect <<-EOF &&
231 + commit $commit
232 + Reflog: master@{0} (C O Mitter <committer@example.com>)
233 + Reflog message: branch: Created from HEAD
234 + Author: A U Thor <author@example.com>
235 + Date: Thu Apr 7 15:15:13 2005 -0700
236 +
237 + 3
238 + EOF
239 git log -1 -g other@{u} >actual &&
240 test_cmp expect actual
241 '
242
243 -cat >expect <<EOF
244 -commit $commit
245 -Reflog: master@{Thu Apr 7 15:17:13 2005 -0700} (C O Mitter <committer@example.com>)
246 -Reflog message: branch: Created from HEAD
247 -Author: A U Thor <author@example.com>
248 -Date: Thu Apr 7 15:15:13 2005 -0700
249 -
250 - 3
251 -EOF
252 -
243 test_expect_success 'log -g other@{u}@{now}' '
244 + commit=$(git rev-parse HEAD) &&
245 + cat >expect <<-EOF &&
246 + commit $commit
247 + Reflog: master@{Thu Apr 7 15:17:13 2005 -0700} (C O Mitter <committer@example.com>)
248 + Reflog message: branch: Created from HEAD
249 + Author: A U Thor <author@example.com>
250 + Date: Thu Apr 7 15:15:13 2005 -0700
251 +
252 + 3
253 + EOF
254 git log -1 -g other@{u}@{now} >actual &&
255 test_cmp expect actual
256 '