diff mbox series

[v4,1/8] t5504: modernize test by moving heredocs into test bodies

Message ID 20250131-pks-push-atomic-respect-exit-code-v4-1-a8b41f01a676@pks.im (mailing list archive)
State Superseded
Headers show
Series transport: don't ignore git-receive-pack(1) exit code on atomic push | expand

Commit Message

Patrick Steinhardt Jan. 31, 2025, 10:53 a.m. UTC
We have several heredocs in t5504 located outside of any particular test
bodies. Move these into the test bodies to match our modern coding
style.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
 t/t5504-fetch-receive-strict.sh | 35 ++++++++++++++++-------------------
 1 file changed, 16 insertions(+), 19 deletions(-)

Comments

Eric Sunshine Jan. 31, 2025, 2:28 p.m. UTC | #1
On Fri, Jan 31, 2025 at 5:53 AM Patrick Steinhardt <ps@pks.im> wrote:
> We have several heredocs in t5504 located outside of any particular test
> bodies. Move these into the test bodies to match our modern coding
> style.
>
> Signed-off-by: Patrick Steinhardt <ps@pks.im>
> ---
> diff --git a/t/t5504-fetch-receive-strict.sh b/t/t5504-fetch-receive-strict.sh
> @@ -64,12 +64,6 @@ test_expect_success 'fetch with transfer.fsckobjects' '
> -cat >exp <<EOF
> -To dst
> -!      refs/heads/main:refs/heads/test [remote rejected] (missing necessary objects)
> -Done
> -EOF
> -
>  test_expect_success 'push without strict' '
> @@ -78,6 +72,11 @@ test_expect_success 'push without strict' '
> +       cat >exp <<-EOF &&
> +       To dst
> +       !       refs/heads/main:refs/heads/test [remote rejected] (missing necessary objects)
> +       Done
> +       EOF

It's minor, but to make this conform to modern style even more, it
would use `\EOF` rather than `EOF`.

(Probably not worth a reroll on its own.)

> @@ -94,11 +93,6 @@ test_expect_success 'push with !receive.fsckobjects' '
> -cat >exp <<EOF
> -To dst
> -!      refs/heads/main:refs/heads/test [remote rejected] (unpacker error)
> -EOF
> -
>  test_expect_success 'push with receive.fsckobjects' '
> @@ -107,6 +101,10 @@ test_expect_success 'push with receive.fsckobjects' '
> +       cat >exp <<-EOF &&
> +       To dst
> +       !       refs/heads/main:refs/heads/test [remote rejected] (unpacker error)
> +       EOF

Ditto.

> @@ -129,15 +127,14 @@ test_expect_success 'repair the "corrupt or missing" object' '
> -cat >bogus-commit <<EOF
> -tree $EMPTY_TREE
> -author Bugs Bunny 1234567890 +0000
> -committer Bugs Bunny <bugs@bun.ni> 1234567890 +0000
> -
> -This commit object intentionally broken
> -EOF
> -
>  test_expect_success 'setup bogus commit' '
> +       cat >bogus-commit <<-EOF &&
> +       tree $EMPTY_TREE
> +       author Bugs Bunny 1234567890 +0000
> +       committer Bugs Bunny <bugs@bun.ni> 1234567890 +0000
> +
> +       This commit object intentionally broken
> +       EOF

This one is correctly using `EOF` since it's interpolating variables.
Junio C Hamano Jan. 31, 2025, 4:26 p.m. UTC | #2
Eric Sunshine <sunshine@sunshineco.com> writes:

>> @@ -78,6 +72,11 @@ test_expect_success 'push without strict' '
>> +       cat >exp <<-EOF &&
>> +       To dst
>> +       !       refs/heads/main:refs/heads/test [remote rejected] (missing necessary objects)
>> +       Done
>> +       EOF
>
> It's minor, but to make this conform to modern style even more, it
> would use `\EOF` rather than `EOF`.
>
> (Probably not worth a reroll on its own.)

