Re: [PATCH v8 4/4] t1006: add tests for git cat-file --literally

2015-04-17 Thread karthik nayak


On 04/18/2015 05:30 AM, Eric Sunshine wrote:

On Wed, Apr 15, 2015 at 1:00 PM, Karthik Nayak karthik@gmail.com wrote:
 Signed-off-by: Karthik Nayak karthik@gmail.com
 ---
 diff --git a/t/t1006-cat-file.sh b/t/t1006-cat-file.sh
 index ab36b1e..61fab78 100755
 --- a/t/t1006-cat-file.sh
 +++ b/t/t1006-cat-file.sh
 @@ -296,4 +308,21 @@ test_expect_success '%(deltabase) reports packed delta 
bases' '
  }
   '

 +bogus_type=bogus
 +bogus_content=bogus
 +bogus_size=$(strlen $bogus_content)

If someone ever changes the value of 'bogus_content' so it contains
whitespace, then the result of strlen() will be incorrect as you've
invoked it. You should quote its argument (as other callers in this
script do) to safeguard against such an issue.

 bogus_size=$(strlen $bogus_content)

 +bogus_sha1=$(printf $bogus_content | git hash-object -t $bogus_type 
--literally -w --stdin)

Ditto regarding quoting of 'bogus_content'.

Also, if someone ever modifies 'bogus_content' so that it contains a
literal '%' (such as %s), then your printf() invocation will
misbehave. Either call it like this:

 $(printf '%s' $bogus_content | ...)

or, better yet, call echo_without_newline() as other similar code
elsewhere in this script does, and as suggested earlier[1].

[1]: http://article.gmane.org/gmane.comp.version-control.git/266972/

 +test_expect_success Type of broken object is correct '
 +   echo $bogus_type expect 
 +   git cat-file -t --literally $bogus_sha1 actual 
 +   test_cmp expect actual
 +'
 +
 +test_expect_success Size of broken object is correct '
 +echo $bogus_size expect 

Bad indentation. Use tab rather than spaces.

 +   git cat-file -s --literally $bogus_sha1 actual 
 +   test_cmp expect actual
 +'
 +
   test_done
 --
 2.4.0.rc1.249.gb598846

Thanks Eric for the changes. I did echo -n at the beginning but that
gave me a warning and asked me to use printf instead. I'll use
echo_without_newline, Thanks.
--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v8 4/4] t1006: add tests for git cat-file --literally

2015-04-17 Thread Eric Sunshine
On Wed, Apr 15, 2015 at 1:00 PM, Karthik Nayak karthik@gmail.com wrote:
 Signed-off-by: Karthik Nayak karthik@gmail.com
 ---
 diff --git a/t/t1006-cat-file.sh b/t/t1006-cat-file.sh
 index ab36b1e..61fab78 100755
 --- a/t/t1006-cat-file.sh
 +++ b/t/t1006-cat-file.sh
 @@ -296,4 +308,21 @@ test_expect_success '%(deltabase) reports packed delta 
 bases' '
 }
  '

 +bogus_type=bogus
 +bogus_content=bogus
 +bogus_size=$(strlen $bogus_content)

If someone ever changes the value of 'bogus_content' so it contains
whitespace, then the result of strlen() will be incorrect as you've
invoked it. You should quote its argument (as other callers in this
script do) to safeguard against such an issue.

bogus_size=$(strlen $bogus_content)

 +bogus_sha1=$(printf $bogus_content | git hash-object -t $bogus_type 
 --literally -w --stdin)

Ditto regarding quoting of 'bogus_content'.

Also, if someone ever modifies 'bogus_content' so that it contains a
literal '%' (such as %s), then your printf() invocation will
misbehave. Either call it like this:

$(printf '%s' $bogus_content | ...)

or, better yet, call echo_without_newline() as other similar code
elsewhere in this script does, and as suggested earlier[1].

[1]: http://article.gmane.org/gmane.comp.version-control.git/266972/

 +test_expect_success Type of broken object is correct '
 +   echo $bogus_type expect 
 +   git cat-file -t --literally $bogus_sha1 actual 
 +   test_cmp expect actual
 +'
 +
 +test_expect_success Size of broken object is correct '
 +echo $bogus_size expect 

Bad indentation. Use tab rather than spaces.

 +   git cat-file -s --literally $bogus_sha1 actual 
 +   test_cmp expect actual
 +'
 +
  test_done
 --
 2.4.0.rc1.249.gb598846
--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v8 4/4] t1006: add tests for git cat-file --literally

2015-04-15 Thread Karthik Nayak
Signed-off-by: Karthik Nayak karthik@gmail.com
---
 t/t1006-cat-file.sh | 29 +
 1 file changed, 29 insertions(+)

diff --git a/t/t1006-cat-file.sh b/t/t1006-cat-file.sh
index ab36b1e..61fab78 100755
--- a/t/t1006-cat-file.sh
+++ b/t/t1006-cat-file.sh
@@ -47,6 +47,18 @@ $content
test_cmp expect actual
 '
 
+test_expect_success Type of $type is correct using --literally '
+   echo $type expect 
+   git cat-file -t --literally $sha1 actual 
+   test_cmp expect actual
+'
+
+test_expect_success Size of $type is correct using --literally '
+   echo $size expect 
+   git cat-file -s --literally $sha1 actual 
+   test_cmp expect actual
+'
+
 test -z $content ||
 test_expect_success Content of $type is correct '
maybe_remove_timestamp $content $no_ts expect 
@@ -296,4 +308,21 @@ test_expect_success '%(deltabase) reports packed delta 
bases' '
}
 '
 
+bogus_type=bogus
+bogus_content=bogus
+bogus_size=$(strlen $bogus_content)
+bogus_sha1=$(printf $bogus_content | git hash-object -t $bogus_type 
--literally -w --stdin)
+
+test_expect_success Type of broken object is correct '
+   echo $bogus_type expect 
+   git cat-file -t --literally $bogus_sha1 actual 
+   test_cmp expect actual
+'
+
+test_expect_success Size of broken object is correct '
+echo $bogus_size expect 
+   git cat-file -s --literally $bogus_sha1 actual 
+   test_cmp expect actual
+'
+
 test_done
-- 
2.4.0.rc1.249.gb598846

--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html