diff mbox series

[07/15] t4011: abstract away SHA-1-specific constants

Message ID 20191005211209.18237-8-sandals@crustytoothpaste.net (mailing list archive)
State New, archived
Headers show
Series SHA-256 test fixes, part 6 | expand

Commit Message

brian m. carlson Oct. 5, 2019, 9:12 p.m. UTC
Adjust the test so that it computes variables for object IDs instead of
using hard-coded hashes.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
---
 t/t4011-diff-symlink.sh | 31 +++++++++++++++++++------------
 1 file changed, 19 insertions(+), 12 deletions(-)

Comments

Derrick Stolee Oct. 8, 2019, 12:21 p.m. UTC | #1
On 10/5/2019 5:12 PM, brian m. carlson wrote:
> Adjust the test so that it computes variables for object IDs instead of
> using hard-coded hashes.

[snip]

> @@ -137,14 +141,17 @@ test_expect_success SYMLINKS 'setup symlinks with attributes' '
>  '
>  
>  test_expect_success SYMLINKS 'symlinks do not respect userdiff config by path' '
> -	cat >expect <<-\EOF &&
> +	file=$(git rev-parse --short $(git hash-object file.bin)) &&
> +	link=$(git rev-parse --short \
> +		$(printf file.bin | git hash-object --stdin)) &&

Why this change from $(git hash-object file.bin) to
$(printf file.bin | git hash-object --stdin)?

For that matter, why are you using the "printf|git hash-object"
pattern throughout your change? Seems like an unnecessary hurdle
to me.

-Stolee
Bert Wesarg Oct. 8, 2019, 12:33 p.m. UTC | #2
On Tue, Oct 8, 2019 at 2:21 PM Derrick Stolee <stolee@gmail.com> wrote:
>
> On 10/5/2019 5:12 PM, brian m. carlson wrote:
> > Adjust the test so that it computes variables for object IDs instead of
> > using hard-coded hashes.
>
> [snip]
>
> > @@ -137,14 +141,17 @@ test_expect_success SYMLINKS 'setup symlinks with attributes' '
> >  '
> >
> >  test_expect_success SYMLINKS 'symlinks do not respect userdiff config by path' '
> > -     cat >expect <<-\EOF &&
> > +     file=$(git rev-parse --short $(git hash-object file.bin)) &&
> > +     link=$(git rev-parse --short \
> > +             $(printf file.bin | git hash-object --stdin)) &&
>
> Why this change from $(git hash-object file.bin) to
> $(printf file.bin | git hash-object --stdin)?

thats two different things. The first hashes the content of file
"file.bin". The second hashes the literal string "file.bin". To avoid
this confusion, may I suggest to use 'printf "%s" "file.bin"', so that
it is clear, that the literal string is meant in this context?

Bert

>
> For that matter, why are you using the "printf|git hash-object"
> pattern throughout your change? Seems like an unnecessary hurdle
> to me.
>
> -Stolee
Derrick Stolee Oct. 8, 2019, 12:38 p.m. UTC | #3
On 10/8/2019 8:33 AM, Bert Wesarg wrote:
> On Tue, Oct 8, 2019 at 2:21 PM Derrick Stolee <stolee@gmail.com> wrote:
>>
>> On 10/5/2019 5:12 PM, brian m. carlson wrote:
>>> Adjust the test so that it computes variables for object IDs instead of
>>> using hard-coded hashes.
>>
>> [snip]
>>
>>> @@ -137,14 +141,17 @@ test_expect_success SYMLINKS 'setup symlinks with attributes' '
>>>  '
>>>
>>>  test_expect_success SYMLINKS 'symlinks do not respect userdiff config by path' '
>>> -     cat >expect <<-\EOF &&
>>> +     file=$(git rev-parse --short $(git hash-object file.bin)) &&
>>> +     link=$(git rev-parse --short \
>>> +             $(printf file.bin | git hash-object --stdin)) &&
>>
>> Why this change from $(git hash-object file.bin) to
>> $(printf file.bin | git hash-object --stdin)?
> 
> thats two different things. The first hashes the content of file
> "file.bin". The second hashes the literal string "file.bin". To avoid
> this confusion, may I suggest to use 'printf "%s" "file.bin"', so that
> it is clear, that the literal string is meant in this context?

Ah, and because the resulting hash is for the contents of the symlink
(not the contents of the file), it makes sense to use printf here.

Thanks for the clarification!

