t / t4019-diff-wserror.shon commit Merge branch 'maint' of git://repo.or.cz/git-gui into maint (891e85a)
   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 "No problem" >>F
  16
  17'
  18
  19blue_grep='7;34m' ;# ESC [ 7 ; 3 4 m
  20
  21test_expect_success default '
  22
  23        git diff --color >output
  24        grep "$blue_grep" output >error
  25        grep -v "$blue_grep" output >normal
  26
  27        grep Eight normal >/dev/null &&
  28        grep HT error >/dev/null &&
  29        grep With error >/dev/null &&
  30        grep No normal >/dev/null
  31
  32'
  33
  34test_expect_success 'without -trail' '
  35
  36        git config core.whitespace -trail
  37        git diff --color >output
  38        grep "$blue_grep" output >error
  39        grep -v "$blue_grep" output >normal
  40
  41        grep Eight normal >/dev/null &&
  42        grep HT error >/dev/null &&
  43        grep With normal >/dev/null &&
  44        grep No normal >/dev/null
  45
  46'
  47
  48test_expect_success 'without -trail (attribute)' '
  49
  50        git config --unset core.whitespace
  51        echo "F whitespace=-trail" >.gitattributes
  52        git diff --color >output
  53        grep "$blue_grep" output >error
  54        grep -v "$blue_grep" output >normal
  55
  56        grep Eight normal >/dev/null &&
  57        grep HT error >/dev/null &&
  58        grep With normal >/dev/null &&
  59        grep No normal >/dev/null
  60
  61'
  62
  63test_expect_success 'without -space' '
  64
  65        rm -f .gitattributes
  66        git config core.whitespace -space
  67        git diff --color >output
  68        grep "$blue_grep" output >error
  69        grep -v "$blue_grep" output >normal
  70
  71        grep Eight normal >/dev/null &&
  72        grep HT normal >/dev/null &&
  73        grep With error >/dev/null &&
  74        grep No normal >/dev/null
  75
  76'
  77
  78test_expect_success 'without -space (attribute)' '
  79
  80        git config --unset core.whitespace
  81        echo "F whitespace=-space" >.gitattributes
  82        git diff --color >output
  83        grep "$blue_grep" output >error
  84        grep -v "$blue_grep" output >normal
  85
  86        grep Eight normal >/dev/null &&
  87        grep HT normal >/dev/null &&
  88        grep With error >/dev/null &&
  89        grep No normal >/dev/null
  90
  91'
  92
  93test_expect_success 'with indent-non-tab only' '
  94
  95        rm -f .gitattributes
  96        git config core.whitespace indent,-trailing,-space
  97        git diff --color >output
  98        grep "$blue_grep" output >error
  99        grep -v "$blue_grep" output >normal
 100
 101        grep Eight error >/dev/null &&
 102        grep HT normal >/dev/null &&
 103        grep With normal >/dev/null &&
 104        grep No normal >/dev/null
 105
 106'
 107
 108test_expect_success 'with indent-non-tab only (attribute)' '
 109
 110        git config --unset core.whitespace
 111        echo "F whitespace=indent,-trailing,-space" >.gitattributes
 112        git diff --color >output
 113        grep "$blue_grep" output >error
 114        grep -v "$blue_grep" output >normal
 115
 116        grep Eight error >/dev/null &&
 117        grep HT normal >/dev/null &&
 118        grep With normal >/dev/null &&
 119        grep No normal >/dev/null
 120
 121'
 122
 123test_done