From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS31976 209.132.180.0/23 X-Spam-Status: No, score=-3.0 required=3.0 tests=AWL,BAYES_00, FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_HI,RP_MATCHES_RCVD shortcircuit=no autolearn=ham autolearn_force=no version=3.4.0 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by dcvr.yhbt.net (Postfix) with ESMTP id E675E201C8 for ; Sat, 18 Nov 2017 18:10:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S966889AbdKRSKh (ORCPT ); Sat, 18 Nov 2017 13:10:37 -0500 Received: from mout.web.de ([212.227.17.11]:53588 "EHLO mout.web.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S966794AbdKRSKg (ORCPT ); Sat, 18 Nov 2017 13:10:36 -0500 Received: from [192.168.178.36] ([91.20.49.242]) by smtp.web.de (mrweb103 [213.165.67.124]) with ESMTPSA (Nemesis) id 0MIvXZ-1eIbXn44Gv-002TUW; Sat, 18 Nov 2017 19:06:19 +0100 Subject: [PATCH 4/6] t7810: improve check of -W with user-defined function lines To: Git List Cc: Junio C Hamano , Vegard Nossum References: <790c2344-a71e-7089-9000-f9b37a4a5cd9@web.de> From: =?UTF-8?Q?Ren=c3=a9_Scharfe?= Message-ID: Date: Sat, 18 Nov 2017 19:06:16 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.4.0 MIME-Version: 1.0 In-Reply-To: <790c2344-a71e-7089-9000-f9b37a4a5cd9@web.de> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-Provags-ID: V03:K0:fjngfQFfBiLzwZunt2kCScKgKIE0F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JIQ7+NMQM2Gb2rHVkEzUt6b2FVvkK2f9nK0sxh G5+PrR+8B/H52zv7wmlu0cgW+FhFxLgVARrpUyVDcOg75ozzTNhQlS6+KBf6cjMSMVFnbuiJr 3NSou+SJtQmGtGE1ooAtxM1OrlO/i4DKNe3hAVjYgYLTlnB1OX+Psr1Xfzn2ljI2ohki8qU2s ug== Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org The check for function context (-W) together with user-defined function line patterns reuses hello.c and pretends it's written in a language in which function lines contain either "printf" or a trailing curly brace. That's a bit obscure. Make the test easier to read by adding a small PowerShell script, using a simple, but meaningful expression, and separating out checks for different aspects into dedicated tests instead of simply matching the whole output byte for byte. Also include a test for showing comments before function lines like git diff -W does, which is currently failing because that functionality is not implemented for git grep, yet. Signed-off-by: Rene Scharfe --- t/t7810-grep.sh | 41 +++++++++++++++++++++++++++++++---------- 1 file changed, 31 insertions(+), 10 deletions(-) diff --git a/t/t7810-grep.sh b/t/t7810-grep.sh index 2a6679c2f5..632b905611 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 <.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_failure ' 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) -- 2.15.0