-Stolee
brian m. carlson Oct. 8, 2019, 7:40 p.m. UTC | #4
On 2019-10-08 at 12:33:43, Bert Wesarg wrote:
> On Tue, Oct 8, 2019 at 2:21 PM Derrick Stolee <stolee@gmail.com> wrote:
> >
> > On 10/5/2019 5:12 PM, brian m. carlson wrote:
> > > Adjust the test so that it computes variables for object IDs instead of
> > > using hard-coded hashes.
> >
> > [snip]
> >
> > > @@ -137,14 +141,17 @@ test_expect_success SYMLINKS 'setup symlinks with attributes' '
> > >  '
> > >
> > >  test_expect_success SYMLINKS 'symlinks do not respect userdiff config by path' '
> > > -     cat >expect <<-\EOF &&
> > > +     file=$(git rev-parse --short $(git hash-object file.bin)) &&
> > > +     link=$(git rev-parse --short \
> > > +             $(printf file.bin | git hash-object --stdin)) &&
> >
> > Why this change from $(git hash-object file.bin) to
> > $(printf file.bin | git hash-object --stdin)?
> 
> thats two different things. The first hashes the content of file
> "file.bin". The second hashes the literal string "file.bin". To avoid
> this confusion, may I suggest to use 'printf "%s" "file.bin"', so that
> it is clear, that the literal string is meant in this context?

This is completely correct, and, yes, I can definitely make that change.
In fact, the fact that this is confusing probably means I should use a
suitably named shell function for this, so I'll make that change when I
reroll.

> > For that matter, why are you using the "printf|git hash-object"
> > pattern throughout your change? Seems like an unnecessary hurdle
> > to me.

I would normally use echo for these types of things (because that's our
style and it's more customary), but in this case the symlink contents
don't contain a newline, so printf is required.
diff mbox series

Patch

diff --git a/t/t4011-diff-symlink.sh b/t/t4011-diff-symlink.sh
index 5ae19b987d..b6934da266 100755
--- a/t/t4011-diff-symlink.sh
+++ b/t/t4011-diff-symlink.sh
@@ -10,10 +10,12 @@  test_description='Test diff of symlinks.
 . "$TEST_DIRECTORY"/diff-lib.sh
 
 test_expect_success 'diff new symlink and file' '
-	cat >expected <<-\EOF &&
+	symlink=$(git rev-parse --short \
+		$(printf xyzzy | git hash-object --stdin)) &&
+	cat >expected <<-EOF &&
 	diff --git a/frotz b/frotz
 	new file mode 120000
-	index 0000000..7c465af
+	index 0000000..$symlink
 	--- /dev/null
 	+++ b/frotz
 	@@ -0,0 +1 @@
@@ -21,7 +23,7 @@  test_expect_success 'diff new symlink and file' '
 	\ No newline at end of file
 	diff --git a/nitfol b/nitfol
 	new file mode 100644
-	index 0000000..7c465af
+	index 0000000..$symlink
 	--- /dev/null
 	+++ b/nitfol
 	@@ -0,0 +1 @@
@@ -46,10 +48,10 @@  test_expect_success 'diff unchanged symlink and file'  '
 '
 
 test_expect_success 'diff removed symlink and file' '
-	cat >expected <<-\EOF &&
+	cat >expected <<-EOF &&
 	diff --git a/frotz b/frotz
 	deleted file mode 120000
-	index 7c465af..0000000
+	index $symlink..0000000
 	--- a/frotz
 	+++ /dev/null
 	@@ -1 +0,0 @@
@@ -57,7 +59,7 @@  test_expect_success 'diff removed symlink and file' '
 	\ No newline at end of file
 	diff --git a/nitfol b/nitfol
 	deleted file mode 100644
-	index 7c465af..0000000
+	index $symlink..0000000
 	--- a/nitfol
 	+++ /dev/null
 	@@ -1 +0,0 @@
@@ -90,9 +92,11 @@  test_expect_success 'diff identical, but newly created symlink and file' '
 '
 
 test_expect_success 'diff different symlink and file' '
-	cat >expected <<-\EOF &&
+	new=$(git rev-parse --short \
+		$(printf yxyyz | git hash-object --stdin)) &&
+	cat >expected <<-EOF &&
 	diff --git a/frotz b/frotz
-	index 7c465af..df1db54 120000
+	index $symlink..$new 120000
 	--- a/frotz
 	+++ b/frotz
 	@@ -1 +1 @@
@@ -101,7 +105,7 @@  test_expect_success 'diff different symlink and file' '
 	+yxyyz
 	\ No newline at end of file
 	diff --git a/nitfol b/nitfol
-	index 7c465af..df1db54 100644
+	index $symlink..$new 100644
 	--- a/nitfol
 	+++ b/nitfol
 	@@ -1 +1 @@
@@ -137,14 +141,17 @@  test_expect_success SYMLINKS 'setup symlinks with attributes' '
 '
 
 test_expect_success SYMLINKS 'symlinks do not respect userdiff config by path' '
-	cat >expect <<-\EOF &&
+	file=$(git rev-parse --short $(git hash-object file.bin)) &&
+	link=$(git rev-parse --short \
+		$(printf file.bin | git hash-object --stdin)) &&
+	cat >expect <<-EOF &&
 	diff --git a/file.bin b/file.bin
 	new file mode 100644
-	index 0000000..d95f3ad
+	index 0000000..$file
 	Binary files /dev/null and b/file.bin differ
 	diff --git a/link.bin b/link.bin
 	new file mode 120000
-	index 0000000..dce41ec
+	index 0000000..$link
 	--- /dev/null
 	+++ b/link.bin
 	@@ -0,0 +1 @@