From patchwork Fri Apr 23 07:29:43 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12219777 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=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT 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 88493C433B4 for ; Fri, 23 Apr 2021 07:29:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5D71261404 for ; Fri, 23 Apr 2021 07:29:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231397AbhDWHa1 (ORCPT ); Fri, 23 Apr 2021 03:30:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34498 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229993AbhDWHa0 (ORCPT ); Fri, 23 Apr 2021 03:30:26 -0400 Received: from mail-wr1-x42b.google.com (mail-wr1-x42b.google.com [IPv6:2a00:1450:4864:20::42b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CE817C06174A for ; Fri, 23 Apr 2021 00:29:50 -0700 (PDT) Received: by mail-wr1-x42b.google.com with SMTP id x7so47266049wrw.10 for ; Fri, 23 Apr 2021 00:29:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=JjIAVZPe/9FsC2UDs3MoIBC2kgFvixkotYhW9Fr0QZg=; b=b98/GTHlUClgR/rZ/rRhtZvKAW8Dktvkm1ASNYkAKj1frkm93cnOtuAIgbGbt4A2cq K6LSGM/A91Kly4ZaY2yBLE2/iXoqGRwp0iiusy7kV+8mVpVjgFuaEgW71aHEnMaM/t1X SBpPKZcEnLZqOFcnROQyNkqzMFzuxbBzJxqEUkEfXB6aoZHj9g9PTQxbt3lPFcYTHFJP L3JTr8dwYXOTrBHv9njTKhaTI4jU9wzLdjqZvMoOSAnph3vg2JDpoFOzqhYeQ72Do3B2 7bN9Bt/GuargSeDBwu91kvl2OToovSxBUwhNyZ8hlJDBbfBWJL/zYc+a2puhreGojoQ8 lfVQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=JjIAVZPe/9FsC2UDs3MoIBC2kgFvixkotYhW9Fr0QZg=; b=BZgBXIf/H1Ue/GEU1XPbdV8Wvzn4c8HX6MR6DNtFJKGPtWNGe8GlGhyuEIzeCRwUEt 1Kb2iEiwuQK2cjtGBusSuI773xmaLkofrSYmK9QNrQFxjkFEjdqEb13fUuCPShvZDVK+ gAYeMWgY6WAk7SUk8YZE80UnmIRxQSFE0aJofggeHAnihppKxjohtyL/vRSD8vce+xvm oZ+YXKnnJEtsc9Sf/nMHHB5rZzxpJJi/skzLWunaNEAKEJiWhetfGApiATQAPZgICEoG fNs57LwHBEqL67uSRnRx3XzkbmNqli/pVayt6DcDBNgh7lxPmM7DdU7mSAvEkfN7AyJk X/GA== X-Gm-Message-State: AOAM533iNfosPO9lPf9VadYA0GX3GpExVSF7McCsxDLaBiLiNaxuF9d9 ZH7CBwYVmrzQDUqN9v2bJeSCAqLvMroWgw== X-Google-Smtp-Source: ABdhPJw6HVG6JnrC/44RGo8XdHDzS6QV18l8nqnwqcWB4xqtvTWyUwjk2+kttHCpCVmUL8gw2XHs8A== X-Received: by 2002:adf:fb87:: with SMTP id a7mr2927067wrr.58.1619162989301; Fri, 23 Apr 2021 00:29:49 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id r19sm8681648wmq.33.2021.04.23.00.29.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Apr 2021 00:29:48 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Jeff King , Matthieu Moy , Johannes Schindelin , Eric Sunshine , =?utf-8?b?xJBvw6BuIFRy4bqnbiBDw7Ru?= =?utf-8?b?ZyBEYW5o?= , =?utf-8?q?SZEDER_G=C3=A1bor?= , Andreas Schwab , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBC?= =?utf-8?b?amFybWFzb24=?= Subject: [PATCH v3 1/4] test-lib-functions: normalize test_path_is_missing() debugging Date: Fri, 23 Apr 2021 09:29:43 +0200 Message-Id: X-Mailer: git-send-email 2.31.1.734.gdef39492517 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Change the test_path_is_missing() to be consistent with related functions. Since 2caf20c52b7 (test-lib: user-friendly alternatives to test [-d|-f|-e], 2010-08-10) we've been ls -ld-ing the bad path and echo-ing $* if it exists. Let's just say that it exists instead. Signed-off-by: Ævar Arnfjörð Bjarmason --- t/test-lib-functions.sh | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh index 213b1988aa4..2914b398470 100644 --- a/t/test-lib-functions.sh +++ b/t/test-lib-functions.sh @@ -810,12 +810,7 @@ test_path_is_missing () { test "$#" -ne 1 && BUG "1 param" if test -e "$1" then - echo "Path exists:" - ls -ld "$1" - if test $# -ge 1 - then - echo "$*" - fi + echo "Path $1 exists!" false fi } From patchwork Fri Apr 23 07:29:44 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12219781 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=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT 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 A6EBFC433B4 for ; Fri, 23 Apr 2021 07:29:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 738B961404 for ; Fri, 23 Apr 2021 07:29:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240983AbhDWHa3 (ORCPT ); Fri, 23 Apr 2021 03:30:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34500 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229456AbhDWHa2 (ORCPT ); Fri, 23 Apr 2021 03:30:28 -0400 Received: from mail-wr1-x42d.google.com (mail-wr1-x42d.google.com [IPv6:2a00:1450:4864:20::42d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DBAF1C061574 for ; Fri, 23 Apr 2021 00:29:51 -0700 (PDT) Received: by mail-wr1-x42d.google.com with SMTP id j5so46335821wrn.4 for ; Fri, 23 Apr 2021 00:29:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=HVBP/+sizzCsPmKr2ZIGb44P5iJ5X5DZZrV6OKnTuCg=; b=Fw/lw5rJEVM2kCJrpkbAJbXW1utoblqF6wzFY1Uw3mUoAoCkuCr/sMTZNo8rOqdhPM RigteArpF8Ax2GsQs2OdqeGcLY/zJJPJLqKsCc+lbE3dpTZ4KcUkOIPjvhiu80fuBaNY hKywHxIXLVMMUJZAGGF44aHkEGy1JRWBKRN4SswjT6D3OU8NHJAA08kfCwQDyWA+3Xbx tbGi/bsxt/KDetE3UDn+PD+SFPDTqedrvtBpbkd2ex1GS16G+/EwRBMLUHvf+i7IMvMD Hqvjq+5zPOX9q0ul+eX+geeUm+qUNUxno31heC+gL63mMEM3pADzFUtIyjfuWPKTmZLu DyZA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=HVBP/+sizzCsPmKr2ZIGb44P5iJ5X5DZZrV6OKnTuCg=; b=buzX0/PQLp6aIeq6YCet2A7crDiHVpx4R5l2OJoB/ql0QM79ffsr6fh2fbA7ZgqXbj 6zo0rOAkaOL1JdTwB/2YovEoPR1yQeS4Z2wx+VMEDJcIlBGUPhMtnxONcQl41DchVBqj 9OxqEO814UXpyb+9nfJDSMjlSPTltm8YlAnQLqRk9IvjSIRElleqVzE81QlsANcT6HE6 NoVMBi9OaE4nOick8rDGyJlCUQ6fxCzy/eLOFqDtvYIvl6AwVYNUkkAmNp8/HFqqYQXV tV34K7zXMlUlwF/Mq79KjiuZFKRjVsQKVNjLe586/CtxeLPeqdbHFIF44u6eNUOkbvkM gO1w== X-Gm-Message-State: AOAM531eC+OR6WuuUPyVa+Q7NxfQYXsRwOd9moZJw2L9YX7ZckPwcIVY zOoh7kMfKJ/kDpIsqI4a8vrQ43Fgs7Bcsw== X-Google-Smtp-Source: ABdhPJwWGEjWzjXc3TKjYY4ieua8fRGfBQVGMdAxW/64X44gK5KeYw+K+vDrE1dBtD7jCnaPktbHxQ== X-Received: by 2002:adf:dd50:: with SMTP id u16mr2916299wrm.380.1619162990256; Fri, 23 Apr 2021 00:29:50 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id r19sm8681648wmq.33.2021.04.23.00.29.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Apr 2021 00:29:49 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Jeff King , Matthieu Moy , Johannes Schindelin , Eric Sunshine , =?utf-8?b?xJBvw6BuIFRy4bqnbiBDw7Ru?= =?utf-8?b?ZyBEYW5o?= , =?utf-8?q?SZEDER_G=C3=A1bor?= , Andreas Schwab , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBC?= =?utf-8?b?amFybWFzb24=?= Subject: [PATCH v3 2/4] Revert and amend "test-lib-functions: assert correct parameter count" Date: Fri, 23 Apr 2021 09:29:44 +0200 Message-Id: X-Mailer: git-send-email 2.31.1.734.gdef39492517 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org This reverts and amends my my own e7884b353b7 (test-lib-functions: assert correct parameter count, 2021-02-12) in order to improve the -x output. The goal here is to get rid of the verbosity of having e.g. a "test 2 -ne 2" line for every "test_cmp". We use "$@" as an argument to "test" to intentionally feed the "test" operator too many arguments if the functions are called with too many arguments, thus piggy-backing on it to check the number of arguments we get. Before this for each test_cmp invocation we'd emit: + test_cmp expect actual + test 2 -ne 2 + eval diff -u "$@" + diff -u expect actual That "test 2 -ne 2" line is new in my e7884b353b7. As noted in 45a2686441b (test-lib-functions: remove bug-inducing "diagnostics" helper param, 2021-02-12) we had buggy invocations of some of these functions with too many parameters. Now we'll get just: + test_cmp expect actual + eval diff -u "$@" + diff -u expect actual This does not to the "right" thing in cases like: test_path_is_file x -a y Which will now turn into: test -f x -a y I consider that to be OK given the trade-off that any extra checking would produce more verbose trace output. As shown in 45a2686441b we had issues with these functions being invoked with multiple parameters (e.g. a glob) by accident, we don't need to be paranoid in guarding against hostile misuse from our own test suite. While I'm at it change a few functions that relied on a "false" being the last statement in the function to use an explicit "return 1" like the other functions in this file. Signed-off-by: Ævar Arnfjörð Bjarmason --- t/test-lib-functions.sh | 59 +++++++++++++++++++---------------------- 1 file changed, 28 insertions(+), 31 deletions(-) diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh index 2914b398470..0adb9fd124d 100644 --- a/t/test-lib-functions.sh +++ b/t/test-lib-functions.sh @@ -756,41 +756,43 @@ test_external_without_stderr () { } # debugging-friendly alternatives to "test [-f|-d|-e]" -# The commands test the existence or non-existence of $1 +# The commands test the existence or non-existence of +# a given argument. +# +# The pattern of using "$@" to "test" instead of "$1" is not a bug. We +# are counting on "test" to error on too many arguments if more than +# one is given. Checking "$#" explicitly would lead to overly verbose +# -x output. test_path_is_file () { - test "$#" -ne 1 && BUG "1 param" - if ! test -f "$1" + if ! test -f "$@" then - echo "File $1 doesn't exist" - false + echo "File $* doesn't exist" + return 1 fi } test_path_is_dir () { - test "$#" -ne 1 && BUG "1 param" - if ! test -d "$1" + if ! test -d "$@" then - echo "Directory $1 doesn't exist" - false + echo "Directory $* doesn't exist" + return 1 fi } test_path_exists () { - test "$#" -ne 1 && BUG "1 param" - if ! test -e "$1" + if ! test -e "$@" then - echo "Path $1 doesn't exist" - false + echo "Path $* doesn't exist" + return 1 fi } # Check if the directory exists and is empty as expected, barf otherwise. test_dir_is_empty () { - test "$#" -ne 1 && BUG "1 param" - test_path_is_dir "$1" && - if test -n "$(ls -a1 "$1" | egrep -v '^\.\.?$')" + test_path_is_dir "$@" && + if test -n "$(ls -a1 "$@" | egrep -v '^\.\.?$')" then - echo "Directory '$1' is not empty, it contains:" + echo "Directory '$*' is not empty, it contains:" ls -la "$1" return 1 fi @@ -798,19 +800,17 @@ test_dir_is_empty () { # Check if the file exists and has a size greater than zero test_file_not_empty () { - test "$#" = 2 && BUG "2 param" - if ! test -s "$1" + if ! test -s "$@" then - echo "'$1' is not a non-empty file." - false + echo "'$*' is not a non-empty file." + return 1 fi } test_path_is_missing () { - test "$#" -ne 1 && BUG "1 param" - if test -e "$1" + if test -e "$@" then - echo "Path $1 exists!" + echo "Path $* exists!" false fi } @@ -1012,7 +1012,6 @@ test_expect_code () { # - not all diff versions understand "-u" test_cmp () { - test "$#" -ne 2 && BUG "2 param" eval "$GIT_TEST_CMP" '"$@"' } @@ -1042,7 +1041,6 @@ test_cmp_config () { # test_cmp_bin - helper to compare binary files test_cmp_bin () { - test "$#" -ne 2 && BUG "2 param" cmp "$@" } @@ -1096,12 +1094,11 @@ verbose () { # otherwise. test_must_be_empty () { - test "$#" -ne 1 && BUG "1 param" - test_path_is_file "$1" && - if test -s "$1" + test_path_is_file "$@" && + if test -s "$@" then - echo "'$1' is not empty, it contains:" - cat "$1" + echo "'$*' is not empty, it contains:" + cat "$@" return 1 fi } From patchwork Fri Apr 23 07:29:45 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12219785 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=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT 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 74FB9C433ED for ; Fri, 23 Apr 2021 07:29:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4BF34613D5 for ; Fri, 23 Apr 2021 07:29:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241031AbhDWHab (ORCPT ); Fri, 23 Apr 2021 03:30:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34508 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240985AbhDWHa3 (ORCPT ); Fri, 23 Apr 2021 03:30:29 -0400 Received: from mail-wr1-x433.google.com (mail-wr1-x433.google.com [IPv6:2a00:1450:4864:20::433]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9A6CBC061574 for ; Fri, 23 Apr 2021 00:29:52 -0700 (PDT) Received: by mail-wr1-x433.google.com with SMTP id w4so43580594wrt.5 for ; Fri, 23 Apr 2021 00:29:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=y4orDhuCwS1oOUaDMVfR+25mT4d60rEmkyN0ge/lj8I=; b=eheWMxko9G8otS1nJIzXz5k3iLwrdl5Pfjr8Tahr5dAPi96wZEK5kchI0lI2Z0WvYV DfbUyk1pPvD1K8foVQJ1qXIyRvfcADrDPymsm3JEJFNNJanu7urHUrvHCXJr1cdHXRtq eIhS/jiDjfj46GrTqQpf1q6xdCfws7z7F0puv+k/XC3CRxu2nhqEoAl9Af7FztNaOBHY vq9uV4XovNWh7+eGDuJnQfCU7xnwGDaKdIhaa+rzp7lIm6eEsdeR8UgrXIVXnyI2xwF/ FJBFJYL4xDgAgsR6xopHFzFWmol/Xg2rR9UyxxBnnW8+7RTcNMkBDkaZdMphcakqMfJg d7NA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=y4orDhuCwS1oOUaDMVfR+25mT4d60rEmkyN0ge/lj8I=; b=iYBe+dUbwoOk6kXGP9NvjFdhzhvXiC7XwbOASYakyP/1fvmS36ZD3p11EU13FSTDIi vUXmX3PPL1ajDHAA4EJ1RrF85rvP4jt7RSssfYp2Q5WAiSNM7H0SDOFbQeITkDsGLDBQ QPacOTvsrLB6lnJcPyvGQvcH5wGHCsoHlIhGIyO4qn/BUFD144UqCku4Is9v+yP2OU5/ Yvd3REc24YcHTxyEGmTCwJS9XeGt4DclKmKrxdjjey8/wPCVjvOT3tAe1YvuoxJRARd/ LCFMM42AvdJl+ygH5i27UzCdN5VQr0q25rlh98wzksKxZ9Tgsip1YY/w12SXLtuW/I33 rIXQ== X-Gm-Message-State: AOAM530GN9VW8UXyHG95MIx//MdBo3XC19M9rJeFAeIuN/MV1W0o95A6 d0ONl3rUprTiD8MiAbLGq+AX++JD04hBiA== X-Google-Smtp-Source: ABdhPJykxqXdIhTwPpCfJAVBXsyaVVG/YeWEXjBLmj+CLvXO9U/ydgs3/jBa2Jrt2vRTL+dRq6SEFw== X-Received: by 2002:adf:fa49:: with SMTP id y9mr2817920wrr.229.1619162991190; Fri, 23 Apr 2021 00:29:51 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id r19sm8681648wmq.33.2021.04.23.00.29.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Apr 2021 00:29:50 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Jeff King , Matthieu Moy , Johannes Schindelin , Eric Sunshine , =?utf-8?b?xJBvw6BuIFRy4bqnbiBDw7Ru?= =?utf-8?b?ZyBEYW5o?= , =?utf-8?q?SZEDER_G=C3=A1bor?= , Andreas Schwab , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBC?= =?utf-8?b?amFybWFzb24=?= Subject: [PATCH v3 3/4] test-helpers: rename "path-utils is_valid_path" to "is-valid-paths" Date: Fri, 23 Apr 2021 09:29:45 +0200 Message-Id: X-Mailer: git-send-email 2.31.1.734.gdef39492517 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Rename this utility added in d2c84dad1c8 (mingw: refuse to access paths with trailing spaces or periods, 2019-09-05) to make it clear that it expects N number of arguments, and for consistency with dc2d9ba3187 (is_{hfs,ntfs}_dotgitmodules: add tests, 2018-05-12). Let's also make it a dashed "is-valid-paths" instead of "is_valid_path*" to make it easier to grep the helper v.s. the C function it calls. Signed-off-by: Ævar Arnfjörð Bjarmason --- t/helper/test-path-utils.c | 2 +- t/t0060-path-utils.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/t/helper/test-path-utils.c b/t/helper/test-path-utils.c index 313a153209c..eed3068ffb7 100644 --- a/t/helper/test-path-utils.c +++ b/t/helper/test-path-utils.c @@ -454,7 +454,7 @@ int cmd__path_utils(int argc, const char **argv) if (argc > 1 && !strcmp(argv[1], "protect_ntfs_hfs")) return !!protect_ntfs_hfs_benchmark(argc - 1, argv + 1); - if (argc > 1 && !strcmp(argv[1], "is_valid_path")) { + if (argc > 1 && !strcmp(argv[1], "is-valid-paths")) { int res = 0, expect = 1, i; for (i = 2; i < argc; i++) diff --git a/t/t0060-path-utils.sh b/t/t0060-path-utils.sh index 0ff06b5d1b3..e7fb748b19c 100755 --- a/t/t0060-path-utils.sh +++ b/t/t0060-path-utils.sh @@ -469,7 +469,7 @@ test_expect_success 'match .gitmodules' ' ' test_expect_success MINGW 'is_valid_path() on Windows' ' - test-tool path-utils is_valid_path \ + test-tool path-utils is-valid-paths \ win32 \ "win32 x" \ ../hello.txt \ From patchwork Fri Apr 23 07:29:46 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12219783 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=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT 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 ED34AC43460 for ; Fri, 23 Apr 2021 07:29:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C336961404 for ; Fri, 23 Apr 2021 07:29:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241069AbhDWHab (ORCPT ); Fri, 23 Apr 2021 03:30:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34510 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229456AbhDWHa3 (ORCPT ); Fri, 23 Apr 2021 03:30:29 -0400 Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [IPv6:2a00:1450:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9DC27C06174A for ; Fri, 23 Apr 2021 00:29:53 -0700 (PDT) Received: by mail-wr1-x430.google.com with SMTP id s7so47218816wru.6 for ; Fri, 23 Apr 2021 00:29:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=fa+MYlH0vijaOejvZrpDMGOn7QoM9c8+JLlQz8lqplk=; b=RSR06H0l6JVwUiiI1AgMcHAk+CB9k3H8Rl9eRpcFr0TiqFMR12PAF+cSklP43jk5DG 8XflCF1e6HGhgF0Aij/l07PKEVcmjTbNdqt1ijSCtIAAvZNKKzBOUiFKd0tkctI5boUt qBPyRBm7bb9ZM92e6rM7Kk+klgD0XwJJzWhDXZ6WTe+9liHBoQD4n7zBtRCoQ0DI2Aga HDl+rwRUZxxC+M4CQhzsJkT6kxhM+nB/IfpyLXss3HoN6oucj1CIo65nClwA1rfCL4EX 5eGaXoyDH2d094vIww1SunLhKJYYf/xh7kWNXGwYf5cflJTyUeNi8+eol3r1PO20/njH Akqw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=fa+MYlH0vijaOejvZrpDMGOn7QoM9c8+JLlQz8lqplk=; b=DHmhsA+Jfroy+ePHYq4neWZTXZZx5YBE+VR9xhNgH0OXbxTL6DwaujjEW9ZX78VYr6 DlUYrzOO1uTl2C0zzapdycF/0e+zM6UWtKBX2jWSmSbZm2UqkLNrLkNMC1+nD8iM2X1w M3+/83DzBaXbQnlimg3rpGCvQvwH1IdGWkbKHXA8o0VUWfuV/zZYrzFS7ygMFCH9ITxy uhbPWzIhk0x235rFPokM1srz2wVfFtmR31ldzoSLdwppifJuZUwbRtMOXz6UQG8hmZao 8KlaY/QgQm9WMOZoppd85dYXeqZBHWvZwLOVkReOXHyR2UIo+7VP7APNpPKOId4bGeJk Rviw== X-Gm-Message-State: AOAM532COyuFVXU90sWHNZHZ8wlabGXfOw79sq4fiv/rlDOkhlnQf6/J MPbkjMn29V4ihqhZCYdBiWrTGQMK33S3MA== X-Google-Smtp-Source: ABdhPJznIBjFQ+Un857fL5xRrJcbNbdFnDf/WXhhNYcaLmBC5utEv0dPErR+jy6+oUmQSXKPR26CWg== X-Received: by 2002:a5d:4405:: with SMTP id z5mr2872388wrq.313.1619162992073; Fri, 23 Apr 2021 00:29:52 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id r19sm8681648wmq.33.2021.04.23.00.29.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Apr 2021 00:29:51 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Jeff King , Matthieu Moy , Johannes Schindelin , Eric Sunshine , =?utf-8?b?xJBvw6BuIFRy4bqnbiBDw7Ru?= =?utf-8?b?ZyBEYW5o?= , =?utf-8?q?SZEDER_G=C3=A1bor?= , Andreas Schwab , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBC?= =?utf-8?b?amFybWFzb24=?= Subject: [PATCH v3 4/4] test-helpers: split "file-size" into "file-size(s)" Date: Fri, 23 Apr 2021 09:29:46 +0200 Message-Id: X-Mailer: git-send-email 2.31.1.734.gdef39492517 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Split the "file-size" helper into two helpers, one that takes 1 argument, and another one that takes N. This allows us to remove the "BUG" check in test-lib-functions.sh for briefer -x output, and more importantly will clearly distinguish those cases where we expect one argument v.s. many. The use in t1050-large.sh wants to check just one pack, we used to check that explicitly before 53b67a801bb (tests: consolidate the `file_size` function into `test-lib-functions.sh`, 2020-11-07), now we do so again. Signed-off-by: Ævar Arnfjörð Bjarmason --- t/helper/test-path-utils.c | 11 ++++++++++- t/t1050-large.sh | 2 +- t/t5319-multi-pack-index.sh | 6 +++--- t/test-lib-functions.sh | 3 +-- 4 files changed, 15 insertions(+), 7 deletions(-) diff --git a/t/helper/test-path-utils.c b/t/helper/test-path-utils.c index eed3068ffb7..17645da4a1c 100644 --- a/t/helper/test-path-utils.c +++ b/t/helper/test-path-utils.c @@ -280,6 +280,8 @@ static int protect_ntfs_hfs_benchmark(int argc, const char **argv) int cmd__path_utils(int argc, const char **argv) { + int is_file_size, is_file_sizes; + if (argc == 3 && !strcmp(argv[1], "normalize_path_copy")) { char *buf = xmallocz(strlen(argv[2])); int rv = normalize_path_copy(buf, argv[2]); @@ -395,10 +397,17 @@ int cmd__path_utils(int argc, const char **argv) return !!res; } - if (argc > 2 && !strcmp(argv[1], "file-size")) { + is_file_size = !strcmp(argv[1], "file-size"); + is_file_sizes = !strcmp(argv[1], "file-sizes"); + if (argc > 2 && (is_file_size || is_file_sizes)) { int res = 0, i; struct stat st; + if (is_file_size && argc > 3) { + res = error("too many arguments to is-file-size, use is-file-sizes?"); + return res; + } + for (i = 2; i < argc; i++) if (stat(argv[i], &st)) res = error_errno("Cannot stat '%s'", argv[i]); diff --git a/t/t1050-large.sh b/t/t1050-large.sh index 4bab6a513c5..0b76ab0e3f9 100755 --- a/t/t1050-large.sh +++ b/t/t1050-large.sh @@ -23,7 +23,7 @@ do test_expect_success "add with $config" ' test_when_finished "rm -f .git/objects/pack/pack-*.* .git/index" && git $config add large1 && - sz=$(test_file_size .git/objects/pack/pack-*.pack) && + sz=$(test-tool path-utils file-size .git/objects/pack/pack-*.pack) && case "$expect" in small) test "$sz" -le 100000 ;; large) test "$sz" -ge 100000 ;; diff --git a/t/t5319-multi-pack-index.sh b/t/t5319-multi-pack-index.sh index 5641d158dfc..baeda407b90 100755 --- a/t/t5319-multi-pack-index.sh +++ b/t/t5319-multi-pack-index.sh @@ -648,7 +648,7 @@ test_expect_success 'repack with minimum size does not alter existing packs' ' test-tool chmtime =-3 .git/objects/pack/pack-B* && test-tool chmtime =-2 .git/objects/pack/pack-A* && ls .git/objects/pack >expect && - MINSIZE=$(test-tool path-utils file-size .git/objects/pack/*pack | sort -n | head -n 1) && + MINSIZE=$(test-tool path-utils file-sizes .git/objects/pack/*pack | sort -n | head -n 1) && git multi-pack-index repack --batch-size=$MINSIZE && ls .git/objects/pack >actual && test_cmp expect actual @@ -672,7 +672,7 @@ test_expect_success 'repack respects repack.packKeptObjects=false' ' test_line_count = 5 idx-list && test-tool read-midx .git/objects | grep idx >midx-list && test_line_count = 5 midx-list && - THIRD_SMALLEST_SIZE=$(test-tool path-utils file-size .git/objects/pack/*pack | sort -n | sed -n 3p) && + THIRD_SMALLEST_SIZE=$(test-tool path-utils file-sizes .git/objects/pack/*pack | sort -n | sed -n 3p) && BATCH_SIZE=$((THIRD_SMALLEST_SIZE + 1)) && git multi-pack-index repack --batch-size=$BATCH_SIZE && ls .git/objects/pack/*idx >idx-list && @@ -687,7 +687,7 @@ test_expect_success 'repack creates a new pack' ' cd dup && ls .git/objects/pack/*idx >idx-list && test_line_count = 5 idx-list && - THIRD_SMALLEST_SIZE=$(test-tool path-utils file-size .git/objects/pack/*pack | sort -n | head -n 3 | tail -n 1) && + THIRD_SMALLEST_SIZE=$(test-tool path-utils file-sizes .git/objects/pack/*pack | sort -n | head -n 3 | tail -n 1) && BATCH_SIZE=$(($THIRD_SMALLEST_SIZE + 1)) && git multi-pack-index repack --batch-size=$BATCH_SIZE && ls .git/objects/pack/*idx >idx-list && diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh index 0adb9fd124d..602d77dee37 100644 --- a/t/test-lib-functions.sh +++ b/t/test-lib-functions.sh @@ -839,8 +839,7 @@ test_line_count () { } test_file_size () { - test "$#" -ne 1 && BUG "1 param" - test-tool path-utils file-size "$1" + test-tool path-utils file-size "$@" } # Returns success if a comma separated string of keywords ($1) contains a