Re: [PATCH] t5300-pack-object.sh: portability issue using /usr/bin/stat

Subsystems: the rest

2 messages, 2 authors, 2016-06-15 · open the first message on its own page

Re: [PATCH] t5300-pack-object.sh: portability issue using /usr/bin/stat

From: Junio C Hamano <hidden>
Date: 2016-06-15 22:43:03

arjen@yaph.org (Arjen Laarhoven) writes:
In the test 'compare delta flavors', /usr/bin/stat is used to get file size.
This isn't portable.  There already is a dependency on Perl, use its '-s'
operator to get the file size.
If you do use Perl, then you do not want to do it as two
separate invocations with their result compared with test.

How about this on top of your patch?
diff --git a/t/t5300-pack-object.sh b/t/t5300-pack-object.sh
index a400e7a..5710a23 100755
--- a/t/t5300-pack-object.sh
+++ b/t/t5300-pack-object.sh
@@ -123,11 +123,13 @@ test_expect_success \
      done'
 cd "$TRASH"
 
-test_expect_success \
-    'compare delta flavors' \
-    'size_2=`perl -e "print -s q[test-2-${packname_2}.pack]"` &&
-     size_3=`perl -e "print -s q[test-3-${packname_3}.pack]"` &&
-     test $size_2 -gt $size_3'
+test_expect_success 'compare delta flavors' '
+	perl -e "
+		exit ( ((-s q[test-2-${packname_2}.pack]) >
+			(-s q[test-3-${packname_3}.pack]))
+			? 0 : 1);
+	"
+'
 
 rm -fr .git2
 mkdir .git2

Re: [PATCH] t5300-pack-object.sh: portability issue using /usr/bin/stat

From: Nicolas Pitre <hidden>
Date: 2016-06-15 22:43:03

On Fri, 6 Apr 2007, Junio C Hamano wrote:
arjen@yaph.org (Arjen Laarhoven) writes:
quoted
In the test 'compare delta flavors', /usr/bin/stat is used to get file size.
This isn't portable.  There already is a dependency on Perl, use its '-s'
operator to get the file size.
If you do use Perl, then you do not want to do it as two
separate invocations with their result compared with test.

How about this on top of your patch?
Well... since this test already depends on wc then why not just use that 
instead of adding a perl dependency?

Something like:
diff --git a/t/t5300-pack-object.sh b/t/t5300-pack-object.sh
index 35e036a..ba785cf 100755
--- a/t/t5300-pack-object.sh
+++ b/t/t5300-pack-object.sh
@@ -125,8 +125,8 @@ cd "$TRASH"
 
 test_expect_success \
     'compare delta flavors' \
-    'size_2=`stat -c "%s" test-2-${packname_2}.pack` &&
-     size_3=`stat -c "%s" test-3-${packname_3}.pack` &&
+    'size_2=`wc -c < test-2-${packname_2}.pack` &&
+     size_3=`wc -c < test-3-${packname_3}.pack` &&
      test $size_2 -gt $size_3'
 
 rm -fr .git2
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help