t / t4052-stat-output.shon commit Merge branch 'rr/die-on-missing-upstream' (03b1558)
   1#!/bin/sh
   2#
   3# Copyright (c) 2012 Zbigniew Jędrzejewski-Szmek
   4#
   5
   6test_description='test --stat output of various commands'
   7
   8. ./test-lib.sh
   9. "$TEST_DIRECTORY"/lib-terminal.sh
  10
  11# 120 character name
  12name=aaaaaaaaaa
  13name=$name$name$name$name$name$name$name$name$name$name$name$name
  14test_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
  22while read cmd args
  23do
  24        cat >expect <<-'EOF'
  25         ...aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa | 1 +
  26        EOF
  27        test_expect_success "$cmd: small change with long name gives more space to the name" '
  28                git $cmd $args >output &&
  29                grep " | " output >actual &&
  30                test_cmp expect actual
  31        '
  32
  33        cat >expect <<-'EOF'
  34         ...aaaaaaaaaaaaaaaaaaaaaaaaaaaaa | 1 +
  35        EOF
  36        test_expect_success "$cmd --stat=width: a long name is given more room when the bar is short" '
  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        '
  62done <<\EOF
  63format-patch -1 --stdout
  64diff HEAD^ HEAD --stat
  65show --stat
  66log -1 --stat
  67EOF
  68
  69
  70test_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
  82cat >expect80 <<'EOF'
  83 abcd | 1000 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  84EOF
  85cat >expect80-graph <<'EOF'
  86|  abcd | 1000 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  87EOF
  88cat >expect200 <<'EOF'
  89 abcd | 1000 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  90EOF
  91cat >expect200-graph <<'EOF'
  92|  abcd | 1000 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  93EOF
  94while read verb expect cmd args
  95do
  96        test_expect_success "$cmd $verb COLUMNS (big change)" '
  97                COLUMNS=200 git $cmd $args >output
  98                grep " | " output >actual &&
  99                test_cmp "$expect" actual
 100        '
 101
 102        test "$cmd" != diff || continue
 103
 104        test_expect_success "$cmd --graph $verb COLUMNS (big change)" '
 105                COLUMNS=200 git $cmd $args --graph >output
 106                grep " | " output >actual &&
 107                test_cmp "$expect-graph" actual
 108        '
 109done <<\EOF
 110ignores expect80 format-patch -1 --stdout
 111respects expect200 diff HEAD^ HEAD --stat
 112respects expect200 show --stat
 113respects expect200 log -1 --stat
 114EOF
 115
 116cat >expect40 <<'EOF'
 117 abcd | 1000 ++++++++++++++++++++++++++
 118EOF
 119cat >expect40-graph <<'EOF'
 120|  abcd | 1000 ++++++++++++++++++++++++
 121EOF
 122while read verb expect cmd args
 123do
 124        test_expect_success "$cmd $verb not enough COLUMNS (big change)" '
 125                COLUMNS=40 git $cmd $args >output
 126                grep " | " output >actual &&
 127                test_cmp "$expect" actual
 128        '
 129
 130        test "$cmd" != diff || continue
 131
 132        test_expect_success "$cmd --graph $verb not enough COLUMNS (big change)" '
 133                COLUMNS=40 git $cmd $args --graph >output
 134                grep " | " output >actual &&
 135                test_cmp "$expect-graph" actual
 136        '
 137done <<\EOF
 138ignores expect80 format-patch -1 --stdout
 139respects expect40 diff HEAD^ HEAD --stat
 140respects expect40 show --stat
 141respects expect40 log -1 --stat
 142EOF
 143
 144cat >expect40 <<'EOF'
 145 abcd | 1000 ++++++++++++++++++++++++++
 146EOF
 147cat >expect40-graph <<'EOF'
 148|  abcd | 1000 ++++++++++++++++++++++++++
 149EOF
 150while read verb expect cmd args
 151do
 152        test_expect_success "$cmd $verb statGraphWidth config" '
 153                git -c diff.statGraphWidth=26 $cmd $args >output
 154                grep " | " output >actual &&
 155                test_cmp "$expect" actual
 156        '
 157
 158        test "$cmd" != diff || continue
 159
 160        test_expect_success "$cmd --graph $verb statGraphWidth config" '
 161                git -c diff.statGraphWidth=26 $cmd $args --graph >output
 162                grep " | " output >actual &&
 163                test_cmp "$expect-graph" actual
 164        '
 165done <<\EOF
 166ignores expect80 format-patch -1 --stdout
 167respects expect40 diff HEAD^ HEAD --stat
 168respects expect40 show --stat
 169respects expect40 log -1 --stat
 170EOF
 171
 172
 173cat >expect <<'EOF'
 174 abcd | 1000 ++++++++++++++++++++++++++
 175EOF
 176cat >expect-graph <<'EOF'
 177|  abcd | 1000 ++++++++++++++++++++++++++
 178EOF
 179while read cmd args
 180do
 181        test_expect_success "$cmd --stat=width with big change" '
 182                git $cmd $args --stat=40 >output
 183                grep " | " output >actual &&
 184                test_cmp expect actual
 185        '
 186
 187        test_expect_success "$cmd --stat-width=width with big change" '
 188                git $cmd $args --stat-width=40 >output
 189                grep " | " output >actual &&
 190                test_cmp expect actual
 191        '
 192
 193        test_expect_success "$cmd --stat-graph-width with big change" '
 194                git $cmd $args --stat-graph-width=26 >output
 195                grep " | " output >actual &&
 196                test_cmp expect actual
 197        '
 198
 199        test "$cmd" != diff || continue
 200
 201        test_expect_success "$cmd --stat-width=width --graph with big change" '
 202                git $cmd $args --stat-width=40 --graph >output
 203                grep " | " output >actual &&
 204                test_cmp expect-graph actual
 205        '
 206
 207        test_expect_success "$cmd --stat-graph-width --graph with big change" '
 208                git $cmd $args --stat-graph-width=26 --graph >output
 209                grep " | " output >actual &&
 210                test_cmp expect-graph actual
 211        '
 212done <<\EOF
 213format-patch -1 --stdout
 214diff HEAD^ HEAD --stat
 215show --stat
 216log -1 --stat
 217EOF
 218
 219test_expect_success 'preparation for long filename tests' '
 220        cp abcd aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa &&
 221        git add aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa &&
 222        git commit -m message
 223'
 224
 225cat >expect <<'EOF'
 226 ...aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa | 1000 ++++++++++++
 227EOF
 228cat >expect-graph <<'EOF'
 229|  ...aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa | 1000 ++++++++++++
 230EOF
 231while read cmd args
 232do
 233        test_expect_success "$cmd --stat=width with big change is more balanced" '
 234                git $cmd $args --stat-width=60 >output &&
 235                grep " | " output >actual &&
 236                test_cmp expect actual
 237        '
 238
 239        test "$cmd" != diff || continue
 240
 241        test_expect_success "$cmd --stat=width --graph with big change is balanced" '
 242                git $cmd $args --stat-width=60 --graph >output &&
 243                grep " | " output >actual &&
 244                test_cmp expect-graph actual
 245        '
 246done <<\EOF
 247format-patch -1 --stdout
 248diff HEAD^ HEAD --stat
 249show --stat
 250log -1 --stat
 251EOF
 252
 253cat >expect80 <<'EOF'
 254 ...aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa | 1000 ++++++++++++++++++++
 255EOF
 256cat >expect80-graph <<'EOF'
 257|  ...aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa | 1000 ++++++++++++++++++++
 258EOF
 259cat >expect200 <<'EOF'
 260 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa | 1000 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 261EOF
 262cat >expect200-graph <<'EOF'
 263|  aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa | 1000 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 264EOF
 265while read verb expect cmd args
 266do
 267        test_expect_success "$cmd $verb COLUMNS (long filename)" '
 268                COLUMNS=200 git $cmd $args >output
 269                grep " | " output >actual &&
 270                test_cmp "$expect" actual
 271        '
 272
 273        test "$cmd" != diff || continue
 274
 275        test_expect_success "$cmd --graph $verb COLUMNS (long filename)" '
 276                COLUMNS=200 git $cmd $args --graph >output
 277                grep " | " output >actual &&
 278                test_cmp "$expect-graph" actual
 279        '
 280done <<\EOF
 281ignores expect80 format-patch -1 --stdout
 282respects expect200 diff HEAD^ HEAD --stat
 283respects expect200 show --stat
 284respects expect200 log -1 --stat
 285EOF
 286
 287cat >expect1 <<'EOF'
 288 ...aaaaaaa | 1000 ++++++
 289EOF
 290cat >expect1-graph <<'EOF'
 291|  ...aaaaaaa | 1000 ++++++
 292EOF
 293while read verb expect cmd args
 294do
 295        test_expect_success COLUMNS_CAN_BE_1 \
 296                "$cmd $verb prefix greater than COLUMNS (big change)" '
 297                COLUMNS=1 git $cmd $args >output
 298                grep " | " output >actual &&
 299                test_cmp "$expect" actual
 300        '
 301
 302        test "$cmd" != diff || continue
 303
 304        test_expect_success COLUMNS_CAN_BE_1 \
 305                "$cmd --graph $verb prefix greater than COLUMNS (big change)" '
 306                COLUMNS=1 git $cmd $args --graph >output
 307                grep " | " output >actual &&
 308                test_cmp "$expect-graph" actual
 309        '
 310done <<\EOF
 311ignores expect80 format-patch -1 --stdout
 312respects expect1 diff HEAD^ HEAD --stat
 313respects expect1 show --stat
 314respects expect1 log -1 --stat
 315EOF
 316
 317cat >expect <<'EOF'
 318 abcd | 1000 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 319EOF
 320test_expect_success 'merge --stat respects COLUMNS (big change)' '
 321        git checkout -b branch HEAD^^ &&
 322        COLUMNS=100 git merge --stat --no-ff master^ >output &&
 323        grep " | " output >actual
 324        test_cmp expect actual
 325'
 326
 327cat >expect <<'EOF'
 328 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa | 1000 +++++++++++++++++++++++++++++++++++++++
 329EOF
 330test_expect_success 'merge --stat respects COLUMNS (long filename)' '
 331        COLUMNS=100 git merge --stat --no-ff master >output &&
 332        grep " | " output >actual
 333        test_cmp expect actual
 334'
 335
 336test_done