t / t4019-diff-wserror.shon commit Merge branch 'master' of git://repo.or.cz/git-gui (dfb9a34)
   1#!/bin/sh
   2
   3test_description='diff whitespace error detection'
   4
   5. ./test-lib.sh
   6
   7test_expect_success setup '
   8
   9        git config diff.color.whitespace "blue reverse" &&
  10        >F &&
  11        git add F &&
  12        echo "         Eight SP indent" >>F &&
  13        echo "  HT and SP indent" >>F &&
  14        echo "With trailing SP " >>F &&
  15        echo "Carriage ReturnQ" | tr Q "\015" >>F &&
  16        echo "No problem" >>F
  17
  18'
  19
  20blue_grep='7;34m' ;# ESC [ 7 ; 3 4 m
  21
  22test_expect_success default '
  23
  24        git diff --color >output
  25        grep "$blue_grep" output >error
  26        grep -v "$blue_grep" output >normal
  27
  28        grep Eight normal >/dev/null &&
  29        grep HT error >/dev/null &&
  30        grep With error >/dev/null &&
  31        grep Return error >/dev/null &&
  32        grep No normal >/dev/null
  33
  34'
  35
  36test_expect_success 'without -trail' '
  37
  38        git config core.whitespace -trail
  39        git diff --color >output
  40        grep "$blue_grep" output >error
  41        grep -v "$blue_grep" output >normal
  42
  43        grep Eight normal >/dev/null &&
  44        grep HT error >/dev/null &&
  45        grep With normal >/dev/null &&
  46        grep Return normal >/dev/null &&
  47        grep No normal >/dev/null
  48
  49'
  50
  51test_expect_success 'without -trail (attribute)' '
  52
  53        git config --unset core.whitespace
  54        echo "F whitespace=-trail" >.gitattributes
  55        git diff --color >output
  56        grep "$blue_grep" output >error
  57        grep -v "$blue_grep" output >normal
  58
  59        grep Eight normal >/dev/null &&
  60        grep HT error >/dev/null &&
  61        grep With normal >/dev/null &&
  62        grep Return normal >/dev/null &&
  63        grep No normal >/dev/null
  64
  65'
  66
  67test_expect_success 'without -space' '
  68
  69        rm -f .gitattributes
  70        git config core.whitespace -space
  71        git diff --color >output
  72        grep "$blue_grep" output >error
  73        grep -v "$blue_grep" output >normal
  74
  75        grep Eight normal >/dev/null &&
  76        grep HT normal >/dev/null &&
  77        grep With error >/dev/null &&
  78        grep Return error >/dev/null &&
  79        grep No normal >/dev/null
  80
  81'
  82
  83test_expect_success 'without -space (attribute)' '
  84
  85        git config --unset core.whitespace
  86        echo "F whitespace=-space" >.gitattributes
  87        git diff --color >output
  88        grep "$blue_grep" output >error
  89        grep -v "$blue_grep" output >normal
  90
  91        grep Eight normal >/dev/null &&
  92        grep HT normal >/dev/null &&
  93        grep With error >/dev/null &&
  94        grep Return error >/dev/null &&
  95        grep No normal >/dev/null
  96
  97'
  98
  99test_expect_success 'with indent-non-tab only' '
 100
 101        rm -f .gitattributes
 102        git config core.whitespace indent,-trailing,-space
 103        git diff --color >output
 104        grep "$blue_grep" output >error
 105        grep -v "$blue_grep" output >normal
 106
 107        grep Eight error >/dev/null &&
 108        grep HT normal >/dev/null &&
 109        grep With normal >/dev/null &&
 110        grep Return normal >/dev/null &&
 111        grep No normal >/dev/null
 112
 113'
 114
 115test_expect_success 'with indent-non-tab only (attribute)' '
 116
 117        git config --unset core.whitespace
 118        echo "F whitespace=indent,-trailing,-space" >.gitattributes
 119        git diff --color >output
 120        grep "$blue_grep" output >error
 121        grep -v "$blue_grep" output >normal
 122
 123        grep Eight error >/dev/null &&
 124        grep HT normal >/dev/null &&
 125        grep With normal >/dev/null &&
 126        grep Return normal >/dev/null &&
 127        grep No normal >/dev/null
 128
 129'
 130
 131test_expect_success 'with cr-at-eol' '
 132
 133        rm -f .gitattributes
 134        git config core.whitespace cr-at-eol
 135        git diff --color >output
 136        grep "$blue_grep" output >error
 137        grep -v "$blue_grep" output >normal
 138
 139        grep Eight normal >/dev/null &&
 140        grep HT error >/dev/null &&
 141        grep With error >/dev/null &&
 142        grep Return normal >/dev/null &&
 143        grep No normal >/dev/null
 144
 145'
 146
 147test_expect_success 'with cr-at-eol (attribute)' '
 148
 149        git config --unset core.whitespace
 150        echo "F whitespace=trailing,cr-at-eol" >.gitattributes
 151        git diff --color >output
 152        grep "$blue_grep" output >error
 153        grep -v "$blue_grep" output >normal
 154
 155        grep Eight normal >/dev/null &&
 156        grep HT error >/dev/null &&
 157        grep With error >/dev/null &&
 158        grep Return normal >/dev/null &&
 159        grep No normal >/dev/null
 160
 161'
 162
 163test_done