# [PATCH] Fix tests for broken sed on Leopard

1 messages from 2007-12-18 to 2007-12-18. Participants: Wincent Colaiuta.
Thread: https://gitlist.dev/t/11348

## Wincent Colaiuta, 2007-12-18 19:45

Subject: [PATCH] Fix tests for broken sed on Leopard
Message-ID: <1198007158-27576-1-git-send-email-win@wincent.com>
URL: https://gitlist.dev/e/1198007158-27576-1-git-send-email-win%40wincent.com
In-Reply-To: <7vzlw7zwj8.fsf@gitster.siamese.dyndns.org>

```
El 18/12/2007, a las 19:29, Junio C Hamano escribiÃ³:

> Could you work it around not by changing what is tested, but by changing
> the way the result (actual and expect) are compared, please?  I actually
> wanted to enhance this to test with values 1023, 2047, and 4095, and
> your change will close the door for such changes.

How about the following? This swaps in perl in place of sed, which we can
hopefully rely upon to work across platforms.

Cheers,
Wincent

-------- 8< --------
Fix tests for broken sed on Leopard

The newly-added common-tail-optimization test fails on Leopard because
the broken sed implementation bails with a spurious "unterminated
substitute pattern" error because of the length of one of the
arguments.

So use perl instead of sed, and at the same time add test cases for
1024 - 1 and 4096 - 1 as suggested by Junio.

Signed-off-by: Wincent Colaiuta <win@wincent.com>
---
 t/t4024-diff-optimize-common.sh |  104 ++++++++++++++++++++++++++++++---------
 1 files changed, 80 insertions(+), 24 deletions(-)

diff --git a/t/t4024-diff-optimize-common.sh b/t/t4024-diff-optimize-common.sh
index 20fe87b..84dfb05 100755
--- a/t/t4024-diff-optimize-common.sh
+++ b/t/t4024-diff-optimize-common.sh
@@ -7,28 +7,12 @@ test_description='common tail optimization'
 z=zzzzzzzz ;# 8
 z="$z$z$z$z$z$z$z$z" ;# 64
 z="$z$z$z$z$z$z$z$z" ;# 512
-z="$z$z$z$z" ;# 2048
-z2047=$(expr "$z" : '.\(.*\)') ; #2047
-
-test_expect_success setup '
-
-	echo "a$z2047" >file-a &&
-	echo "b" >file-b &&
-	echo "$z2047" >>file-b &&
-	echo "c$z2047" | tr -d "\012" >file-c &&
-	echo "d" >file-d &&
-	echo "$z2047" | tr -d "\012" >>file-d &&
-
-	git add file-a file-b file-c file-d &&
-
-	echo "A$z2047" >file-a &&
-	echo "B" >file-b &&
-	echo "$z2047" >>file-b &&
-	echo "C$z2047" | tr -d "\012" >file-c &&
-	echo "D" >file-d &&
-	echo "$z2047" | tr -d "\012" >>file-d
-
-'
+z1024="$z$z"
+z1023=$(expr "$z1024" : '.\(.*\)')
+z2048="$z1024$z1024"
+z2047=$(expr "$z2048" : '.\(.*\)')
+z4096="$z2048$z2048"
+z4095=$(expr "$z4096" : '.\(.*\)')
 
 cat >expect <<\EOF
 diff --git a/file-a b/file-a
@@ -59,11 +43,83 @@ diff --git a/file-d b/file-d
 +D
 EOF
 
-test_expect_success 'diff -U0' '
+test_expect_success 'setup (1023-char sequence)' '
+
+	echo "a$z1023" >file-a &&
+	echo "b" >file-b &&
+	echo "$z1023" >>file-b &&
+	echo "c$z1023" | tr -d "\012" >file-c &&
+	echo "d" >file-d &&
+	echo "$z1023" | tr -d "\012" >>file-d &&
+
+	git add file-a file-b file-c file-d &&
+
+	echo "A$z1023" >file-a &&
+	echo "B" >file-b &&
+	echo "$z1023" >>file-b &&
+	echo "C$z1023" | tr -d "\012" >file-c &&
+	echo "D" >file-d &&
+	echo "$z1023" | tr -d "\012" >>file-d
+
+'
+
+test_expect_success 'diff -U0 (1023-char sequence)' '
+	git diff -U0 | perl -pe "s/^index.+\n//g; s/$z1023/Z/g" >actual &&
+	diff -u expect actual
+
+'
+
+test_expect_success 'setup (2047-char sequence)' '
 
-	git diff -U0 | sed -e "/^index/d" -e "s/$z2047/Z/g" >actual &&
+	echo "a$z2047" >file-a &&
+	echo "b" >file-b &&
+	echo "$z2047" >>file-b &&
+	echo "c$z2047" | tr -d "\012" >file-c &&
+	echo "d" >file-d &&
+	echo "$z2047" | tr -d "\012" >>file-d &&
+
+	git add file-a file-b file-c file-d &&
+
+	echo "A$z2047" >file-a &&
+	echo "B" >file-b &&
+	echo "$z2047" >>file-b &&
+	echo "C$z2047" | tr -d "\012" >file-c &&
+	echo "D" >file-d &&
+	echo "$z2047" | tr -d "\012" >>file-d
+
+'
+
+test_expect_success 'diff -U0 (2047-char sequence)' '
+
+	git diff -U0 | perl -pe "s/^index.+\n//g; s/$z2047/Z/g" >actual &&
 	diff -u expect actual
 
 '
 
+test_expect_success 'setup (4095-char sequence)' '
+
+	echo "a$z4095" >file-a &&
+	echo "b" >file-b &&
+	echo "$z4095" >>file-b &&
+	echo "c$z4095" | tr -d "\012" >file-c &&
+	echo "d" >file-d &&
+	echo "$z4095" | tr -d "\012" >>file-d &&
+
+	git add file-a file-b file-c file-d &&
+
+	echo "A$z4095" >file-a &&
+	echo "B" >file-b &&
+	echo "$z4095" >>file-b &&
+	echo "C$z4095" | tr -d "\012" >file-c &&
+	echo "D" >file-d &&
+	echo "$z4095" | tr -d "\012" >>file-d
+
+'
+
+test_expect_success 'diff -U0 (4095-char sequence)' '
+
+	git diff -U0 | perl -pe "s/^index.+\n//g; s/$z4095/Z/g" >actual &&
+	diff -u expect actual
+
+'
 test_done
-- 
1.5.4.rc0.68.g15eb8-dirty

```
