3d823af38f11bff3e9e617a9b5eb32e6667bc343
   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
  85
  86cat >expect200 <<'EOF'
  87 abcd | 1000 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  88EOF
  89
  90while read verb expect cmd args
  91do
  92        test_expect_success "$cmd $verb COLUMNS (big change)" '
  93                COLUMNS=200 git $cmd $args >output
  94                grep " | " output >actual &&
  95                test_cmp "$expect" actual
  96        '
  97done <<\EOF
  98ignores expect80 format-patch -1 --stdout
  99respects expect200 diff HEAD^ HEAD --stat
 100respects expect200 show --stat
 101respects expect200 log -1 --stat
 102EOF
 103
 104cat >expect40 <<'EOF'
 105 abcd | 1000 ++++++++++++++++++++++++++
 106EOF
 107
 108while read verb expect cmd args
 109do
 110        test_expect_success "$cmd $verb not enough COLUMNS (big change)" '
 111                COLUMNS=40 git $cmd $args >output
 112                grep " | " output >actual &&
 113                test_cmp "$expect" actual
 114        '
 115done <<\EOF
 116ignores expect80 format-patch -1 --stdout
 117respects expect40 diff HEAD^ HEAD --stat
 118respects expect40 show --stat
 119respects expect40 log -1 --stat
 120EOF
 121
 122
 123cat >expect <<'EOF'
 124 abcd | 1000 ++++++++++++++++++++++++++
 125EOF
 126while read cmd args
 127do
 128        test_expect_success "$cmd --stat=width with big change" '
 129                git $cmd $args --stat=40 >output
 130                grep " | " output >actual &&
 131                test_cmp expect actual
 132        '
 133
 134        test_expect_success "$cmd --stat-width=width with big change" '
 135                git $cmd $args --stat-width=40 >output
 136                grep " | " output >actual &&
 137                test_cmp expect actual
 138        '
 139
 140        test_expect_success "$cmd --stat-graph--width with big change" '
 141                git $cmd $args --stat-graph-width=26 >output
 142                grep " | " output >actual &&
 143                test_cmp expect actual
 144        '
 145done <<\EOF
 146format-patch -1 --stdout
 147diff HEAD^ HEAD --stat
 148show --stat
 149log -1 --stat
 150EOF
 151
 152test_expect_success 'preparation for long filename tests' '
 153        cp abcd aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa &&
 154        git add aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa &&
 155        git commit -m message
 156'
 157
 158cat >expect <<'EOF'
 159 ...aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa | 1000 ++++++++++++
 160EOF
 161while read cmd args
 162do
 163        test_expect_success "$cmd --stat=width with big change is more balanced" '
 164                git $cmd $args --stat-width=60 >output &&
 165                grep " | " output >actual &&
 166                test_cmp expect actual
 167        '
 168done <<\EOF
 169format-patch -1 --stdout
 170diff HEAD^ HEAD --stat
 171show --stat
 172log -1 --stat
 173EOF
 174
 175cat >expect80 <<'EOF'
 176 ...aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa | 1000 ++++++++++++++++++++
 177EOF
 178cat >expect200 <<'EOF'
 179 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa | 1000 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 180EOF
 181while read verb expect cmd args
 182do
 183        test_expect_success "$cmd $verb COLUMNS (long filename)" '
 184                COLUMNS=200 git $cmd $args >output
 185                grep " | " output >actual &&
 186                test_cmp "$expect" actual
 187        '
 188done <<\EOF
 189ignores expect80 format-patch -1 --stdout
 190respects expect200 diff HEAD^ HEAD --stat
 191respects expect200 show --stat
 192respects expect200 log -1 --stat
 193EOF
 194
 195cat >expect <<'EOF'
 196 abcd | 1000 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 197EOF
 198test_expect_success 'merge --stat respects COLUMNS (big change)' '
 199        git checkout -b branch HEAD^^ &&
 200        COLUMNS=100 git merge --stat --no-ff master^ >output &&
 201        grep " | " output >actual
 202        test_cmp expect actual
 203'
 204
 205cat >expect <<'EOF'
 206 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa | 1000 +++++++++++++++++++++++++++++++++++++++
 207EOF
 208test_expect_success 'merge --stat respects COLUMNS (long filename)' '
 209        COLUMNS=100 git merge --stat --no-ff master >output &&
 210        grep " | " output >actual
 211        test_cmp expect actual
 212'
 213
 214test_done