diff --stat: tests for long filenames and big change counts

In preparation for updates to the "diff --stat" that updates the logic to split the allotted columns into the name part and the graph part to make the output more readable, add a handful of tests to document the corner case behaviour in which long filenames and big changes are shown. When a pathname is so long that it cannot fit on the column, the current code truncates it to make sure that the graph part has enough room to show a meaningful graph. If the actual change is small (e.g. only one line changed), this results in the final output that is shorter than the width we aim for. Signed-off-by: Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Junio C Hamano committed Mar 1, 2012 at 13:26 UTC 31c2373d39558f98222a1fd8b83ed74ccaa87161
1 file changed +182
t/t4052-stat-output.sh new
+182
@@ -0,0 +1,182 @@
1 +#!/bin/sh
2 +#
3 +# Copyright (c) 2012 Zbigniew Jędrzejewski-Szmek
4 +#
5 +
6 +test_description='test --stat output of various commands'
7 +
8 +. ./test-lib.sh
9 +. "$TEST_DIRECTORY"/lib-terminal.sh
10 +
11 +# 120 character name
12 +name=aaaaaaaaaa
13 +name=$name$name$name$name$name$name$name$name$name$name$name$name
14 +test_expect_success 'preparation' '
15 + >"$name" &&
16 + git add "$name" &&
17 + git commit -m message &&
18 + echo a >"$name" &&
19 + git commit -m message "$name"
20 +'
21 +
22 +while read cmd args
23 +do
24 + cat >expect <<-'EOF'
25 + ...aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa | 1 +
26 + EOF
27 + test_expect_success "$cmd: a short graph bar does not extend to the full width" '
28 + git $cmd $args >output &&
29 + grep " | " output >actual &&
30 + test_cmp expect actual
31 + '
32 +
33 + cat >expect <<-'EOF'
34 + ...aaaaaaaaaaaaaaaaaaaaaa | 1 +
35 + EOF
36 + test_expect_success "$cmd --stat=width: name is chopped to leave room to the right of a short bar" '
37 + git $cmd $args --stat=40 >output &&
38 + grep " | " output >actual &&
39 + test_cmp expect actual
40 + '
41 +
42 + test_expect_success "$cmd --stat-width=width with long name" '
43 + git $cmd $args --stat-width=40 >output &&
44 + grep " | " output >actual &&
45 + test_cmp expect actual
46 + '
47 +
48 + cat >expect <<-'EOF'
49 + ...aaaaaaaaaaaaaaaaaaaaaaaaaaa | 1 +
50 + EOF
51 + test_expect_success "$cmd --stat=...,name-width with long name" '
52 + git $cmd $args --stat=60,30 >output &&
53 + grep " | " output >actual &&
54 + test_cmp expect actual
55 + '
56 +
57 + test_expect_success "$cmd --stat-name-width with long name" '
58 + git $cmd $args --stat-name-width=30 >output &&
59 + grep " | " output >actual &&
60 + test_cmp expect actual
61 + '
62 +done <<\EOF
63 +format-patch -1 --stdout
64 +diff HEAD^ HEAD --stat
65 +show --stat
66 +log -1 --stat
67 +EOF
68 +
69 +
70 +test_expect_success 'preparation for big change tests' '
71 + >abcd &&
72 + git add abcd &&
73 + git commit -m message &&
74 + i=0 &&
75 + while test $i -lt 1000
76 + do
77 + echo $i && i=$(($i + 1))
78 + done >abcd &&
79 + git commit -m message abcd
80 +'
81 +
82 +cat >expect80 <<'EOF'
83 + abcd | 1000 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
84 +EOF
85 +
86 +while read verb expect cmd args
87 +do
88 + test_expect_success "$cmd $verb COLUMNS (big change)" '
89 + COLUMNS=200 git $cmd $args >output
90 + grep " | " output >actual &&
91 + test_cmp "$expect" actual
92 + '
93 +done <<\EOF
94 +ignores expect80 format-patch -1 --stdout
95 +ignores expect80 diff HEAD^ HEAD --stat
96 +ignores expect80 show --stat
97 +ignores expect80 log -1 --stat
98 +EOF
99 +
100 +cat >expect <<'EOF'
101 + abcd | 1000 ++++++++++++++++++++++++++
102 +EOF
103 +while read cmd args
104 +do
105 + test_expect_success "$cmd --stat=width with big change" '
106 + git $cmd $args --stat=40 >output
107 + grep " | " output >actual &&
108 + test_cmp expect actual
109 + '
110 +
111 + test_expect_success "$cmd --stat-width=width with big change" '
112 + git $cmd $args --stat-width=40 >output
113 + grep " | " output >actual &&
114 + test_cmp expect actual
115 + '
116 +done <<\EOF
117 +format-patch -1 --stdout
118 +diff HEAD^ HEAD --stat
119 +show --stat
120 +log -1 --stat
121 +EOF
122 +
123 +test_expect_success 'preparation for long filename tests' '
124 + cp abcd aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa &&
125 + git add aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa &&
126 + git commit -m message
127 +'
128 +
129 +cat >expect <<'EOF'
130 + ...aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa | 1000 +++++
131 +EOF
132 +while read cmd args
133 +do
134 + test_expect_success "$cmd --stat=width with big change and long name favors name part" '
135 + git $cmd $args --stat-width=60 >output &&
136 + grep " | " output >actual &&
137 + test_cmp expect actual
138 + '
139 +done <<\EOF
140 +format-patch -1 --stdout
141 +diff HEAD^ HEAD --stat
142 +show --stat
143 +log -1 --stat
144 +EOF
145 +
146 +cat >expect80 <<'EOF'
147 + ...aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa | 1000 ++++++++++++++++++++
148 +EOF
149 +while read verb expect cmd args
150 +do
151 + test_expect_success "$cmd $verb COLUMNS (long filename)" '
152 + COLUMNS=200 git $cmd $args >output
153 + grep " | " output >actual &&
154 + test_cmp "$expect" actual
155 + '
156 +done <<\EOF
157 +ignores expect80 format-patch -1 --stdout
158 +ignores expect80 diff HEAD^ HEAD --stat
159 +ignores expect80 show --stat
160 +ignores expect80 log -1 --stat
161 +EOF
162 +
163 +cat >expect <<'EOF'
164 + abcd | 1000 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
165 +EOF
166 +test_expect_success 'merge --stat ignores COLUMNS (big change)' '
167 + git checkout -b branch HEAD^^ &&
168 + COLUMNS=100 git merge --stat --no-ff master^ >output &&
169 + grep " | " output >actual
170 + test_cmp expect actual
171 +'
172 +
173 +cat >expect <<'EOF'
174 + ...aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa | 1000 ++++++++++++++++++++
175 +EOF
176 +test_expect_success 'merge --stat ignores COLUMNS (long filename)' '
177 + COLUMNS=100 git merge --stat --no-ff master >output &&
178 + grep " | " output >actual
179 + test_cmp expect actual
180 +'
181 +
182 +test_done