From patchwork Wed Apr 21 14:58:34 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: 12216329 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 87D54C433B4 for ; Wed, 21 Apr 2021 14:58:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5B5E16144B for ; Wed, 21 Apr 2021 14:58:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243733AbhDUO7T (ORCPT ); Wed, 21 Apr 2021 10:59:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35994 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243727AbhDUO7R (ORCPT ); Wed, 21 Apr 2021 10:59:17 -0400 Received: from mail-wm1-x32d.google.com (mail-wm1-x32d.google.com [IPv6:2a00:1450:4864:20::32d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 31925C06138A for ; Wed, 21 Apr 2021 07:58:43 -0700 (PDT) Received: by mail-wm1-x32d.google.com with SMTP id q123-20020a1c43810000b029012c7d852459so2777784wma.0 for ; Wed, 21 Apr 2021 07:58:43 -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=okHkhyBoLVzo0EidXSeP/EVHyRLow2pvIsyTn5/kb5k=; b=lZPtXCpqTRaBnQvZlXzB+BwKkY83w/FV9SlzIJxDU0nbSmnZj/7yiSxPEnnPB9qva3 /c059O4ZSnoU2wvO5oIZcRnQBT7TkbFOE6tpZKwx3nGIcWKQRU6MCpSO2Kd4F3ey46/Q UjXxjiZxUt6X8/bu9rRA/KqAS0hNtQqaIA9PMFJBqS9h43iYRuPTSfoHcIpxubs0wonO yMbKCtcV3yr8zg+esrMmsOJ9/fBK2p9lNiViRpc99uxdBcGA+mZ4im0FStaERPQDxPvO miBqTvabKxW+BUsGXrzLBKGYpYaah5gREly6j1L/7vWeZXsyvB3XNTwzPp0FTYdeF3eo AGgg== 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=okHkhyBoLVzo0EidXSeP/EVHyRLow2pvIsyTn5/kb5k=; b=Kiue1Rcln84lD4k58ddPCVRFI2OqpFH8qyIRKCo/mQCGaKc14cGMejjdrfuD8qRznS 6bN0N3Diim00rz3RYZKXvBnCZjYBBR+oORWKFiL6IaJLwzZOtwOuIzs8Q8NcGz6m1WIs LApyH7kKbtPKMAeH4nPXbpzJ22bxrqUD6whOYohvb3jDEV8SO/ooGFTp/dLdh/9bgTDa djH70VfcUS9BxiaUwI3qW801GxazhD6B044hAW31qxdQIwNLy+1k0KukLu5sX686XRPD C5LRALtdZaKdX33Dgy8iUoP1oXP6BgfoHckkoboUJZeGq0hm8oILXL74TKnTtpyoynQT dGfQ== X-Gm-Message-State: AOAM5308il/SHxg3lWU6gLIWT1STPGpgO3TKPL9iC+gvV9DupKLsFvFh daqHdZCXKNTQt8nAs9oZMxQOmnn8CPs6RQ== X-Google-Smtp-Source: ABdhPJwQIugKOMZ9ay+nqwx6Lu0owLHgpyNZYoi6NlMlOYOaSUsTuO+s1RMRNqmmbmm/Pjnu1X0pNw== X-Received: by 2002:a1c:e20a:: with SMTP id z10mr9964994wmg.158.1619017121649; Wed, 21 Apr 2021 07:58:41 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id g1sm3394316wrd.69.2021.04.21.07.58.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Apr 2021 07:58:41 -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 v2 1/5] test-lib-functions: normalize test_path_is_missing() debugging Date: Wed, 21 Apr 2021 16:58:34 +0200 Message-Id: X-Mailer: git-send-email 2.31.1.723.g9a7f2f961d4 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 bd64a15c731..0232cc9f46d 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 Wed Apr 21 14:58:35 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: 12216327 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 86C27C43460 for ; Wed, 21 Apr 2021 14:58:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4D07961454 for ; Wed, 21 Apr 2021 14:58:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243735AbhDUO7T (ORCPT ); Wed, 21 Apr 2021 10:59:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36002 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243722AbhDUO7R (ORCPT ); Wed, 21 Apr 2021 10:59:17 -0400 Received: from mail-wm1-x32e.google.com (mail-wm1-x32e.google.com [IPv6:2a00:1450:4864:20::32e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5EC48C06174A for ; Wed, 21 Apr 2021 07:58:44 -0700 (PDT) Received: by mail-wm1-x32e.google.com with SMTP id n4-20020a05600c4f84b029013151278decso1395874wmq.4 for ; Wed, 21 Apr 2021 07:58:44 -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=k7G1Mzbi4o74nyXO8mzA2M3o4XSGGiDAtZ8/sn4OkYQ=; b=ngQnG9zN+VQDxRFpdS+e87ywqM0vLVivFRcg5EnQWnf4CCrUWqHrP5t+GwFE5GBSPU QaqDHnJMcCgfnpoTn0W0AQJpnsCBw5GB865YFs9AkaFxNtavIuNsxquyA+7uEiYCRdDG TL8kSEv+UnhXHNiL6akvsa4Y8INMm9gpzwMb7qvea8MTS7Lhw1yDUwow6GPBs47oEbuA 9CWOtCLFk40ta+CtKD+eB0GnAyh2P8rNzLH2eo2WX9vwO0nUGMzP9Or/JayjbtodCf3L 3XIS6GXX1DnzD5CJP79SmCCSZrga8SmIcy5n7pxj7OJmIDtHR19WTeGzB4sAk5EDoEEj qHBA== 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=k7G1Mzbi4o74nyXO8mzA2M3o4XSGGiDAtZ8/sn4OkYQ=; b=h690Pt7q8DMhzG2AW2NvzRf0D0EYkp0M2A7idxe8j8oXZxYTknvKFzt0ZnvNb65KdM fIb1SB+iDnOEQwbXziVPaIYRpfPrb64M9tJCRvb82a83EzfvcFDNdQWuiQVLqJk2ZRz6 FHRCJILkcq3eCn0QLxLcgFzFNkD1iVHPqmmwww3jg8I72HrJwI7g6xpyqmMXyrhkL6vT H3ZyQyN7I6MaBwr+5E+NhFYw6MR6yjAp325nCG5MYRkONXrZZAOTfIXkrZfxP8Du6G/y palfC8fsDe04lcUOXjHoqHxO5ymzLm2oRkCFztnCPN3a/A0uZAKsm2uM6jP+HbzisexJ ZXCQ== X-Gm-Message-State: AOAM5304Aw9be1A6swIpU476rPsMg+hpfXMvSQHbxXN1LosLtGU5QbOT 55LVDfbit3txrN8DRsxmutn9f0DSHFHdPw== X-Google-Smtp-Source: ABdhPJyNVfwFelhFcaC4A2y2BU3qq6kqLky7wqX4gJySQRa0pI03HiEhx+PkkjRJulRQHe21vcWmKA== X-Received: by 2002:a05:600c:3397:: with SMTP id o23mr10037322wmp.26.1619017122667; Wed, 21 Apr 2021 07:58:42 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id g1sm3394316wrd.69.2021.04.21.07.58.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Apr 2021 07:58:42 -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 v2 2/5] Revert and amend "test-lib-functions: assert correct parameter count" Date: Wed, 21 Apr 2021 16:58:35 +0200 Message-Id: X-Mailer: git-send-email 2.31.1.723.g9a7f2f961d4 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 0232cc9f46d..f8f5bf9de1e 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 "$@" } @@ -1103,12 +1101,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 Wed Apr 21 14:58:36 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: 12216331 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.8 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,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 D61A2C433ED for ; Wed, 21 Apr 2021 14:58:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A91256144B for ; Wed, 21 Apr 2021 14:58:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242866AbhDUO7W (ORCPT ); Wed, 21 Apr 2021 10:59:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36004 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243738AbhDUO7S (ORCPT ); Wed, 21 Apr 2021 10:59:18 -0400 Received: from mail-wm1-x32a.google.com (mail-wm1-x32a.google.com [IPv6:2a00:1450:4864:20::32a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 220EAC06138B for ; Wed, 21 Apr 2021 07:58:45 -0700 (PDT) Received: by mail-wm1-x32a.google.com with SMTP id p10-20020a1c544a0000b02901387e17700fso1405991wmi.2 for ; Wed, 21 Apr 2021 07:58:45 -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=h/9xCQ7wJooRRmN/xo95+MIKfVh9rMU7PTFmQBTEBZY=; b=tvhBuJVHVtfelTOq6kY4bMMgDYmiZftNzPcHjgTarD9VURMxquHJI0mhQy/RjTbY3w 7N+Oj1kysPf5uNDgxXDJltl7Dlooea1KTFJ1ZnzqtmiXDF+95qzO+6AUvJCpo7ECDItQ 1zKKCLDntOwjTvw0N/f3A6LLe9L56fONJIxkHHa+aLi3YUx3UxdEQ2BcNSOvJD5VAv0V xmLhfvs/u9YlSufZVklCCz1BwZBDBgRa4P/bJzKTXBoCykovUgcVIqv6zWNS1fdDjv9R WnwBFLao5VnZaxQLh+AK0ETyoOiQJeCdnGHAT9GWwrQYnV1SS7Wm/rufr6x7s8i5/vYu soGg== 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=h/9xCQ7wJooRRmN/xo95+MIKfVh9rMU7PTFmQBTEBZY=; b=iRDhDsJoVfqBVznN8rmAv5yKayYmWFM6eQq0nECV6QbDXpWSzaGH0PV3s/Y5cBQuWd Tsb8gcNU0186U6FLbnBqPnMQkQFs//HGl/mhHMOMvystDm0V2QzxK8OaKFcdbZDPu/mG T2Ud6n8GPyQkvEkar+nVBp2Qm1fVyagJzA3jiqy5TeToEHwyPwWXXDAUtB2evtx57I7f shKoq6TWFQquAUy0Lz9dIHoSZ1eXwzoGr9fAW8KdBJ36I0E+TPL60c8ov4gQ1dk9Vncx bM6k98fMSWDP+qzCOCWrHRgGiKhSO/HDCmgeM+9w0aCS8MPAr7xdFx9iZH8RPl99be6f hIjA== X-Gm-Message-State: AOAM530WvbzSYyQBwej8wemZypMVQqnX9OkJn5Oq80kSYrmNiMNAtQlA 7BDa5khY2kgvt4s3XPasAmIpsEzmRvAUDQ== X-Google-Smtp-Source: ABdhPJyg/z4aU9JQ6HD0GP+KsgrM/JYPxwi8qD56IqnA7jcy5cMIqGuk0kWjUnArrn7MpdH1NZ380w== X-Received: by 2002:a7b:c4cc:: with SMTP id g12mr10183825wmk.3.1619017123561; Wed, 21 Apr 2021 07:58:43 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id g1sm3394316wrd.69.2021.04.21.07.58.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Apr 2021 07:58:42 -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 v2 3/5] test helpers: remove unused test-tool path-utils slice-tests Date: Wed, 21 Apr 2021 16:58:36 +0200 Message-Id: X-Mailer: git-send-email 2.31.1.723.g9a7f2f961d4 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org This utility was last used in the code removed in 4c2c38e800f (ci: modification of main.yml to use cmake for vs-build job, 2020-06-26). Let's also remove this now-dead code. Signed-off-by: Ævar Arnfjörð Bjarmason --- t/helper/test-path-utils.c | 31 ------------------------------- 1 file changed, 31 deletions(-) diff --git a/t/helper/test-path-utils.c b/t/helper/test-path-utils.c index 313a153209c..3d7c0f1d19d 100644 --- a/t/helper/test-path-utils.c +++ b/t/helper/test-path-utils.c @@ -177,14 +177,6 @@ static int is_dotgitmodules(const char *path) return is_hfs_dotgitmodules(path) || is_ntfs_dotgitmodules(path); } -static int cmp_by_st_size(const void *a, const void *b) -{ - intptr_t x = (intptr_t)((struct string_list_item *)a)->util; - intptr_t y = (intptr_t)((struct string_list_item *)b)->util; - - return x > y ? -1 : (x < y ? +1 : 0); -} - /* * A very simple, reproducible pseudo-random generator. Copied from * `test-genrandom.c`. @@ -428,29 +420,6 @@ int cmd__path_utils(int argc, const char **argv) return 0; } - if (argc > 5 && !strcmp(argv[1], "slice-tests")) { - int res = 0; - long offset, stride, i; - struct string_list list = STRING_LIST_INIT_NODUP; - struct stat st; - - offset = strtol(argv[2], NULL, 10); - stride = strtol(argv[3], NULL, 10); - if (stride < 1) - stride = 1; - for (i = 4; i < argc; i++) - if (stat(argv[i], &st)) - res = error_errno("Cannot stat '%s'", argv[i]); - else - string_list_append(&list, argv[i])->util = - (void *)(intptr_t)st.st_size; - QSORT(list.items, list.nr, cmp_by_st_size); - for (i = offset; i < list.nr; i+= stride) - printf("%s\n", list.items[i].string); - - return !!res; - } - if (argc > 1 && !strcmp(argv[1], "protect_ntfs_hfs")) return !!protect_ntfs_hfs_benchmark(argc - 1, argv + 1); From patchwork Wed Apr 21 14:58:37 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: 12216333 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 4F910C433B4 for ; Wed, 21 Apr 2021 14:58:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1F15C6144D for ; Wed, 21 Apr 2021 14:58:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242910AbhDUO73 (ORCPT ); Wed, 21 Apr 2021 10:59:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36006 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243739AbhDUO7T (ORCPT ); Wed, 21 Apr 2021 10:59:19 -0400 Received: from mail-wm1-x32d.google.com (mail-wm1-x32d.google.com [IPv6:2a00:1450:4864:20::32d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0611BC06174A for ; Wed, 21 Apr 2021 07:58:46 -0700 (PDT) Received: by mail-wm1-x32d.google.com with SMTP id p10-20020a1c544a0000b02901387e17700fso1406022wmi.2 for ; Wed, 21 Apr 2021 07:58:45 -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=EsExcjIp7owzXlWpsf1OOJSOZ1CPO4ebGhp1WzAO1cQ=; b=WxqwtNIoCUd0kZ5PX9PBKJnHn2yBUp0xDpCCOau8Z+SjFmjvcZjsxk2K82rgthrw73 S3FSkpIKQZY9wTd7nkMDkxSBOL5tiTVHbAwOr5fZEaPq9v4xFn+mWca5zklnCT1IAqPk 87CoDWwHQ6hei3rRtGdFV6Ph5d6WxyokFKcGtdGdqpEEbSeG5ybBQO8jhPVqjSaptKzN 6AN3vd/N9aPLcJpX0nvFTrzupCmQEWaDCmEu0u2knSnZJqAYMmzyzmcCRvf0CR9mji7b RXAbSxUugrbqQoLu/v3QoT59UjPIxc0SqA3dipVaJ8IgNo2T3hg77Y60BNSjBT4qsBxC N7WQ== 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=EsExcjIp7owzXlWpsf1OOJSOZ1CPO4ebGhp1WzAO1cQ=; b=XyI/GHZXAYUQ3jutqKN/QuJLtLqQWMAMCVuEsmUZXyPEQwrWHaMiKdN1PBTGU+w8df NQ9+2CF+E98vI/GMhsM4ypEKR3H/U7+GOADYx3mJMg5OWFZniZ+G7+yTi9Hj/qmJtcTy BOcfzbWiutxPFTNX9dDcMQY2CThvy9S4KP/01NfnmU76JanIPRDe0NS34WMqaH473sZB /Br0gidb70uYorv29Lr5RVRaDd3M+LMYBqgeqg5lZt61neMJ/j74MDMri47x2+Cw59nl LrStZvM8yFsm5zKJwM+lGt52qxw190JCweBIVmYOmjzaQs4TL4wgi4NVqJQ9T8AWn/to i5YQ== X-Gm-Message-State: AOAM531v89LNxehZ447ku2qfYczeVZKbHir1iJBXvGD4Ygtbxp9rAWlv 9xtw64ccF3QI3H0EgCJW2uar+29CKy2mXg== X-Google-Smtp-Source: ABdhPJxXngo0BDzOhH6WYXaBr8T4XIjoiBCi0wktE1lj+PXD07a8FzrL6ApEuJ7zloZWYdTAUqZE7A== X-Received: by 2002:a05:600c:b47:: with SMTP id k7mr10172118wmr.109.1619017124484; Wed, 21 Apr 2021 07:58:44 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id g1sm3394316wrd.69.2021.04.21.07.58.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Apr 2021 07:58:43 -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 v2 4/5] test-helpers: rename "path-utils is_valid_path" to "is-valid-paths" Date: Wed, 21 Apr 2021 16:58:37 +0200 Message-Id: X-Mailer: git-send-email 2.31.1.723.g9a7f2f961d4 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 3d7c0f1d19d..af7d7fd5454 100644 --- a/t/helper/test-path-utils.c +++ b/t/helper/test-path-utils.c @@ -423,7 +423,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 Wed Apr 21 14:58:38 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: 12216335 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 D86B2C43460 for ; Wed, 21 Apr 2021 14:58:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B46936144B for ; Wed, 21 Apr 2021 14:58:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240026AbhDUO7a (ORCPT ); Wed, 21 Apr 2021 10:59:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36018 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243748AbhDUO7U (ORCPT ); Wed, 21 Apr 2021 10:59:20 -0400 Received: from mail-wm1-x333.google.com (mail-wm1-x333.google.com [IPv6:2a00:1450:4864:20::333]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 13C12C06138B for ; Wed, 21 Apr 2021 07:58:47 -0700 (PDT) Received: by mail-wm1-x333.google.com with SMTP id d200-20020a1c1dd10000b02901384767d4a5so1462937wmd.3 for ; Wed, 21 Apr 2021 07:58:47 -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=a1a5Sw4kknoAv7zzJUvHLJsCwqLqdiICbS6UhWYFhFw=; b=UKu5nPWD85DWonILPwpUinvibccC92LlRvAEKVEDZVebfI0xZRGs+mIkQQ4Dj4nhQc Tc4ONk56BI2O91mMeAsI6ExGG8f7yUB26qdtJGPC1nngwXUsoVuM71p2OuS8+Vk3lVLO QZL46j+TRztBp4LJd2T2xmYIyntL+8Inj3krqdGdhbzCgJA81Fv+l8HImzs2mLRZC9rg yKqlK10aV4Ga9gFnVY4jRYnvXUoUn/EzxDsnzRZmlpJvHRaaBZenKlDVlPoC3XGM5nEg /N2rnek7owiiGCYEz8qTyr+If5RIiLkUQjKk46gIgWxVLPgMeOFBitY06VZwO2b0uNmc t0vA== 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=a1a5Sw4kknoAv7zzJUvHLJsCwqLqdiICbS6UhWYFhFw=; b=l2Th1/3HoqB3pbg4N+lkH4Nwj7dYr1GUdTXlJxIy38SSGBKimgpN8ZE4UJfQXPWNiQ AjSlU9vaQm2iud665sAJJgf5HyoY0nhrZVfAoLeRLPKZOQx5/iovchbbyr3XGD9yKOPi 8sbBc9ChEtrVBUoUgvDBHiusrZRkU/yt5Im4HzCskJqVECiutNPwN57SlqlHfdP084ta h3itaKk2VQ/nSx1DigHNzbTrNj/gy8190M06PvkH82W8cGUYphAnt2xcuSvW7uSnu/ba ELX2QvNpvlYgnI7BNDi+AHF13esQAST8lqRXqOE824f794NJfkHabAEhl36LlcqbY8qq WsbA== X-Gm-Message-State: AOAM532XOmz5uAcjNjLJ9ugALH26QcmlxJjSkFr+q8YMqbhyQEDCMPzd 2DMEX39KXK/DPPoM7NRAfr9uNasT1lnkjQ== X-Google-Smtp-Source: ABdhPJxyYDDBuAxuDHqFGDU4yJLuIbWiNO9VExk1WPBp8PleX9g+FkajOUMMpyYogStreHJKNgO1Og== X-Received: by 2002:a7b:c201:: with SMTP id x1mr9994587wmi.124.1619017125424; Wed, 21 Apr 2021 07:58:45 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id g1sm3394316wrd.69.2021.04.21.07.58.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Apr 2021 07:58:44 -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 v2 5/5] test-helpers: split "file-size" into "file-size(s)" Date: Wed, 21 Apr 2021 16:58:38 +0200 Message-Id: X-Mailer: git-send-email 2.31.1.723.g9a7f2f961d4 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 af7d7fd5454..23970db8183 100644 --- a/t/helper/test-path-utils.c +++ b/t/helper/test-path-utils.c @@ -272,6 +272,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]); @@ -387,10 +389,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 f8f5bf9de1e..20d1f94fd97 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