diff options
| author | Junio C Hamano <gitster@pobox.com> | 2017-11-28 13:41:50 +0900 |
|---|---|---|
| committer | Junio C Hamano <gitster@pobox.com> | 2017-11-28 13:41:50 +0900 |
| commit | f03490164811f19c8d2222a658398d67b14e905d (patch) | |
| tree | 0427ffa7fee9b19daeb2bf0c92986a27ea9724d2 /t/t7810-grep.sh | |
| parent | 3b49e1b0e900a88cab9e1b035dac83c0dd6ae2b3 (diff) | |
| parent | a5dc20b0701cee53b2c37a4aa3a339b48d5bb298 (diff) | |
| download | git-f03490164811f19c8d2222a658398d67b14e905d.tar.gz | |
Merge branch 'rs/include-comments-before-the-function-header'
"git grep -W", "git diff -W" and their friends learned a heuristic
to extend a pre-context beyond the line that matches the "function
pattern" (aka "diff.*.xfuncname") to include a comment block, if
exists, that immediately precedes it.
* rs/include-comments-before-the-function-header:
grep: show non-empty lines before functions with -W
grep: update boundary variable for pre-context
t7810: improve check of -W with user-defined function lines
xdiff: show non-empty lines before functions with -W
xdiff: factor out is_func_rec()
t4051: add test for comments preceding function lines
Diffstat (limited to 't/t7810-grep.sh')
| -rwxr-xr-x | t/t7810-grep.sh | 41 |
1 files changed, 31 insertions, 10 deletions
diff --git a/t/t7810-grep.sh b/t/t7810-grep.sh index 2a6679c2f5..c02ca735b9 100755 --- a/t/t7810-grep.sh +++ b/t/t7810-grep.sh @@ -60,6 +60,18 @@ test_expect_success setup ' echo " line with leading space3" echo "line without leading space2" } >space && + cat >hello.ps1 <<-\EOF && + # No-op. + function dummy() {} + + # Say hello. + function hello() { + echo "Hello world." + } # hello + + # Still a no-op. + function dummy() {} + EOF git add . && test_tick && git commit -m initial @@ -766,18 +778,27 @@ test_expect_success 'grep -W shows no trailing empty lines' ' test_cmp expected actual ' -cat >expected <<EOF -hello.c= printf("Hello world.\n"); -hello.c: return 0; -hello.c- /* char ?? */ -EOF - test_expect_success 'grep -W with userdiff' ' test_when_finished "rm -f .gitattributes" && - git config diff.custom.xfuncname "(printf.*|})$" && - echo "hello.c diff=custom" >.gitattributes && - git grep -W return >actual && - test_cmp expected actual + git config diff.custom.xfuncname "^function .*$" && + echo "hello.ps1 diff=custom" >.gitattributes && + git grep -W echo >function-context-userdiff-actual +' + +test_expect_success ' includes preceding comment' ' + grep "# Say hello" function-context-userdiff-actual +' + +test_expect_success ' includes function line' ' + grep "=function hello" function-context-userdiff-actual +' + +test_expect_success ' includes matching line' ' + grep ": echo" function-context-userdiff-actual +' + +test_expect_success ' includes last line of the function' ' + grep "} # hello" function-context-userdiff-actual ' for threads in $(test_seq 0 10) |
