da14984585f047f8b43dc20d5ec66d98e8b21c2e
   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         ...aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa |    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         ...aaaaaaaaaaaaaaaaaaaaaaaaaa |    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_expect_success "$cmd $verb statGraphWidth config" '
 131                git -c diff.statGraphWidth=26 $cmd $args >output
 132                grep " | " output >actual &&
 133                test_cmp "$expect" actual
 134        '
 135
 136        test "$cmd" != diff || continue
 137
 138        test_expect_success "$cmd --graph $verb not enough COLUMNS (big change)" '
 139                COLUMNS=40 git $cmd $args --graph >output
 140                grep " | " output >actual &&
 141                test_cmp "$expect-graph" actual
 142        '
 143
 144        test_expect_success "$cmd --graph $verb statGraphWidth config" '
 145                git -c diff.statGraphWidth=26 $cmd $args --graph >output
 146                grep " | " output >actual &&
 147                test_cmp "$expect-graph" actual
 148        '
 149done <<\EOF
 150ignores expect80 format-patch -1 --stdout
 151respects expect40 diff HEAD^ HEAD --stat
 152respects expect40 show --stat
 153respects expect40 log -1 --stat
 154EOF
 155
 156
 157cat >expect <<'EOF'
 158 abcd | 1000 ++++++++++++++++++++++++++
 159EOF
 160cat >expect-graph <<'EOF'
 161|  abcd | 1000 ++++++++++++++++++++++++++
 162EOF
 163while read cmd args
 164do
 165        test_expect_success "$cmd --stat=width with big change" '
 166                git $cmd $args --stat=40 >output
 167                grep " | " output >actual &&
 168                test_cmp expect actual
 169        '
 170
 171        test_expect_success "$cmd --stat-width=width with big change" '
 172                git $cmd $args --stat-width=40 >output
 173                grep " | " output >actual &&
 174                test_cmp expect actual
 175        '
 176
 177        test_expect_success "$cmd --stat-graph-width with big change" '
 178                git $cmd $args --stat-graph-width=26 >output
 179                grep " | " output >actual &&
 180                test_cmp expect actual
 181        '
 182
 183        test "$cmd" != diff || continue
 184
 185        test_expect_success "$cmd --stat-width=width --graph with big change" '
 186                git $cmd $args --stat-width=40 --graph >output
 187                grep " | " output >actual &&
 188                test_cmp expect-graph actual
 189        '
 190
 191        test_expect_success "$cmd --stat-graph-width --graph with big change" '
 192                git $cmd $args --stat-graph-width=26 --graph >output
 193                grep " | " output >actual &&
 194                test_cmp expect-graph actual
 195        '
 196done <<\EOF
 197format-patch -1 --stdout
 198diff HEAD^ HEAD --stat
 199show --stat
 200log -1 --stat
 201EOF
 202
 203test_expect_success 'preparation for long filename tests' '
 204        cp abcd aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa &&
 205        git add aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa &&
 206        git commit -m message
 207'
 208
 209cat >expect <<'EOF'
 210 ...aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa | 1000 ++++++++++++
 211EOF
 212cat >expect-graph <<'EOF'
 213|  ...aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa | 1000 ++++++++++++
 214EOF
 215while read cmd args
 216do
 217        test_expect_success "$cmd --stat=width with big change is more balanced" '
 218                git $cmd $args --stat-width=60 >output &&
 219                grep " | " output >actual &&
 220                test_cmp expect actual
 221        '
 222
 223        test "$cmd" != diff || continue
 224
 225        test_expect_success "$cmd --stat=width --graph with big change is balanced" '
 226                git $cmd $args --stat-width=60 --graph >output &&
 227                grep " | " output >actual &&
 228                test_cmp expect-graph actual
 229        '
 230done <<\EOF
 231format-patch -1 --stdout
 232diff HEAD^ HEAD --stat
 233show --stat
 234log -1 --stat
 235EOF
 236
 237cat >expect80 <<'EOF'
 238 ...aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa | 1000 ++++++++++++++++++++
 239EOF
 240cat >expect80-graph <<'EOF'
 241|  ...aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa | 1000 ++++++++++++++++++++
 242EOF
 243cat >expect200 <<'EOF'
 244 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa | 1000 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 245EOF
 246cat >expect200-graph <<'EOF'
 247|  aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa | 1000 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 248EOF
 249while read verb expect cmd args
 250do
 251        test_expect_success "$cmd $verb COLUMNS (long filename)" '
 252                COLUMNS=200 git $cmd $args >output
 253                grep " | " output >actual &&
 254                test_cmp "$expect" actual
 255        '
 256
 257        test "$cmd" != diff || continue
 258
 259        test_expect_success "$cmd --graph $verb COLUMNS (long filename)" '
 260                COLUMNS=200 git $cmd $args --graph >output
 261                grep " | " output >actual &&
 262                test_cmp "$expect-graph" actual
 263        '
 264done <<\EOF
 265ignores expect80 format-patch -1 --stdout
 266respects expect200 diff HEAD^ HEAD --stat
 267respects expect200 show --stat
 268respects expect200 log -1 --stat
 269EOF
 270
 271cat >expect <<'EOF'
 272 abcd | 1000 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 273EOF
 274test_expect_success 'merge --stat respects COLUMNS (big change)' '
 275        git checkout -b branch HEAD^^ &&
 276        COLUMNS=100 git merge --stat --no-ff master^ >output &&
 277        grep " | " output >actual
 278        test_cmp expect actual
 279'
 280
 281cat >expect <<'EOF'
 282 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa | 1000 +++++++++++++++++++++++++++++++++++++++
 283EOF
 284test_expect_success 'merge --stat respects COLUMNS (long filename)' '
 285        COLUMNS=100 git merge --stat --no-ff master >output &&
 286        grep " | " output >actual
 287        test_cmp expect actual
 288'
 289
 290test_done