diff mbox series

[2/6] t3433: remove loops from tests

Message ID 20200407141125.30872-3-phillip.wood123@gmail.com (mailing list archive)
State New, archived
Headers show
Series fixup ra/rebase-i-more-options | expand

Commit Message

Phillip Wood April 7, 2020, 2:11 p.m. UTC
From: Phillip Wood <phillip.wood@dunelm.org.uk>

Looping inside a test is asking for trouble as we only detect any
failure on the last iteration. Instead get all the dates at once which
is also more efficient. Note the previous code accidentally compared the
diffs as well as the dates this is fixed as well.

Signed-off-by: Phillip Wood <phillip.wood@dunelm.org.uk>
---
 t/t3433-rebase-options-compatibility.sh | 18 +++++-------------
 1 file changed, 5 insertions(+), 13 deletions(-)

Comments

Elijah Newren April 7, 2020, 2:30 p.m. UTC | #1
On Tue, Apr 7, 2020 at 7:11 AM Phillip Wood <phillip.wood123@gmail.com> wrote:
>
> From: Phillip Wood <phillip.wood@dunelm.org.uk>
>
> Looping inside a test is asking for trouble as we only detect any
> failure on the last iteration. Instead get all the dates at once which
> is also more efficient. Note the previous code accidentally compared the
> diffs as well as the dates this is fixed as well.

Add a semicolon between "dates" and "this" in the last sentence?

>
> Signed-off-by: Phillip Wood <phillip.wood@dunelm.org.uk>
> ---
>  t/t3433-rebase-options-compatibility.sh | 18 +++++-------------
>  1 file changed, 5 insertions(+), 13 deletions(-)
>
> diff --git a/t/t3433-rebase-options-compatibility.sh b/t/t3433-rebase-options-compatibility.sh
> index 5166f158dd..2b4d75f1ef 100755
> --- a/t/t3433-rebase-options-compatibility.sh
> +++ b/t/t3433-rebase-options-compatibility.sh
> @@ -90,13 +90,9 @@ test_expect_success '--committer-date-is-author-date works with rebase -r' '
>         git checkout side &&
>         git merge --no-ff commit3 &&
>         git rebase -r --root --committer-date-is-author-date &&
> -       git rev-list HEAD >rev_list &&
> -       while read HASH
> -       do
> -               git show $HASH --pretty="format:%ai" >authortime
> -               git show $HASH --pretty="format:%ci" >committertime
> -               test_cmp authortime committertime
> -       done <rev_list
> +       git log --pretty="format:%ai" >authortime &&
> +       git log --pretty="format:%ci" >committertime &&
> +       test_cmp authortime committertime
>  '
>
>  # Checking for +0000 in author time is enough since default
> @@ -120,12 +116,8 @@ test_expect_success '--ignore-date works with rebase -r' '
>         git checkout side &&
>         git merge --no-ff commit3 &&
>         git rebase -r --root --ignore-date &&
> -       git rev-list HEAD >rev_list &&
> -       while read HASH
> -       do
> -               git show $HASH --pretty="format:%ai" >authortime
> -               grep "+0000" authortime
> -       done <rev_list
> +       git log --pretty=%ai >authortime &&
> +       ! grep -v "+0000" authortime
>  '

The new form is much more readable (and more correct and efficient, as
you point out).  Thanks.
diff mbox series

Patch

diff --git a/t/t3433-rebase-options-compatibility.sh b/t/t3433-rebase-options-compatibility.sh
index 5166f158dd..2b4d75f1ef 100755
--- a/t/t3433-rebase-options-compatibility.sh
+++ b/t/t3433-rebase-options-compatibility.sh
@@ -90,13 +90,9 @@  test_expect_success '--committer-date-is-author-date works with rebase -r' '
 	git checkout side &&
 	git merge --no-ff commit3 &&
 	git rebase -r --root --committer-date-is-author-date &&
-	git rev-list HEAD >rev_list &&
-	while read HASH
-	do
-		git show $HASH --pretty="format:%ai" >authortime
-		git show $HASH --pretty="format:%ci" >committertime
-		test_cmp authortime committertime
-	done <rev_list
+	git log --pretty="format:%ai" >authortime &&
+	git log --pretty="format:%ci" >committertime &&
+	test_cmp authortime committertime
 '
 
 # Checking for +0000 in author time is enough since default
@@ -120,12 +116,8 @@  test_expect_success '--ignore-date works with rebase -r' '
 	git checkout side &&
 	git merge --no-ff commit3 &&
 	git rebase -r --root --ignore-date &&
-	git rev-list HEAD >rev_list &&
-	while read HASH
-	do
-		git show $HASH --pretty="format:%ai" >authortime
-		grep "+0000" authortime
-	done <rev_list
+	git log --pretty=%ai >authortime &&
+	! grep -v "+0000" authortime
 '
 
 test_done