t / t4018-diff-funcname.shon commit tests: defang pager tests by explicitly disabling the log.mailmap warning (ef60740)
   1#!/bin/sh
   2#
   3# Copyright (c) 2007 Johannes E. Schindelin
   4#
   5
   6test_description='Test custom diff function name patterns'
   7
   8. ./test-lib.sh
   9
  10test_expect_success 'setup' '
  11        # a non-trivial custom pattern
  12        git config diff.custom1.funcname "!static
  13!String
  14[^      ].*s.*" &&
  15
  16        # a custom pattern which matches to end of line
  17        git config diff.custom2.funcname "......Beer\$" &&
  18
  19        # alternation in pattern
  20        git config diff.custom3.funcname "Beer$" &&
  21        git config diff.custom3.xfuncname "^[   ]*((public|static).*)$" &&
  22
  23        # for regexp compilation tests
  24        echo A >A.java &&
  25        echo B >B.java
  26'
  27
  28diffpatterns="
  29        ada
  30        bibtex
  31        cpp
  32        csharp
  33        css
  34        fortran
  35        fountain
  36        golang
  37        html
  38        java
  39        matlab
  40        objc
  41        pascal
  42        perl
  43        php
  44        python
  45        ruby
  46        rust
  47        tex
  48        custom1
  49        custom2
  50        custom3
  51"
  52
  53for p in $diffpatterns
  54do
  55        test_expect_success "builtin $p pattern compiles" '
  56                echo "*.java diff=$p" >.gitattributes &&
  57                test_expect_code 1 git diff --no-index \
  58                        A.java B.java 2>msg &&
  59                test_i18ngrep ! fatal msg &&
  60                test_i18ngrep ! error msg
  61        '
  62        test_expect_success "builtin $p wordRegex pattern compiles" '
  63                echo "*.java diff=$p" >.gitattributes &&
  64                test_expect_code 1 git diff --no-index --word-diff \
  65                        A.java B.java 2>msg &&
  66                test_i18ngrep ! fatal msg &&
  67                test_i18ngrep ! error msg
  68        '
  69done
  70
  71test_expect_success 'last regexp must not be negated' '
  72        echo "*.java diff=java" >.gitattributes &&
  73        test_config diff.java.funcname "!static" &&
  74        test_expect_code 128 git diff --no-index A.java B.java 2>msg &&
  75        test_i18ngrep ": Last expression must not be negated:" msg
  76'
  77
  78test_expect_success 'setup hunk header tests' '
  79        for i in $diffpatterns
  80        do
  81                echo "$i-* diff=$i"
  82        done > .gitattributes &&
  83
  84        # add all test files to the index
  85        (
  86                cd "$TEST_DIRECTORY"/t4018 &&
  87                git --git-dir="$TRASH_DIRECTORY/.git" add .
  88        ) &&
  89
  90        # place modified files in the worktree
  91        for i in $(git ls-files)
  92        do
  93                sed -e "s/ChangeMe/IWasChanged/" <"$TEST_DIRECTORY/t4018/$i" >"$i" || return 1
  94        done
  95'
  96
  97# check each individual file
  98for i in $(git ls-files)
  99do
 100        if grep broken "$i" >/dev/null 2>&1
 101        then
 102                result=failure
 103        else
 104                result=success
 105        fi
 106        test_expect_$result "hunk header: $i" "
 107                test_when_finished 'cat actual' &&      # for debugging only
 108                git diff -U1 $i >actual &&
 109                grep '@@ .* @@.*RIGHT' actual
 110        "
 111done
 112
 113test_done