@matheusbsbs / matheus-bagliano / commits / 885ed372d0
Fork 0

t4024: fix test script to use simpler sed pattern

The earlier test stripped away expected number of 'z' but the output would have been very hard to read once somebody broke the common tail optimization. Instead, count the number of 'z' and show it, to help diagnosing the problem better in the future. Signed-off-by: Junio C Hamano <gitster@pobox.com>

Junio C Hamano committed Dec 19, 2007 at 16:21 UTC 885ed372d09f68806b17fc8fd0ac13a46636aeb2
1 file changed +123 -35
t/t4024-diff-optimize-common.sh
+123 -35
@@ -10,58 +10,146 @@ z="$z$z$z$z$z$z$z$z" ;# 512
10 z="$z$z$z$z" ;# 2048
11 z2047=$(expr "$z" : '.\(.*\)') ; #2047
12
13 -test_expect_success setup '
14 -
15 - echo "a$z2047" >file-a &&
16 - echo "b" >file-b &&
17 - echo "$z2047" >>file-b &&
18 - echo "c$z2047" | tr -d "\012" >file-c &&
19 - echo "d" >file-d &&
20 - echo "$z2047" | tr -d "\012" >>file-d &&
13 +x=zzzzzzzzzz ;# 10
14 +y="$x$x$x$x$x$x$x$x$x$x" ;# 100
15 +z="$y$y$y$y$y$y$y$y$y$y" ;# 1000
16 +z1000=$z
17 +z100=$y
18 +z10=$x
19
22 - git add file-a file-b file-c file-d &&
20 +zs() {
21 + count="$1"
22 + while test "$count" -ge 1000
23 + do
24 + count=$(($count - 1000))
25 + printf "%s" $z1000
26 + done
27 + while test "$count" -ge 100
28 + do
29 + count=$(($count - 100))
30 + printf "%s" $z100
31 + done
32 + while test "$count" -ge 10
33 + do
34 + count=$(($count - 10))
35 + printf "%s" $z10
36 + done
37 + while test "$count" -ge 1
38 + do
39 + count=$(($count - 1))
40 + printf "z"
41 + done
42 +}
43
24 - echo "A$z2047" >file-a &&
25 - echo "B" >file-b &&
26 - echo "$z2047" >>file-b &&
27 - echo "C$z2047" | tr -d "\012" >file-c &&
28 - echo "D" >file-d &&
29 - echo "$z2047" | tr -d "\012" >>file-d
30 -
31 -'
44 +zc () {
45 + sed -e "/^index/d" \
46 + -e "s/$z1000/Q/g" \
47 + -e "s/QQQQQQQQQ/Z9000/g" \
48 + -e "s/QQQQQQQQ/Z8000/g" \
49 + -e "s/QQQQQQQ/Z7000/g" \
50 + -e "s/QQQQQQ/Z6000/g" \
51 + -e "s/QQQQQ/Z5000/g" \
52 + -e "s/QQQQ/Z4000/g" \
53 + -e "s/QQQ/Z3000/g" \
54 + -e "s/QQ/Z2000/g" \
55 + -e "s/Q/Z1000/g" \
56 + -e "s/$z100/Q/g" \
57 + -e "s/QQQQQQQQQ/Z900/g" \
58 + -e "s/QQQQQQQQ/Z800/g" \
59 + -e "s/QQQQQQQ/Z700/g" \
60 + -e "s/QQQQQQ/Z600/g" \
61 + -e "s/QQQQQ/Z500/g" \
62 + -e "s/QQQQ/Z400/g" \
63 + -e "s/QQQ/Z300/g" \
64 + -e "s/QQ/Z200/g" \
65 + -e "s/Q/Z100/g" \
66 + -e "s/000Z//g" \
67 + -e "s/$z10/Q/g" \
68 + -e "s/QQQQQQQQQ/Z90/g" \
69 + -e "s/QQQQQQQQ/Z80/g" \
70 + -e "s/QQQQQQQ/Z70/g" \
71 + -e "s/QQQQQQ/Z60/g" \
72 + -e "s/QQQQQ/Z50/g" \
73 + -e "s/QQQQ/Z40/g" \
74 + -e "s/QQQ/Z30/g" \
75 + -e "s/QQ/Z20/g" \
76 + -e "s/Q/Z10/g" \
77 + -e "s/00Z//g" \
78 + -e "s/z/Q/g" \
79 + -e "s/QQQQQQQQQ/Z9/g" \
80 + -e "s/QQQQQQQQ/Z8/g" \
81 + -e "s/QQQQQQQ/Z7/g" \
82 + -e "s/QQQQQQ/Z6/g" \
83 + -e "s/QQQQQ/Z5/g" \
84 + -e "s/QQQQ/Z4/g" \
85 + -e "s/QQQ/Z3/g" \
86 + -e "s/QQ/Z2/g" \
87 + -e "s/Q/Z1/g" \
88 + -e "s/0Z//g" \
89 + ;
90 +}
91
33 -cat >expect <<\EOF
34 -diff --git a/file-a b/file-a
35 ---- a/file-a
36 -+++ b/file-a
92 +expect_pattern () {
93 + cnt="$1"
94 + cat <<EOF
95 +diff --git a/file-a$cnt b/file-a$cnt
96 +--- a/file-a$cnt
97 ++++ b/file-a$cnt
98 @@ -1 +1 @@
38 --aZ
39 -+AZ
40 -diff --git a/file-b b/file-b
41 ---- a/file-b
42 -+++ b/file-b
99 +-Z${cnt}a
100 ++Z${cnt}A
101 +diff --git a/file-b$cnt b/file-b$cnt
102 +--- a/file-b$cnt
103 ++++ b/file-b$cnt
104 @@ -1 +1 @@
105 -b
106 +B
46 -diff --git a/file-c b/file-c
47 ---- a/file-c
48 -+++ b/file-c
107 +diff --git a/file-c$cnt b/file-c$cnt
108 +--- a/file-c$cnt
109 ++++ b/file-c$cnt
110 @@ -1 +1 @@
50 --cZ
111 +-cZ$cnt
112 \ No newline at end of file
52 -+CZ
113 ++CZ$cnt
114 \ No newline at end of file
54 -diff --git a/file-d b/file-d
55 ---- a/file-d
56 -+++ b/file-d
115 +diff --git a/file-d$cnt b/file-d$cnt
116 +--- a/file-d$cnt
117 ++++ b/file-d$cnt
118 @@ -1 +1 @@
119 -d
120 +D
121 EOF
122 +}
123 +
124 +sample='1023 1024 1025 2047 4095'
125 +
126 +test_expect_success setup '
127 +
128 + for n in $sample
129 + do
130 + ( zs $n ; echo a ) >file-a$n &&
131 + ( echo b; zs $n; echo ) >file-b$n &&
132 + ( printf c; zs $n ) >file-c$n &&
133 + ( echo d; zs $n ) >file-d$n &&
134 +
135 + git add file-a$n file-b$n file-c$n file-d$n &&
136 +
137 + ( zs $n ; echo A ) >file-a$n &&
138 + ( echo B; zs $n; echo ) >file-b$n &&
139 + ( printf C; zs $n ) >file-c$n &&
140 + ( echo D; zs $n ) >file-d$n &&
141 +
142 + expect_pattern $n || break
143 +
144 + done >expect
145 +'
146
147 test_expect_success 'diff -U0' '
148
64 - git diff -U0 | sed -e "/^index/d" -e "s/$z2047/Z/g" >actual &&
149 + for n in $sample
150 + do
151 + git diff -U0 file-?$n
152 + done | zc >actual &&
153 diff -u expect actual
154
155 '