t / t7002-grep.shon commit sha1_file.c: learn about index version 2 (74e34e1)
   1#!/bin/sh
   2#
   3# Copyright (c) 2006 Junio C Hamano
   4#
   5
   6test_description='git grep various.
   7'
   8
   9. ./test-lib.sh
  10
  11test_expect_success setup '
  12        {
  13                echo foo mmap bar
  14                echo foo_mmap bar
  15                echo foo_mmap bar mmap
  16                echo foo mmap bar_mmap
  17                echo foo_mmap bar mmap baz
  18        } >file &&
  19        echo x x xx x >x &&
  20        echo y yy >y &&
  21        echo zzz > z &&
  22        mkdir t &&
  23        echo test >t/t &&
  24        git add file x y z t/t &&
  25        git commit -m initial
  26'
  27
  28for H in HEAD ''
  29do
  30        case "$H" in
  31        HEAD)   HC='HEAD:' L='HEAD' ;;
  32        '')     HC= L='in working tree' ;;
  33        esac
  34
  35        test_expect_success "grep -w $L" '
  36                {
  37                        echo ${HC}file:1:foo mmap bar
  38                        echo ${HC}file:3:foo_mmap bar mmap
  39                        echo ${HC}file:4:foo mmap bar_mmap
  40                        echo ${HC}file:5:foo_mmap bar mmap baz
  41                } >expected &&
  42                git grep -n -w -e mmap $H >actual &&
  43                diff expected actual
  44        '
  45
  46        test_expect_success "grep -w $L (x)" '
  47                {
  48                        echo ${HC}x:1:x x xx x
  49                } >expected &&
  50                git grep -n -w -e "x xx* x" $H >actual &&
  51                diff expected actual
  52        '
  53
  54        test_expect_success "grep -w $L (y-1)" '
  55                {
  56                        echo ${HC}y:1:y yy
  57                } >expected &&
  58                git grep -n -w -e "^y" $H >actual &&
  59                diff expected actual
  60        '
  61
  62        test_expect_success "grep -w $L (y-2)" '
  63                : >expected &&
  64                if git grep -n -w -e "^y y" $H >actual
  65                then
  66                        echo should not have matched
  67                        cat actual
  68                        false
  69                else
  70                        diff expected actual
  71                fi
  72        '
  73
  74        test_expect_success "grep -w $L (z)" '
  75                : >expected &&
  76                if git grep -n -w -e "^z" $H >actual
  77                then
  78                        echo should not have matched
  79                        cat actual
  80                        false
  81                else
  82                        diff expected actual
  83                fi
  84        '
  85
  86        test_expect_success "grep $L (t-1)" '
  87                echo "${HC}t/t:1:test" >expected &&
  88                git grep -n -e test $H >actual &&
  89                diff expected actual
  90        '
  91
  92        test_expect_success "grep $L (t-2)" '
  93                echo "${HC}t:1:test" >expected &&
  94                (
  95                        cd t &&
  96                        git grep -n -e test $H
  97                ) >actual &&
  98                diff expected actual
  99        '
 100
 101        test_expect_success "grep $L (t-3)" '
 102                echo "${HC}t/t:1:test" >expected &&
 103                (
 104                        cd t &&
 105                        git grep --full-name -n -e test $H
 106                ) >actual &&
 107                diff expected actual
 108        '
 109
 110done
 111
 112test_done