t / t4052-stat-output.shon commit pretty: allow %(trailers) options with explicit value (4f732e0)
   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
  22cat >expect72 <<-'EOF'
  23 ...aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa | 1 +
  24EOF
  25test_expect_success "format-patch: small change with long name gives more space to the name" '
  26        git format-patch -1 --stdout >output &&
  27        grep " | " output >actual &&
  28        test_cmp expect72 actual
  29'
  30
  31while read cmd args
  32do
  33        cat >expect80 <<-'EOF'
  34         ...aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa | 1 +
  35        EOF
  36        test_expect_success "$cmd: small change with long name gives more space to the name" '
  37                git $cmd $args >output &&
  38                grep " | " output >actual &&
  39                test_cmp expect80 actual
  40        '
  41done <<\EOF
  42diff HEAD^ HEAD --stat
  43show --stat
  44log -1 --stat
  45EOF
  46
  47while read cmd args
  48do
  49        cat >expect <<-'EOF'
  50         ...aaaaaaaaaaaaaaaaaaaaaaaaaaaaa | 1 +
  51        EOF
  52        test_expect_success "$cmd --stat=width: a long name is given more room when the bar is short" '
  53                git $cmd $args --stat=40 >output &&
  54                grep " | " output >actual &&
  55                test_cmp expect actual
  56        '
  57
  58        test_expect_success "$cmd --stat-width=width with long name" '
  59                git $cmd $args --stat-width=40 >output &&
  60                grep " | " output >actual &&
  61                test_cmp expect actual
  62        '
  63
  64        cat >expect <<-'EOF'
  65         ...aaaaaaaaaaaaaaaaaaaaaaaaaaa | 1 +
  66        EOF
  67        test_expect_success "$cmd --stat=...,name-width with long name" '
  68                git $cmd $args --stat=60,30 >output &&
  69                grep " | " output >actual &&
  70                test_cmp expect actual
  71        '
  72
  73        test_expect_success "$cmd --stat-name-width with long name" '
  74                git $cmd $args --stat-name-width=30 >output &&
  75                grep " | " output >actual &&
  76                test_cmp expect actual
  77        '
  78done <<\EOF
  79format-patch -1 --stdout
  80diff HEAD^ HEAD --stat
  81show --stat
  82log -1 --stat
  83EOF
  84
  85
  86test_expect_success 'preparation for big change tests' '
  87        >abcd &&
  88        git add abcd &&
  89        git commit -m message &&
  90        i=0 &&
  91        while test $i -lt 1000
  92        do
  93                echo $i && i=$(($i + 1))
  94        done >abcd &&
  95        git commit -m message abcd
  96'
  97
  98cat >expect72 <<'EOF'
  99 abcd | 1000 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 100EOF
 101cat >expect72-graph <<'EOF'
 102|  abcd | 1000 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 103EOF
 104cat >expect200 <<'EOF'
 105 abcd | 1000 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 106EOF
 107cat >expect200-graph <<'EOF'
 108|  abcd | 1000 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 109EOF
 110while read verb expect cmd args
 111do
 112        test_expect_success "$cmd $verb COLUMNS (big change)" '
 113                COLUMNS=200 git $cmd $args >output &&
 114                grep " | " output >actual &&
 115                test_cmp "$expect" actual
 116        '
 117
 118        case "$cmd" in diff|show) continue;; esac
 119
 120        test_expect_success "$cmd --graph $verb COLUMNS (big change)" '
 121                COLUMNS=200 git $cmd $args --graph >output &&
 122                grep " | " output >actual &&
 123                test_cmp "$expect-graph" actual
 124        '
 125done <<\EOF
 126ignores expect72 format-patch -1 --stdout
 127respects expect200 diff HEAD^ HEAD --stat
 128respects expect200 show --stat
 129respects expect200 log -1 --stat
 130EOF
 131
 132cat >expect40 <<'EOF'
 133 abcd | 1000 ++++++++++++++++++++++++++
 134EOF
 135cat >expect40-graph <<'EOF'
 136|  abcd | 1000 ++++++++++++++++++++++++
 137EOF
 138while read verb expect cmd args
 139do
 140        test_expect_success "$cmd $verb not enough COLUMNS (big change)" '
 141                COLUMNS=40 git $cmd $args >output &&
 142                grep " | " output >actual &&
 143                test_cmp "$expect" actual
 144        '
 145
 146        case "$cmd" in diff|show) continue;; esac
 147
 148        test_expect_success "$cmd --graph $verb not enough COLUMNS (big change)" '
 149                COLUMNS=40 git $cmd $args --graph >output &&
 150                grep " | " output >actual &&
 151                test_cmp "$expect-graph" actual
 152        '
 153done <<\EOF
 154ignores expect72 format-patch -1 --stdout
 155respects expect40 diff HEAD^ HEAD --stat
 156respects expect40 show --stat
 157respects expect40 log -1 --stat
 158EOF
 159
 160cat >expect40 <<'EOF'
 161 abcd | 1000 ++++++++++++++++++++++++++
 162EOF
 163cat >expect40-graph <<'EOF'
 164|  abcd | 1000 ++++++++++++++++++++++++++
 165EOF
 166while read verb expect cmd args
 167do
 168        test_expect_success "$cmd $verb statGraphWidth config" '
 169                git -c diff.statGraphWidth=26 $cmd $args >output &&
 170                grep " | " output >actual &&
 171                test_cmp "$expect" actual
 172        '
 173
 174        case "$cmd" in diff|show) continue;; esac
 175
 176        test_expect_success "$cmd --graph $verb statGraphWidth config" '
 177                git -c diff.statGraphWidth=26 $cmd $args --graph >output &&
 178                grep " | " output >actual &&
 179                test_cmp "$expect-graph" actual
 180        '
 181done <<\EOF
 182ignores expect72 format-patch -1 --stdout
 183respects expect40 diff HEAD^ HEAD --stat
 184respects expect40 show --stat
 185respects expect40 log -1 --stat
 186EOF
 187
 188
 189cat >expect <<'EOF'
 190 abcd | 1000 ++++++++++++++++++++++++++
 191EOF
 192cat >expect-graph <<'EOF'
 193|  abcd | 1000 ++++++++++++++++++++++++++
 194EOF
 195while read cmd args
 196do
 197        test_expect_success "$cmd --stat=width with big change" '
 198                git $cmd $args --stat=40 >output &&
 199                grep " | " output >actual &&
 200                test_cmp expect actual
 201        '
 202
 203        test_expect_success "$cmd --stat-width=width with big change" '
 204                git $cmd $args --stat-width=40 >output &&
 205                grep " | " output >actual &&
 206                test_cmp expect actual
 207        '
 208
 209        test_expect_success "$cmd --stat-graph-width with big change" '
 210                git $cmd $args --stat-graph-width=26 >output &&
 211                grep " | " output >actual &&
 212                test_cmp expect actual
 213        '
 214
 215        case "$cmd" in diff|show) continue;; esac
 216
 217        test_expect_success "$cmd --stat-width=width --graph with big change" '
 218                git $cmd $args --stat-width=40 --graph >output &&
 219                grep " | " output >actual &&
 220                test_cmp expect-graph actual
 221        '
 222
 223        test_expect_success "$cmd --stat-graph-width --graph with big change" '
 224                git $cmd $args --stat-graph-width=26 --graph >output &&
 225                grep " | " output >actual &&
 226                test_cmp expect-graph actual
 227        '
 228done <<\EOF
 229format-patch -1 --stdout
 230diff HEAD^ HEAD --stat
 231show --stat
 232log -1 --stat
 233EOF
 234
 235test_expect_success 'preparation for long filename tests' '
 236        cp abcd aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa &&
 237        git add aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa &&
 238        git commit -m message
 239'
 240
 241cat >expect <<'EOF'
 242 ...aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa | 1000 ++++++++++++
 243EOF
 244cat >expect-graph <<'EOF'
 245|  ...aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa | 1000 ++++++++++++
 246EOF
 247while read cmd args
 248do
 249        test_expect_success "$cmd --stat=width with big change is more balanced" '
 250                git $cmd $args --stat-width=60 >output &&
 251                grep " | " output >actual &&
 252                test_cmp expect actual
 253        '
 254
 255        case "$cmd" in diff|show) continue;; esac
 256
 257        test_expect_success "$cmd --stat=width --graph with big change is balanced" '
 258                git $cmd $args --stat-width=60 --graph >output &&
 259                grep " | " output >actual &&
 260                test_cmp expect-graph actual
 261        '
 262done <<\EOF
 263format-patch -1 --stdout
 264diff HEAD^ HEAD --stat
 265show --stat
 266log -1 --stat
 267EOF
 268
 269cat >expect72 <<'EOF'
 270 ...aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa | 1000 +++++++++++++++++
 271EOF
 272cat >expect72-graph <<'EOF'
 273|  ...aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa | 1000 +++++++++++++++++
 274EOF
 275cat >expect200 <<'EOF'
 276 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa | 1000 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 277EOF
 278cat >expect200-graph <<'EOF'
 279|  aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa | 1000 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 280EOF
 281while read verb expect cmd args
 282do
 283        test_expect_success "$cmd $verb COLUMNS (long filename)" '
 284                COLUMNS=200 git $cmd $args >output &&
 285                grep " | " output >actual &&
 286                test_cmp "$expect" actual
 287        '
 288
 289        case "$cmd" in diff|show) continue;; esac
 290
 291        test_expect_success "$cmd --graph $verb COLUMNS (long filename)" '
 292                COLUMNS=200 git $cmd $args --graph >output &&
 293                grep " | " output >actual &&
 294                test_cmp "$expect-graph" actual
 295        '
 296done <<\EOF
 297ignores expect72 format-patch -1 --stdout
 298respects expect200 diff HEAD^ HEAD --stat
 299respects expect200 show --stat
 300respects expect200 log -1 --stat
 301EOF
 302
 303cat >expect1 <<'EOF'
 304 ...aaaaaaa | 1000 ++++++
 305EOF
 306cat >expect1-graph <<'EOF'
 307|  ...aaaaaaa | 1000 ++++++
 308EOF
 309while read verb expect cmd args
 310do
 311        test_expect_success COLUMNS_CAN_BE_1 \
 312                "$cmd $verb prefix greater than COLUMNS (big change)" '
 313                COLUMNS=1 git $cmd $args >output &&
 314                grep " | " output >actual &&
 315                test_cmp "$expect" actual
 316        '
 317
 318        case "$cmd" in diff|show) continue;; esac
 319
 320        test_expect_success COLUMNS_CAN_BE_1 \
 321                "$cmd --graph $verb prefix greater than COLUMNS (big change)" '
 322                COLUMNS=1 git $cmd $args --graph >output &&
 323                grep " | " output >actual &&
 324                test_cmp "$expect-graph" actual
 325        '
 326done <<\EOF
 327ignores expect72 format-patch -1 --stdout
 328respects expect1 diff HEAD^ HEAD --stat
 329respects expect1 show --stat
 330respects expect1 log -1 --stat
 331EOF
 332
 333cat >expect <<'EOF'
 334 abcd | 1000 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 335EOF
 336test_expect_success 'merge --stat respects COLUMNS (big change)' '
 337        git checkout -b branch HEAD^^ &&
 338        COLUMNS=100 git merge --stat --no-ff master^ >output &&
 339        grep " | " output >actual &&
 340        test_cmp expect actual
 341'
 342
 343cat >expect <<'EOF'
 344 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa | 1000 +++++++++++++++++++++++++++++++++++++++
 345EOF
 346test_expect_success 'merge --stat respects COLUMNS (long filename)' '
 347        COLUMNS=100 git merge --stat --no-ff master >output &&
 348        grep " | " output >actual &&
 349        test_cmp expect actual
 350'
 351
 352test_done