1#!/bin/sh
   2test_description='diff whitespace error detection'
   4. ./test-lib.sh
   6test_expect_success setup '
   8        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'
  19blue_grep='7;34m' ;# ESC [ 7 ; 3 4 m
  21test_expect_success default '
  23        git diff --color >output
  25        grep "$blue_grep" output >error
  26        grep -v "$blue_grep" output >normal
  27        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'
  35test_expect_success 'without -trail' '
  37        git config core.whitespace -trail
  39        git diff --color >output
  40        grep "$blue_grep" output >error
  41        grep -v "$blue_grep" output >normal
  42        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'
  50test_expect_success 'without -trail (attribute)' '
  52        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        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'
  66test_expect_success 'without -space' '
  68        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        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'
  82test_expect_success 'without -space (attribute)' '
  84        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        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'
  98test_expect_success 'with indent-non-tab only' '
 100        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        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'
 114test_expect_success 'with indent-non-tab only (attribute)' '
 116        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        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'
 130test_expect_success 'with cr-at-eol' '
 132        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        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'
 146test_expect_success 'with cr-at-eol (attribute)' '
 148        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        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'
 162test_done