t / t4018-diff-funcname.shon commit setup: drop repository_format_version global (c90e529)
   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        fortran
  34        fountain
  35        html
  36        java
  37        matlab
  38        objc
  39        pascal
  40        perl
  41        php
  42        python
  43        ruby
  44        tex
  45        custom1
  46        custom2
  47        custom3
  48"
  49
  50for p in $diffpatterns
  51do
  52        test_expect_success "builtin $p pattern compiles" '
  53                echo "*.java diff=$p" >.gitattributes &&
  54                test_expect_code 1 git diff --no-index \
  55                        A.java B.java 2>msg &&
  56                test_i18ngrep ! fatal msg &&
  57                test_i18ngrep ! error msg
  58        '
  59        test_expect_success "builtin $p wordRegex pattern compiles" '
  60                echo "*.java diff=$p" >.gitattributes &&
  61                test_expect_code 1 git diff --no-index --word-diff \
  62                        A.java B.java 2>msg &&
  63                test_i18ngrep ! fatal msg &&
  64                test_i18ngrep ! error msg
  65        '
  66done
  67
  68test_expect_success 'last regexp must not be negated' '
  69        echo "*.java diff=java" >.gitattributes &&
  70        test_config diff.java.funcname "!static" &&
  71        test_expect_code 128 git diff --no-index A.java B.java 2>msg &&
  72        test_i18ngrep ": Last expression must not be negated:" msg
  73'
  74
  75test_expect_success 'setup hunk header tests' '
  76        for i in $diffpatterns
  77        do
  78                echo "$i-* diff=$i"
  79        done > .gitattributes &&
  80
  81        # add all test files to the index
  82        (
  83                cd "$TEST_DIRECTORY"/t4018 &&
  84                git --git-dir="$TRASH_DIRECTORY/.git" add .
  85        ) &&
  86
  87        # place modified files in the worktree
  88        for i in $(git ls-files)
  89        do
  90                sed -e "s/ChangeMe/IWasChanged/" <"$TEST_DIRECTORY/t4018/$i" >"$i" || return 1
  91        done
  92'
  93
  94# check each individual file
  95for i in $(git ls-files)
  96do
  97        if grep broken "$i" >/dev/null 2>&1
  98        then
  99                result=failure
 100        else
 101                result=success
 102        fi
 103        test_expect_$result "hunk header: $i" "
 104                test_when_finished 'cat actual' &&      # for debugging only
 105                git diff -U1 $i >actual &&
 106                grep '@@ .* @@.*RIGHT' actual
 107        "
 108done
 109
 110test_done