Yup.  The rule of thumb is to quote the end-of-heredoc marker when
the here-doc does not need interpolation, to serve as a hint to tell
the readers that the here-doc is a literal text.
Patrick Steinhardt Feb. 3, 2025, 6:04 a.m. UTC | #3
On Fri, Jan 31, 2025 at 09:28:01AM -0500, Eric Sunshine wrote:
> On Fri, Jan 31, 2025 at 5:53 AM Patrick Steinhardt <ps@pks.im> wrote:
> > We have several heredocs in t5504 located outside of any particular test
> > bodies. Move these into the test bodies to match our modern coding
> > style.
> >
> > Signed-off-by: Patrick Steinhardt <ps@pks.im>
> > ---
> > diff --git a/t/t5504-fetch-receive-strict.sh b/t/t5504-fetch-receive-strict.sh
> > @@ -64,12 +64,6 @@ test_expect_success 'fetch with transfer.fsckobjects' '
> > -cat >exp <<EOF
> > -To dst
> > -!      refs/heads/main:refs/heads/test [remote rejected] (missing necessary objects)
> > -Done
> > -EOF
> > -
> >  test_expect_success 'push without strict' '
> > @@ -78,6 +72,11 @@ test_expect_success 'push without strict' '
> > +       cat >exp <<-EOF &&
> > +       To dst
> > +       !       refs/heads/main:refs/heads/test [remote rejected] (missing necessary objects)
> > +       Done
> > +       EOF
> 
> It's minor, but to make this conform to modern style even more, it
> would use `\EOF` rather than `EOF`.

Yup, indeed. Will fix, thanks for your review!

Patrick
diff mbox series

Patch

diff --git a/t/t5504-fetch-receive-strict.sh b/t/t5504-fetch-receive-strict.sh
index e273ab29c7..29f18841c3 100755
--- a/t/t5504-fetch-receive-strict.sh
+++ b/t/t5504-fetch-receive-strict.sh
@@ -64,12 +64,6 @@  test_expect_success 'fetch with transfer.fsckobjects' '
 	)
 '
 
-cat >exp <<EOF
-To dst
-!	refs/heads/main:refs/heads/test	[remote rejected] (missing necessary objects)
-Done
-EOF
-
 test_expect_success 'push without strict' '
 	rm -rf dst &&
 	git init dst &&
@@ -78,6 +72,11 @@  test_expect_success 'push without strict' '
 		git config fetch.fsckobjects false &&
 		git config transfer.fsckobjects false
 	) &&
+	cat >exp <<-EOF &&
+	To dst
+	!	refs/heads/main:refs/heads/test	[remote rejected] (missing necessary objects)
+	Done
+	EOF
 	test_must_fail git push --porcelain dst main:refs/heads/test >act &&
 	test_cmp exp act
 '
@@ -94,11 +93,6 @@  test_expect_success 'push with !receive.fsckobjects' '
 	test_cmp exp act
 '
 
-cat >exp <<EOF
-To dst
-!	refs/heads/main:refs/heads/test	[remote rejected] (unpacker error)
-EOF
-
 test_expect_success 'push with receive.fsckobjects' '
 	rm -rf dst &&
 	git init dst &&
@@ -107,6 +101,10 @@  test_expect_success 'push with receive.fsckobjects' '
 		git config receive.fsckobjects true &&
 		git config transfer.fsckobjects false
 	) &&
+	cat >exp <<-EOF &&
+	To dst
+	!	refs/heads/main:refs/heads/test	[remote rejected] (unpacker error)
+	EOF
 	test_must_fail git push --porcelain dst main:refs/heads/test >act &&
 	test_cmp exp act
 '
@@ -129,15 +127,14 @@  test_expect_success 'repair the "corrupt or missing" object' '
 	git fsck
 '
 
-cat >bogus-commit <<EOF
-tree $EMPTY_TREE
-author Bugs Bunny 1234567890 +0000
-committer Bugs Bunny <bugs@bun.ni> 1234567890 +0000
-
-This commit object intentionally broken
-EOF
-
 test_expect_success 'setup bogus commit' '
+	cat >bogus-commit <<-EOF &&
+	tree $EMPTY_TREE
+	author Bugs Bunny 1234567890 +0000
+	committer Bugs Bunny <bugs@bun.ni> 1234567890 +0000
+
+	This commit object intentionally broken
+	EOF
 	commit="$(git hash-object --literally -t commit -w --stdin <bogus-commit)"
 '