Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8035FC43461 for ; Fri, 30 Apr 2021 16:33:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6475761186 for ; Fri, 30 Apr 2021 16:33:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230380AbhD3QeN convert rfc822-to-8bit (ORCPT ); Fri, 30 Apr 2021 12:34:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46674 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231652AbhD3QeD (ORCPT ); Fri, 30 Apr 2021 12:34:03 -0400 Received: from mav.lukeshu.com (mav.lukeshu.com [IPv6:2001:19f0:5c00:8069:5400:ff:fe26:6a86]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 29D4EC06174A for ; Fri, 30 Apr 2021 09:33:14 -0700 (PDT) Received: from lukeshu-dw-thinkpad (unknown [IPv6:2601:281:8200:26:4e34:88ff:fe48:5521]) by mav.lukeshu.com (Postfix) with ESMTPSA id 1E03680590; Fri, 30 Apr 2021 12:33:11 -0400 (EDT) Date: Fri, 30 Apr 2021 10:33:10 -0600 Message-ID: <87im43pwah.wl-lukeshu@lukeshu.com> From: Luke Shumaker To: =?ISO-8859-1?Q?=C6var_Arnfj=F6r=F0?= Bjarmason Cc: Luke Shumaker , git@vger.kernel.org, Avery Pennarun , Charles Bailey , Danny Lin , "David A .\ Greene" , David Aguilar , James Denholm , Jeff King , Jonathan Nieder , Junio C Hamano , =?UTF-8?B?Tmd1eeG7hW4g?= =?ISO-8859-1?Q?Th=E1i_?= =?UTF-8?B?Tmfhu41j?= Duy , Roger L Strain , Techlive Zheng , Eric Sunshine , Luke Shumaker Subject: Re: [PATCH v3 06/30] subtree: t7900: use 'test' for string equality In-Reply-To: <87r1isxffw.fsf@evledraar.gmail.com> References: <20210426174525.3937858-1-lukeshu@lukeshu.com> <20210427211748.2607474-1-lukeshu@lukeshu.com> <20210427211748.2607474-7-lukeshu@lukeshu.com> <87r1isxffw.fsf@evledraar.gmail.com> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM-LB/1.14.9 (=?ISO-8859-4?Q?Goj=F2?=) APEL-LB/10.8 EasyPG/1.0.0 Emacs/27.2 (x86_64-pc-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8BIT Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org On Fri, 30 Apr 2021 03:55:04 -0600, Ævar Arnfjörð Bjarmason wrote: > > > On Tue, Apr 27 2021, Luke Shumaker wrote: > > > From: Luke Shumaker > > > > t7900-subtree.sh defines its own `check_equal A B` function, instead of > > just using `test A = B` like all of the other tests. Don't be special, > > get rid of `check_equal` in favor of `test`. > > > > Signed-off-by: Luke Shumaker > > --- > > contrib/subtree/t/t7900-subtree.sh | 60 ++++++++++++------------------ > > 1 file changed, 24 insertions(+), 36 deletions(-) > > > > diff --git a/contrib/subtree/t/t7900-subtree.sh b/contrib/subtree/t/t7900-subtree.sh > > index 12b8cb03c7..76183153c9 100755 > > --- a/contrib/subtree/t/t7900-subtree.sh > > +++ b/contrib/subtree/t/t7900-subtree.sh > > @@ -28,18 +28,6 @@ create () { > > git add "$1" > > } > > > > -check_equal () { > > - test_debug 'echo' > > - test_debug "echo \"check a:\" \"{$1}\"" > > - test_debug "echo \" b:\" \"{$2}\"" > > - if test "$1" = "$2" > > - then > > - return 0 > > - else > > - return 1 > > - fi > > -} > > It looks like the reason this was used because when this fails just > having the "test" makes for bad debugging. I.e. if the values don't > match the $1 and $2 are not aligned, so it's hard to eyeball what went > wrong. It's easy to make that assumption, but looking at the history it seems the "actual" reason it exists is that it's vestigial from before the subtree tests used test-lib.sh, and echoing it like that was the only way you'd get feedback. > These days this is more idiomatic: > > echo "Add [...]" >expected > last_commit_message >actual && > test_cmp expected actual > > So I think in this case a better narrower improvement would be to keep > the check_equal function. I wonder if we shouldn't just in general in > t/test-lib.sh have a test_cmp_str for this use-case. I.e. a trivial > wrapper that echos the two strings to a file for you, before running > diff(1). But it's been my experience that the tests are already impossible to debug without passing `-x`, so everything from `check_equal` ends up being just noise. And also I figured if `test` is good enough for t9350-fast-export.sh, then it's good enough for t7900-subtree.sh... after working with subtree, I'd accidentally written a couple of the checks in one of my fast-export patchsets using `check_equal`. Being special makes things harder to hack on. -- Happy hacking, ~ Luke Shumaker