#!/bin/sh # # Copyright (c) 2007 Johannes E. Schindelin # global test_description := ''Test custom diff function name patterns'' source ./test-lib.sh test_expect_success 'setup' ' # a non-trivial custom pattern git config diff.custom1.funcname "!static !String [^ ].*s.*" && # a custom pattern which matches to end of line git config diff.custom2.funcname "......Beer\$" && # alternation in pattern git config diff.custom3.funcname "Beer$" && git config diff.custom3.xfuncname "^[ ]*((public|static).*)$" && # for regexp compilation tests echo A >A.java && echo B >B.java ' global diffpatterns := '" ada bibtex cpp csharp css fortran fountain html java matlab objc pascal perl php python ruby tex custom1 custom2 custom3 '" for p in [$diffpatterns] { test_expect_success "builtin $p pattern compiles" ' echo "*.java diff=$p" >.gitattributes && test_expect_code 1 git diff --no-index \ A.java B.java 2>msg && test_i18ngrep ! fatal msg && test_i18ngrep ! error msg ' test_expect_success "builtin $p wordRegex pattern compiles" ' echo "*.java diff=$p" >.gitattributes && test_expect_code 1 git diff --no-index --word-diff \ A.java B.java 2>msg && test_i18ngrep ! fatal msg && test_i18ngrep ! error msg ' } test_expect_success 'last regexp must not be negated' ' echo "*.java diff=java" >.gitattributes && test_config diff.java.funcname "!static" && test_expect_code 128 git diff --no-index A.java B.java 2>msg && test_i18ngrep ": Last expression must not be negated:" msg ' test_expect_success 'setup hunk header tests' ' for i in $diffpatterns do echo "$i-* diff=$i" done > .gitattributes && # add all test files to the index ( cd "$TEST_DIRECTORY"/t4018 && git --git-dir="$TRASH_DIRECTORY/.git" add . ) && # place modified files in the worktree for i in $(git ls-files) do sed -e "s/ChangeMe/IWasChanged/" <"$TEST_DIRECTORY/t4018/$i" >"$i" || return 1 done ' # check each individual file for i in [$[git ls-files]] { if grep broken $i >/dev/null !2 > !1 { global result := 'failure' } else { global result := 'success' } test_expect_$result "hunk header: $i" " test_when_finished 'cat actual' && # for debugging only git diff -U1 $i >actual && grep '@@ .* @@.*RIGHT' actual " } test_done (CommandList children: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:test_description) op: Equal rhs: {(SQ <"Test custom diff function name patterns">)} spids: [13] ) ] spids: [13] ) (C {(.)} {(./test-lib.sh)}) (C {(test_expect_success)} {(SQ )} { (SQ <"\n"> <"\t# a non-trivial custom pattern\n"> <"\tgit config diff.custom1.funcname \"!static\n"> <"!String\n"> <"[^ \t].*s.*\" &&\n"> <"\n"> <"\t# a custom pattern which matches to end of line\n"> <"\tgit config diff.custom2.funcname \"......Beer\\$\" &&\n"> <"\n"> <"\t# alternation in pattern\n"> <"\tgit config diff.custom3.funcname \"Beer$\" &&\n"> <"\tgit config diff.custom3.xfuncname \"^[ \t]*((public|static).*)$\" &&\n"> <"\n"> <"\t# for regexp compilation tests\n"> <"\techo A >A.java &&\n"> <"\techo B >B.java\n"> ) } ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:diffpatterns) op: Equal rhs: { (DQ ("\n") ("\tada\n") ("\tbibtex\n") ("\tcpp\n") ("\tcsharp\n") ("\tcss\n") ("\tfortran\n") ("\tfountain\n") ("\thtml\n") ("\tjava\n") ("\tmatlab\n") ("\tobjc\n") ("\tpascal\n") ("\tperl\n") ("\tphp\n") ("\tpython\n") ("\truby\n") ("\ttex\n") ("\tcustom1\n") ("\tcustom2\n") ("\tcustom3\n") ) } spids: [50] ) ] spids: [50] ) (ForEach iter_name: p iter_words: [{($ VSub_Name "$diffpatterns")}] do_arg_iter: False body: (DoGroup children: [ (C {(test_expect_success)} {(DQ ("builtin ") ($ VSub_Name "$p") (" pattern compiles"))} { (SQ <"\n"> <"\t\techo \"*.java diff=$p\" >.gitattributes &&\n"> <"\t\ttest_expect_code 1 git diff --no-index \\\n"> <"\t\t\tA.java B.java 2>msg &&\n"> <"\t\ttest_i18ngrep ! fatal msg &&\n"> <"\t\ttest_i18ngrep ! error msg\n"> <"\t"> ) } ) (C {(test_expect_success)} {(DQ ("builtin ") ($ VSub_Name "$p") (" wordRegex pattern compiles"))} { (SQ <"\n"> <"\t\techo \"*.java diff=$p\" >.gitattributes &&\n"> <"\t\ttest_expect_code 1 git diff --no-index --word-diff \\\n"> <"\t\t\tA.java B.java 2>msg &&\n"> <"\t\ttest_i18ngrep ! fatal msg &&\n"> <"\t\ttest_i18ngrep ! error msg\n"> <"\t"> ) } ) ] spids: [84 124] ) spids: [81 -1] ) (C {(test_expect_success)} {(SQ <"last regexp must not be negated">)} { (SQ <"\n"> <"\techo \"*.java diff=java\" >.gitattributes &&\n"> <"\ttest_config diff.java.funcname \"!static\" &&\n"> <"\ttest_expect_code 128 git diff --no-index A.java B.java 2>msg &&\n"> <"\ttest_i18ngrep \": Last expression must not be negated:\" msg\n"> ) } ) (C {(test_expect_success)} {(SQ <"setup hunk header tests">)} { (SQ <"\n"> <"\tfor i in $diffpatterns\n"> <"\tdo\n"> <"\t\techo \"$i-* diff=$i\"\n"> <"\tdone > .gitattributes &&\n"> <"\n"> <"\t# add all test files to the index\n"> <"\t(\n"> <"\t\tcd \"$TEST_DIRECTORY\"/t4018 &&\n"> <"\t\tgit --git-dir=\"$TRASH_DIRECTORY/.git\" add .\n"> <"\t) &&\n"> <"\n"> <"\t# place modified files in the worktree\n"> <"\tfor i in $(git ls-files)\n"> <"\tdo\n"> <"\t\tsed -e \"s/ChangeMe/IWasChanged/\" <\"$TEST_DIRECTORY/t4018/$i\" >\"$i\" || return 1\n"> <"\tdone\n"> ) } ) (ForEach iter_name: i iter_words: [ { (CommandSubPart command_list: (CommandList children:[(C {(git)} {(ls-files)})]) left_token: spids: [178 182] ) } ] do_arg_iter: False body: (DoGroup children: [ (If arms: [ (if_arm cond: [ (SimpleCommand words: [{(grep)} {(broken)} {(DQ ($ VSub_Name "$i"))}] redirects: [ (Redir op_id: Redir_Great fd: -1 arg_word: {(/dev/null)} spids: [197] ) (Redir op_id: Redir_GreatAnd fd: 2 arg_word: {(1)} spids: [200] ) ] ) ] action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:result) op: Equal rhs: {(failure)} spids: [207] ) ] spids: [207] ) ] spids: [-1 204] ) ] else_action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:result) op: Equal rhs: {(success)} spids: [214] ) ] spids: [214] ) ] spids: [211 218] ) (C {(test_expect_) ($ VSub_Name "$result")} {(DQ ("hunk header: ") ($ VSub_Name "$i"))} { (DQ ("\n") ("\t\ttest_when_finished 'cat actual' &&\t# for debugging only\n") ("\t\tgit diff -U1 ") ($ VSub_Name "$i") (" >actual &&\n") ("\t\tgrep '@@ .* @@.*RIGHT' actual\n") ("\t") ) } ) ] spids: [184 239] ) spids: [177 -1] ) (C {(test_done)}) ] )