From patchwork Wed Jul 21 22:57:40 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: 12392425 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 01F09C6377C for ; Wed, 21 Jul 2021 22:58:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E57DC6127C for ; Wed, 21 Jul 2021 22:58:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230394AbhGUWRw (ORCPT ); Wed, 21 Jul 2021 18:17:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60562 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230104AbhGUWRv (ORCPT ); Wed, 21 Jul 2021 18:17:51 -0400 Received: from mail-wm1-x330.google.com (mail-wm1-x330.google.com [IPv6:2a00:1450:4864:20::330]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 05B34C061757 for ; Wed, 21 Jul 2021 15:58:27 -0700 (PDT) Received: by mail-wm1-x330.google.com with SMTP id l6so2249104wmq.0 for ; Wed, 21 Jul 2021 15:58:26 -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=JtdU5nEPFSFO4vDTc8tv0rUkhERuOnv7sYNyEiZODEU=; b=BlZyYYNyWhPTyV4KI7riwVVivSFHehshYJMV53zC8SATXmYh5aWUqUkuV/aXj/zuOt tjIjctKf5R1FeacgIXWbbAS6gmpls71cTNEh/xZwvjcRBKPnDvJstw/t6gjibj6eebVA 2R9YutjKo0ekRHRwYeDpkqnFKh/hAdUhnlZutYm6FeuD6gxaCV5ROMKVXunB10wE7OIy smZKruLEjb5FvwZ89FD818R/OBiFuUn+mFOsKAcdw0zWU1C1aA19zdVAetK4krpg0MYr PWytIBsT46gAFgbUsNrPKA3CI+7Jo3V1UHmWGB8OKm6+kssgwyyQ0kBbLTdPgrq+ZKNV ygXg== 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=JtdU5nEPFSFO4vDTc8tv0rUkhERuOnv7sYNyEiZODEU=; b=Uy01ahN6+5yF/Rhkn5s8nZL0exO9sUn4DfBD2db/QfiewPMVKyLNUzTUTB50/EkVsc I5REiVqPtkOFqAy+wEBxyvBbXKcXOVBsD0zeeSgQ74B90+2V8VcH4ZR2WJf7PsweX2Ln 6oZD5TfD9yM9SmRMmDkr6t2MKTg32YSJzzg4cStExvQcJRAfB1UJU3zjFi5qkmza6Uu2 Z11n150fT6m4w8BLH1PX+DAaeQv+pZerq5VjvUX3afNNhQl5pLDjBIXEnEFAPWyHOzaP YIopYu8meJGodvJXonvz5dDCQvVKDBTT5iB9LGq4qj1xOPhlamaO2I9B0aAMlVxCx2he HPnA== X-Gm-Message-State: AOAM533u42tTyMkKvdI7A9Oe4loC5EiGcuYHjLWs8E7Hc0N7be11xhxJ Wkn3uglK50PesyIb8LYuHIMYP1lbR07gGA== X-Google-Smtp-Source: ABdhPJzKQ2rKNArDuHpWibM8QRD9HORSyQ6Ygc5jzWXlFgu7hNSBvmNPLSUDZD+dFSf14jQRjFm8PQ== X-Received: by 2002:a1c:f214:: with SMTP id s20mr39540276wmc.14.1626908305295; Wed, 21 Jul 2021 15:58:25 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id g18sm23129818wmk.37.2021.07.21.15.58.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Jul 2021 15:58:24 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Jeff King , Felipe Contreras , Adam Spiers , Thomas Rast , Ilya Bobyr , Patrick Steinhardt , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v2 1/8] test-lib tests: move "run_sub_test" to a new lib-subtest.sh Date: Thu, 22 Jul 2021 00:57:40 +0200 Message-Id: X-Mailer: git-send-email 2.32.0.955.ge7c5360f7e7 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Move the "check_sub_test_lib_test()" and its sister functions to a new lib-subtest.sh. In the future (not in this series) I'd like to test test-lib's output in a more targeted and smaller test, and I'll need these functions to do that. Signed-off-by: Ævar Arnfjörð Bjarmason --- t/lib-subtest.sh | 86 ++++++++++++++++++++++++++++++++++++++++++++++ t/t0000-basic.sh | 88 +----------------------------------------------- 2 files changed, 87 insertions(+), 87 deletions(-) create mode 100644 t/lib-subtest.sh diff --git a/t/lib-subtest.sh b/t/lib-subtest.sh new file mode 100644 index 00000000000..3cfe09911a2 --- /dev/null +++ b/t/lib-subtest.sh @@ -0,0 +1,86 @@ +_run_sub_test_lib_test_common () { + neg="$1" name="$2" descr="$3" # stdin is the body of the test code + shift 3 + + # intercept pseudo-options at the front of the argument list that we + # will not pass to child script + skip= + while test $# -gt 0 + do + case "$1" in + --skip=*) + skip=${1#--*=} + shift + ;; + *) + break + ;; + esac + done + + mkdir "$name" && + ( + # Pretend we're not running under a test harness, whether we + # are or not. The test-lib output depends on the setting of + # this variable, so we need a stable setting under which to run + # the sub-test. + sane_unset HARNESS_ACTIVE && + cd "$name" && + write_script "$name.sh" "$TEST_SHELL_PATH" <<-EOF && + test_description='$descr (run in sub test-lib) + + This is run in a sub test-lib so that we do not get incorrect + passing metrics + ' + + # Point to the t/test-lib.sh, which isn't in ../ as usual + . "\$TEST_DIRECTORY"/test-lib.sh + EOF + cat >>"$name.sh" && + export TEST_DIRECTORY && + # The child test re-sources GIT-BUILD-OPTIONS and may thus + # override the test output directory. We thus pass it as an + # explicit override to the child. + TEST_OUTPUT_DIRECTORY_OVERRIDE=$(pwd) && + export TEST_OUTPUT_DIRECTORY_OVERRIDE && + GIT_SKIP_TESTS=$skip && + export GIT_SKIP_TESTS && + sane_unset GIT_TEST_FAIL_PREREQS && + if test -z "$neg" + then + ./"$name.sh" "$@" >out 2>err + else + ! ./"$name.sh" "$@" >out 2>err + fi + ) +} + +run_sub_test_lib_test () { + _run_sub_test_lib_test_common '' "$@" +} + +run_sub_test_lib_test_err () { + _run_sub_test_lib_test_common '!' "$@" +} + +check_sub_test_lib_test () { + name="$1" # stdin is the expected output from the test + ( + cd "$name" && + test_must_be_empty err && + sed -e 's/^> //' -e 's/Z$//' >expect && + test_cmp expect out + ) +} + +check_sub_test_lib_test_err () { + name="$1" # stdin is the expected output from the test + # expected error output is in descriptor 3 + ( + cd "$name" && + sed -e 's/^> //' -e 's/Z$//' >expect.out && + test_cmp expect.out out && + sed -e 's/^> //' -e 's/Z$//' <&3 >expect.err && + test_cmp expect.err err + ) +} diff --git a/t/t0000-basic.sh b/t/t0000-basic.sh index cb87768513c..a3865dd77ba 100755 --- a/t/t0000-basic.sh +++ b/t/t0000-basic.sh @@ -19,6 +19,7 @@ modification *should* take notice and update the test vectors here. ' . ./test-lib.sh +. "$TEST_DIRECTORY"/lib-subtest.sh try_local_xy () { local x="local" y="alsolocal" && @@ -66,93 +67,6 @@ test_expect_success 'success is reported like this' ' : ' -_run_sub_test_lib_test_common () { - neg="$1" name="$2" descr="$3" # stdin is the body of the test code - shift 3 - - # intercept pseudo-options at the front of the argument list that we - # will not pass to child script - skip= - while test $# -gt 0 - do - case "$1" in - --skip=*) - skip=${1#--*=} - shift - ;; - *) - break - ;; - esac - done - - mkdir "$name" && - ( - # Pretend we're not running under a test harness, whether we - # are or not. The test-lib output depends on the setting of - # this variable, so we need a stable setting under which to run - # the sub-test. - sane_unset HARNESS_ACTIVE && - cd "$name" && - write_script "$name.sh" "$TEST_SHELL_PATH" <<-EOF && - test_description='$descr (run in sub test-lib) - - This is run in a sub test-lib so that we do not get incorrect - passing metrics - ' - - # Point to the t/test-lib.sh, which isn't in ../ as usual - . "\$TEST_DIRECTORY"/test-lib.sh - EOF - cat >>"$name.sh" && - export TEST_DIRECTORY && - # The child test re-sources GIT-BUILD-OPTIONS and may thus - # override the test output directory. We thus pass it as an - # explicit override to the child. - TEST_OUTPUT_DIRECTORY_OVERRIDE=$(pwd) && - export TEST_OUTPUT_DIRECTORY_OVERRIDE && - GIT_SKIP_TESTS=$skip && - export GIT_SKIP_TESTS && - sane_unset GIT_TEST_FAIL_PREREQS && - if test -z "$neg" - then - ./"$name.sh" "$@" >out 2>err - else - ! ./"$name.sh" "$@" >out 2>err - fi - ) -} - -run_sub_test_lib_test () { - _run_sub_test_lib_test_common '' "$@" -} - -run_sub_test_lib_test_err () { - _run_sub_test_lib_test_common '!' "$@" -} - -check_sub_test_lib_test () { - name="$1" # stdin is the expected output from the test - ( - cd "$name" && - test_must_be_empty err && - sed -e 's/^> //' -e 's/Z$//' >expect && - test_cmp expect out - ) -} - -check_sub_test_lib_test_err () { - name="$1" # stdin is the expected output from the test - # expected error output is in descriptor 3 - ( - cd "$name" && - sed -e 's/^> //' -e 's/Z$//' >expect.out && - test_cmp expect.out out && - sed -e 's/^> //' -e 's/Z$//' <&3 >expect.err && - test_cmp expect.err err - ) -} - test_expect_success 'pretend we have a fully passing test suite' ' run_sub_test_lib_test full-pass "3 passing tests" <<-\EOF && for i in 1 2 3 From patchwork Wed Jul 21 22:57:41 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: 12392427 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 14F34C6377D for ; Wed, 21 Jul 2021 22:58:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0699F61289 for ; Wed, 21 Jul 2021 22:58:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230405AbhGUWRy (ORCPT ); Wed, 21 Jul 2021 18:17:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60564 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230363AbhGUWRv (ORCPT ); Wed, 21 Jul 2021 18:17:51 -0400 Received: from mail-wm1-x329.google.com (mail-wm1-x329.google.com [IPv6:2a00:1450:4864:20::329]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CC603C061575 for ; Wed, 21 Jul 2021 15:58:27 -0700 (PDT) Received: by mail-wm1-x329.google.com with SMTP id f10-20020a05600c4e8ab029023e8d74d693so1855950wmq.3 for ; Wed, 21 Jul 2021 15:58:27 -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=DTH7QIIKvJ8B/mSNTKnpfDIz0Ng8TlVu1oRt4zoIdVc=; b=nkjsGR5DnHI8YH53xrD/6/ri3425xn6xSBU8sa4/1RN/cwlQv0lABYYqn3EHBM/hGi JNqfrF+QJ/WzHxbjGHL3t4xhhmXzTO4mTutdCFlvj2lRPaDbeRzS2LtJjXVgf7LHrSI+ Qzoz+5wAh1+QeLXAdXSwc8MkZLK07/91FcertNCbwEsMlm11pcFbuBn+E3csncoNW31y d6aIk4Rihjb8xFvSXYQj4A5sfNYSRxJAo+KJWXmOVIACJEkplOydQz+6NBs5KerUXb9/ EdEBsvoHPDPu4q6+KAkwUkNCIsHYmbutdOn8T2CbTGnJkz8KNX9AjmA6wSMtDTPJSM8I 7epA== 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=DTH7QIIKvJ8B/mSNTKnpfDIz0Ng8TlVu1oRt4zoIdVc=; b=K9teVGtG2U/9zmIcfXvFtxmI9UJyDMRNquykyYDrlA48yGf05kFQ2zU4qCRXm/sdkU FnHeEjecf40KIkIAJxfl3vJWFgW55jnLgrqta0jKXcKqodshhfOewvvwcz4EKJ7vfP+U 4SnQeIqa462KVzTSaAGCTz85RvTz+0dxTc0PVfjY5by77oAQSrzRbmj22r/xr5jbbUyu DhXD9YNYnM/eExKMB0DLGj27ZRAO28u5M2kDkQKm+iTTHefN+HDcrwB9T3xALnfgcOE/ BYDm84P2QSyNrVuOxQBhLFmbWcMGaAoZtvsiN2bsFqBCnVzyfjVWeYIRdZKX4rwoTSf9 y1Vw== X-Gm-Message-State: AOAM53165QPJKXmsZEFTY1uu+Pn+IFqHcAXg/zygUHpSywVkvhnLioFK aLBv9Hq7AunPT1Rr9sFeRe3XG9s/g3n38w== X-Google-Smtp-Source: ABdhPJw7yQtRLoSJlQElNJgjThIcVw8GinyjsGXVP16sdrjXZ9BuPMSngGFkGtUtpFgL+kaKeEFk3w== X-Received: by 2002:a1c:1f12:: with SMTP id f18mr6009898wmf.183.1626908306094; Wed, 21 Jul 2021 15:58:26 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id g18sm23129818wmk.37.2021.07.21.15.58.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Jul 2021 15:58:25 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Jeff King , Felipe Contreras , Adam Spiers , Thomas Rast , Ilya Bobyr , Patrick Steinhardt , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v2 2/8] test-lib tests: split up "write and run" into two functions Date: Thu, 22 Jul 2021 00:57:41 +0200 Message-Id: X-Mailer: git-send-email 2.32.0.955.ge7c5360f7e7 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Refactor the function to write and run tests of the test-lib.sh output into two functions. When this was added back in 565b6fa87bb (tests: refactor mechanics of testing in a sub test-lib, 2012-12-16) there was no reason to do this, but since we started supporting test arguments in 517cd55fd51 (test-lib: self-test that --verbose works, 2013-06-23) we've started to write out duplicate tests simply to test different arguments, now we'll be able to re-use them. This change doesn't consolidate any of those tests yet, it just makes it possible to do so. All the changes in t0000-basic.sh are a simple search-replacement. Signed-off-by: Ævar Arnfjörð Bjarmason --- t/lib-subtest.sh | 46 ++++++++++++++++++++++-------- t/t0000-basic.sh | 74 ++++++++++++++++++++++++------------------------ 2 files changed, 71 insertions(+), 49 deletions(-) diff --git a/t/lib-subtest.sh b/t/lib-subtest.sh index 3cfe09911a2..8f3f6dddcf4 100644 --- a/t/lib-subtest.sh +++ b/t/lib-subtest.sh @@ -1,3 +1,22 @@ +write_sub_test_lib_test () { + name="$1" descr="$2" # stdin is the body of the test code + mkdir "$name" && + ( + cd "$name" && + write_script "$name.sh" "$TEST_SHELL_PATH" <<-EOF && + test_description='$descr (run in sub test-lib) + + This is run in a sub test-lib so that we do not get incorrect + passing metrics + ' + + # Point to the t/test-lib.sh, which isn't in ../ as usual + . "\$TEST_DIRECTORY"/test-lib.sh + EOF + cat >>"$name.sh" + ) +} + _run_sub_test_lib_test_common () { neg="$1" name="$2" descr="$3" # stdin is the body of the test code shift 3 @@ -18,25 +37,15 @@ _run_sub_test_lib_test_common () { esac done - mkdir "$name" && ( + cd "$name" && + # Pretend we're not running under a test harness, whether we # are or not. The test-lib output depends on the setting of # this variable, so we need a stable setting under which to run # the sub-test. sane_unset HARNESS_ACTIVE && - cd "$name" && - write_script "$name.sh" "$TEST_SHELL_PATH" <<-EOF && - test_description='$descr (run in sub test-lib) - This is run in a sub test-lib so that we do not get incorrect - passing metrics - ' - - # Point to the t/test-lib.sh, which isn't in ../ as usual - . "\$TEST_DIRECTORY"/test-lib.sh - EOF - cat >>"$name.sh" && export TEST_DIRECTORY && # The child test re-sources GIT-BUILD-OPTIONS and may thus # override the test output directory. We thus pass it as an @@ -55,6 +64,18 @@ _run_sub_test_lib_test_common () { ) } +write_and_run_sub_test_lib_test () { + name="$1" descr="$2" # stdin is the body of the test code + write_sub_test_lib_test "$@" || return 1 + _run_sub_test_lib_test_common '' "$@" +} + +write_and_run_sub_test_lib_test_err () { + name="$1" descr="$2" # stdin is the body of the test code + write_sub_test_lib_test "$@" || return 1 + _run_sub_test_lib_test_common '!' "$@" +} + run_sub_test_lib_test () { _run_sub_test_lib_test_common '' "$@" } @@ -84,3 +105,4 @@ check_sub_test_lib_test_err () { test_cmp expect.err err ) } + diff --git a/t/t0000-basic.sh b/t/t0000-basic.sh index a3865dd77ba..a7c5aaacab6 100755 --- a/t/t0000-basic.sh +++ b/t/t0000-basic.sh @@ -68,7 +68,7 @@ test_expect_success 'success is reported like this' ' ' test_expect_success 'pretend we have a fully passing test suite' ' - run_sub_test_lib_test full-pass "3 passing tests" <<-\EOF && + write_and_run_sub_test_lib_test full-pass "3 passing tests" <<-\EOF && for i in 1 2 3 do test_expect_success "passing test #$i" "true" @@ -85,7 +85,7 @@ test_expect_success 'pretend we have a fully passing test suite' ' ' test_expect_success 'pretend we have a partially passing test suite' ' - run_sub_test_lib_test_err \ + write_and_run_sub_test_lib_test_err \ partial-pass "2/3 tests passing" <<-\EOF && test_expect_success "passing test #1" "true" test_expect_success "failing test #2" "false" @@ -103,7 +103,7 @@ test_expect_success 'pretend we have a partially passing test suite' ' ' test_expect_success 'pretend we have a known breakage' ' - run_sub_test_lib_test failing-todo "A failing TODO test" <<-\EOF && + write_and_run_sub_test_lib_test failing-todo "A failing TODO test" <<-\EOF && test_expect_success "passing test" "true" test_expect_failure "pretend we have a known breakage" "false" test_done @@ -118,7 +118,7 @@ test_expect_success 'pretend we have a known breakage' ' ' test_expect_success 'pretend we have fixed a known breakage' ' - run_sub_test_lib_test passing-todo "A passing TODO test" <<-\EOF && + write_and_run_sub_test_lib_test passing-todo "A passing TODO test" <<-\EOF && test_expect_failure "pretend we have fixed a known breakage" "true" test_done EOF @@ -130,7 +130,7 @@ test_expect_success 'pretend we have fixed a known breakage' ' ' test_expect_success 'pretend we have fixed one of two known breakages (run in sub test-lib)' ' - run_sub_test_lib_test partially-passing-todos \ + write_and_run_sub_test_lib_test partially-passing-todos \ "2 TODO tests, one passing" <<-\EOF && test_expect_failure "pretend we have a known breakage" "false" test_expect_success "pretend we have a passing test" "true" @@ -149,7 +149,7 @@ test_expect_success 'pretend we have fixed one of two known breakages (run in su ' test_expect_success 'pretend we have a pass, fail, and known breakage' ' - run_sub_test_lib_test_err \ + write_and_run_sub_test_lib_test_err \ mixed-results1 "mixed results #1" <<-\EOF && test_expect_success "passing test" "true" test_expect_success "failing test" "false" @@ -168,7 +168,7 @@ test_expect_success 'pretend we have a pass, fail, and known breakage' ' ' test_expect_success 'pretend we have a mix of all possible results' ' - run_sub_test_lib_test_err \ + write_and_run_sub_test_lib_test_err \ mixed-results2 "mixed results #2" <<-\EOF && test_expect_success "passing test" "true" test_expect_success "passing test" "true" @@ -204,7 +204,7 @@ test_expect_success 'pretend we have a mix of all possible results' ' ' test_expect_success 'test --verbose' ' - run_sub_test_lib_test_err \ + write_and_run_sub_test_lib_test_err \ t1234-verbose "test verbose" --verbose <<-\EOF && test_expect_success "passing test" true test_expect_success "test with output" "echo foo" @@ -231,7 +231,7 @@ test_expect_success 'test --verbose' ' ' test_expect_success 'test --verbose-only' ' - run_sub_test_lib_test_err \ + write_and_run_sub_test_lib_test_err \ t2345-verbose-only-2 "test verbose-only=2" \ --verbose-only=2 <<-\EOF && test_expect_success "passing test" true @@ -255,7 +255,7 @@ test_expect_success 'test --verbose-only' ' test_expect_success 'GIT_SKIP_TESTS' ' ( - run_sub_test_lib_test git-skip-tests-basic \ + write_and_run_sub_test_lib_test git-skip-tests-basic \ "GIT_SKIP_TESTS" \ --skip="git.2" <<-\EOF && for i in 1 2 3 @@ -276,7 +276,7 @@ test_expect_success 'GIT_SKIP_TESTS' ' test_expect_success 'GIT_SKIP_TESTS several tests' ' ( - run_sub_test_lib_test git-skip-tests-several \ + write_and_run_sub_test_lib_test git-skip-tests-several \ "GIT_SKIP_TESTS several tests" \ --skip="git.2 git.5" <<-\EOF && for i in 1 2 3 4 5 6 @@ -300,7 +300,7 @@ test_expect_success 'GIT_SKIP_TESTS several tests' ' test_expect_success 'GIT_SKIP_TESTS sh pattern' ' ( - run_sub_test_lib_test git-skip-tests-sh-pattern \ + write_and_run_sub_test_lib_test git-skip-tests-sh-pattern \ "GIT_SKIP_TESTS sh pattern" \ --skip="git.[2-5]" <<-\EOF && for i in 1 2 3 4 5 6 @@ -324,7 +324,7 @@ test_expect_success 'GIT_SKIP_TESTS sh pattern' ' test_expect_success 'GIT_SKIP_TESTS entire suite' ' ( - run_sub_test_lib_test git-skip-tests-entire-suite \ + write_and_run_sub_test_lib_test git-skip-tests-entire-suite \ "GIT_SKIP_TESTS entire suite" \ --skip="git" <<-\EOF && for i in 1 2 3 @@ -341,7 +341,7 @@ test_expect_success 'GIT_SKIP_TESTS entire suite' ' test_expect_success 'GIT_SKIP_TESTS does not skip unmatched suite' ' ( - run_sub_test_lib_test git-skip-tests-unmatched-suite \ + write_and_run_sub_test_lib_test git-skip-tests-unmatched-suite \ "GIT_SKIP_TESTS does not skip unmatched suite" \ --skip="notgit" <<-\EOF && for i in 1 2 3 @@ -361,7 +361,7 @@ test_expect_success 'GIT_SKIP_TESTS does not skip unmatched suite' ' ' test_expect_success '--run basic' ' - run_sub_test_lib_test run-basic \ + write_and_run_sub_test_lib_test run-basic \ "--run basic" --run="1,3,5" <<-\EOF && for i in 1 2 3 4 5 6 do @@ -382,7 +382,7 @@ test_expect_success '--run basic' ' ' test_expect_success '--run with a range' ' - run_sub_test_lib_test run-range \ + write_and_run_sub_test_lib_test run-range \ "--run with a range" --run="1-3" <<-\EOF && for i in 1 2 3 4 5 6 do @@ -403,7 +403,7 @@ test_expect_success '--run with a range' ' ' test_expect_success '--run with two ranges' ' - run_sub_test_lib_test run-two-ranges \ + write_and_run_sub_test_lib_test run-two-ranges \ "--run with two ranges" --run="1-2,5-6" <<-\EOF && for i in 1 2 3 4 5 6 do @@ -424,7 +424,7 @@ test_expect_success '--run with two ranges' ' ' test_expect_success '--run with a left open range' ' - run_sub_test_lib_test run-left-open-range \ + write_and_run_sub_test_lib_test run-left-open-range \ "--run with a left open range" --run="-3" <<-\EOF && for i in 1 2 3 4 5 6 do @@ -445,7 +445,7 @@ test_expect_success '--run with a left open range' ' ' test_expect_success '--run with a right open range' ' - run_sub_test_lib_test run-right-open-range \ + write_and_run_sub_test_lib_test run-right-open-range \ "--run with a right open range" --run="4-" <<-\EOF && for i in 1 2 3 4 5 6 do @@ -466,7 +466,7 @@ test_expect_success '--run with a right open range' ' ' test_expect_success '--run with basic negation' ' - run_sub_test_lib_test run-basic-neg \ + write_and_run_sub_test_lib_test run-basic-neg \ "--run with basic negation" --run="!3" <<-\EOF && for i in 1 2 3 4 5 6 do @@ -487,7 +487,7 @@ test_expect_success '--run with basic negation' ' ' test_expect_success '--run with two negations' ' - run_sub_test_lib_test run-two-neg \ + write_and_run_sub_test_lib_test run-two-neg \ "--run with two negations" --run="!3,!6" <<-\EOF && for i in 1 2 3 4 5 6 do @@ -508,7 +508,7 @@ test_expect_success '--run with two negations' ' ' test_expect_success '--run a range and negation' ' - run_sub_test_lib_test run-range-and-neg \ + write_and_run_sub_test_lib_test run-range-and-neg \ "--run a range and negation" --run="-4,!2" <<-\EOF && for i in 1 2 3 4 5 6 do @@ -529,7 +529,7 @@ test_expect_success '--run a range and negation' ' ' test_expect_success '--run range negation' ' - run_sub_test_lib_test run-range-neg \ + write_and_run_sub_test_lib_test run-range-neg \ "--run range negation" --run="!1-3" <<-\EOF && for i in 1 2 3 4 5 6 do @@ -550,7 +550,7 @@ test_expect_success '--run range negation' ' ' test_expect_success '--run include, exclude and include' ' - run_sub_test_lib_test run-inc-neg-inc \ + write_and_run_sub_test_lib_test run-inc-neg-inc \ "--run include, exclude and include" \ --run="1-5,!1-3,2" <<-\EOF && for i in 1 2 3 4 5 6 @@ -572,7 +572,7 @@ test_expect_success '--run include, exclude and include' ' ' test_expect_success '--run include, exclude and include, comma separated' ' - run_sub_test_lib_test run-inc-neg-inc-comma \ + write_and_run_sub_test_lib_test run-inc-neg-inc-comma \ "--run include, exclude and include, comma separated" \ --run=1-5,!1-3,2 <<-\EOF && for i in 1 2 3 4 5 6 @@ -594,7 +594,7 @@ test_expect_success '--run include, exclude and include, comma separated' ' ' test_expect_success '--run exclude and include' ' - run_sub_test_lib_test run-neg-inc \ + write_and_run_sub_test_lib_test run-neg-inc \ "--run exclude and include" \ --run="!3-,5" <<-\EOF && for i in 1 2 3 4 5 6 @@ -616,7 +616,7 @@ test_expect_success '--run exclude and include' ' ' test_expect_success '--run empty selectors' ' - run_sub_test_lib_test run-empty-sel \ + write_and_run_sub_test_lib_test run-empty-sel \ "--run empty selectors" \ --run="1,,3,,,5" <<-\EOF && for i in 1 2 3 4 5 6 @@ -638,7 +638,7 @@ test_expect_success '--run empty selectors' ' ' test_expect_success '--run substring selector' ' - run_sub_test_lib_test run-substring-selector \ + write_and_run_sub_test_lib_test run-substring-selector \ "--run empty selectors" \ --run="relevant" <<-\EOF && test_expect_success "relevant test" "true" @@ -662,7 +662,7 @@ test_expect_success '--run substring selector' ' ' test_expect_success '--run keyword selection' ' - run_sub_test_lib_test_err run-inv-range-start \ + write_and_run_sub_test_lib_test_err run-inv-range-start \ "--run invalid range start" \ --run="a-5" <<-\EOF && test_expect_success "passing test #1" "true" @@ -677,7 +677,7 @@ test_expect_success '--run keyword selection' ' ' test_expect_success '--run invalid range end' ' - run_sub_test_lib_test_err run-inv-range-end \ + write_and_run_sub_test_lib_test_err run-inv-range-end \ "--run invalid range end" \ --run="1-z" <<-\EOF && test_expect_success "passing test #1" "true" @@ -692,7 +692,7 @@ test_expect_success '--run invalid range end' ' ' test_expect_success 'tests respect prerequisites' ' - run_sub_test_lib_test prereqs "tests respect prereqs" <<-\EOF && + write_and_run_sub_test_lib_test prereqs "tests respect prereqs" <<-\EOF && test_set_prereq HAVEIT test_expect_success HAVEIT "prereq is satisfied" "true" @@ -722,7 +722,7 @@ test_expect_success 'tests respect prerequisites' ' ' test_expect_success 'tests respect lazy prerequisites' ' - run_sub_test_lib_test lazy-prereqs "respect lazy prereqs" <<-\EOF && + write_and_run_sub_test_lib_test lazy-prereqs "respect lazy prereqs" <<-\EOF && test_lazy_prereq LAZY_TRUE true test_expect_success LAZY_TRUE "lazy prereq is satisifed" "true" @@ -746,7 +746,7 @@ test_expect_success 'tests respect lazy prerequisites' ' ' test_expect_success 'nested lazy prerequisites' ' - run_sub_test_lib_test nested-lazy "nested lazy prereqs" <<-\EOF && + write_and_run_sub_test_lib_test nested-lazy "nested lazy prereqs" <<-\EOF && test_lazy_prereq NESTED_INNER " >inner && @@ -772,7 +772,7 @@ test_expect_success 'nested lazy prerequisites' ' ' test_expect_success 'lazy prereqs do not turn off tracing' ' - run_sub_test_lib_test lazy-prereq-and-tracing \ + write_and_run_sub_test_lib_test lazy-prereq-and-tracing \ "lazy prereqs and -x" -v -x <<-\EOF && test_lazy_prereq LAZY true @@ -785,7 +785,7 @@ test_expect_success 'lazy prereqs do not turn off tracing' ' ' test_expect_success 'tests clean up after themselves' ' - run_sub_test_lib_test cleanup "test with cleanup" <<-\EOF && + write_and_run_sub_test_lib_test cleanup "test with cleanup" <<-\EOF && clean=no test_expect_success "do cleanup" " test_when_finished clean=yes @@ -805,7 +805,7 @@ test_expect_success 'tests clean up after themselves' ' ' test_expect_success 'tests clean up even on failures' ' - run_sub_test_lib_test_err \ + write_and_run_sub_test_lib_test_err \ failing-cleanup "Failing tests with cleanup commands" <<-\EOF && test_expect_success "tests clean up even after a failure" " touch clean-after-failure && @@ -834,7 +834,7 @@ test_expect_success 'tests clean up even on failures' ' ' test_expect_success 'test_atexit is run' ' - run_sub_test_lib_test_err \ + write_and_run_sub_test_lib_test_err \ atexit-cleanup "Run atexit commands" -i <<-\EOF && test_expect_success "tests clean up even after a failure" " > ../../clean-atexit && From patchwork Wed Jul 21 22:57:42 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: 12392433 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 03AECC6377B for ; Wed, 21 Jul 2021 22:58:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E735761261 for ; Wed, 21 Jul 2021 22:58:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230413AbhGUWR6 (ORCPT ); Wed, 21 Jul 2021 18:17:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60570 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230402AbhGUWRx (ORCPT ); Wed, 21 Jul 2021 18:17:53 -0400 Received: from mail-wm1-x334.google.com (mail-wm1-x334.google.com [IPv6:2a00:1450:4864:20::334]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 95C03C061575 for ; Wed, 21 Jul 2021 15:58:28 -0700 (PDT) Received: by mail-wm1-x334.google.com with SMTP id g12so2235641wme.2 for ; Wed, 21 Jul 2021 15:58:28 -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=cEf1xRD2P0TRa0UR6b4B94ry55kqqrQ6cD9UNsUfTBE=; b=lvR5OHp1SFzcjvJBkYW1EI71oU2h6yunrmE89kOIeZJPktjGv+hBjtcBqpyBb7SA9Z slX1nwsNWt3Keze0UMWhrN0W46ftdxioL7ZNpA+mw+9JcOnicw9Rc2Ku/SarpFKii7UP lNHJHYrJsLVW9Ia0FXb68Nb4naEDcYUgJx7ASlEkIJlYhks/NGKnJvza20oQbgrqphv9 pn8waSmqmmadL2SJ48wuDFipvRHq9FN8Gw9ba9LvOA/NuZBIx+dUKqTWbszDN0AOP943 aBdX5abzT7wMXoIYmKdEs0pE03eJs7aI/4oI9o5w+CbtyAsJpwKX1D6kZMvURfTjpAtf isJA== 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=cEf1xRD2P0TRa0UR6b4B94ry55kqqrQ6cD9UNsUfTBE=; b=ccrqPmGuzSHvucf4l8ZrVRyxCiiuYxreC4HsoQsYYTo5GbDNTn+O9gSmtaGF1A9LK9 xq4nE9vuMjfELxIXHX37qxWMLy9ARuTrnJutvQgXD5TuhG9mQ8z1fVYur+6p1QfJptLq ZsHk0C/PPoHY4k0PT0yUFm2wG9Ko/pE1iIHH6dkNx1ToBlOxBiY71exX8eEot+K9fzY0 KQzHR2snf/pMVmIRXfqUIRA1cdCnpnmfnGWu9uHxtkryYhPKXESk2ZkUX9tm8Rn/voBe N5vaNVLXkS10+BP1Re5n+3U7vaGCEkMW0hBwk4o5JslH460DNUcZ0OFbNldGg6XdaUs5 CD7Q== X-Gm-Message-State: AOAM532aEmhgut8ZVmCWJwnz7+aGfO+49RdJEpre2Z3o2WVCdIvhhk+6 Tx+fX2pGxtE1pdmZv7QHkGXozdbt42w0hg== X-Google-Smtp-Source: ABdhPJxj01fxtsl14kX62ryEqgPWfV/vA2K7B2dFtd8XrOwGYXox6QOjapUrAR7JSABXK3D0ypO+Cw== X-Received: by 2002:a05:600c:3581:: with SMTP id p1mr6303430wmq.150.1626908307006; Wed, 21 Jul 2021 15:58:27 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id g18sm23129818wmk.37.2021.07.21.15.58.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Jul 2021 15:58:26 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Jeff King , Felipe Contreras , Adam Spiers , Thomas Rast , Ilya Bobyr , Patrick Steinhardt , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v2 3/8] test-lib tests: stop using a subshell in write_sub_test_lib_test() Date: Thu, 22 Jul 2021 00:57:42 +0200 Message-Id: X-Mailer: git-send-email 2.32.0.955.ge7c5360f7e7 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Now that this function doesn't handle running the test anymore we can do away with the sub-shell, which was used to scope an "unset" and "export" shell variables. Signed-off-by: Ævar Arnfjörð Bjarmason --- t/lib-subtest.sh | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/t/lib-subtest.sh b/t/lib-subtest.sh index 8f3f6dddcf4..727b0850e9b 100644 --- a/t/lib-subtest.sh +++ b/t/lib-subtest.sh @@ -1,20 +1,17 @@ write_sub_test_lib_test () { name="$1" descr="$2" # stdin is the body of the test code mkdir "$name" && - ( - cd "$name" && - write_script "$name.sh" "$TEST_SHELL_PATH" <<-EOF && - test_description='$descr (run in sub test-lib) + write_script "$name/$name.sh" "$TEST_SHELL_PATH" <<-EOF && + test_description='$descr (run in sub test-lib) - This is run in a sub test-lib so that we do not get incorrect - passing metrics - ' + This is run in a sub test-lib so that we do not get incorrect + passing metrics + ' - # Point to the t/test-lib.sh, which isn't in ../ as usual - . "\$TEST_DIRECTORY"/test-lib.sh - EOF - cat >>"$name.sh" - ) + # Point to the t/test-lib.sh, which isn't in ../ as usual + . "\$TEST_DIRECTORY"/test-lib.sh + EOF + cat >>"$name/$name.sh" } _run_sub_test_lib_test_common () { From patchwork Wed Jul 21 22:57: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: 12392431 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 C1B01C6377C for ; Wed, 21 Jul 2021 22:58:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A83D76124C for ; Wed, 21 Jul 2021 22:58:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230407AbhGUWR5 (ORCPT ); Wed, 21 Jul 2021 18:17:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60582 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230404AbhGUWRx (ORCPT ); Wed, 21 Jul 2021 18:17:53 -0400 Received: from mail-wm1-x331.google.com (mail-wm1-x331.google.com [IPv6:2a00:1450:4864:20::331]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 55290C0613D3 for ; Wed, 21 Jul 2021 15:58:29 -0700 (PDT) Received: by mail-wm1-x331.google.com with SMTP id k14-20020a05600c1c8eb02901f13dd1672aso1591842wms.0 for ; Wed, 21 Jul 2021 15:58:29 -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=7YEFu7o/YHKr3Fjh7v2GlewdMbUWQ/L4fKkHCMZ3r5M=; b=A6gk1BFlBvMdu02bAoKt1NJ/ybUYSSvWleh/zI6nmRgQt/a6JGujJ/DQxXkc7DaQQS 4avrYC46hmvqxXhWt05iP8IRg6TEASwTq5TW0qf4wkVwOpVUdrC7je4QG5LsOFTQEINP n1cX/PMq8Of2OvoIz/CXnZj61q4ChUXyKMPddvPM1pc+k2toNWRQGzdfnEkG2B2mjruM cqbupwU1g2/BveUES4boiuscTGaagq750bNWRsGQQTDHFri1mZE3r+Q9qCq84hIF0dyQ Xv6FwcL1I9L3A2/XlMJP34sp/9ubHJgE/t6tGAUEofU21UbI6tqLe3KXpzVfVPF49rwJ 0s4Q== 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=7YEFu7o/YHKr3Fjh7v2GlewdMbUWQ/L4fKkHCMZ3r5M=; b=tJ0LACPIpQk4jW9LwecxUsezLe2rlSNNzBIZrhdqr32S8bomewsN7HJHSFYwx9s0Gk PpfhPHGiVJhTJwJgBo/AWPAERNOTjAIiGkvU2P8u7vUIwOiHQxFg/Q8l1OVIOQw2GNvX oVxg3XjdLlAAIA3vhsDJf8yUkS/wim6YO1i30GpktJq5Bh5/zvw80HnqUc7E2I3v1dVn W3ptGLplk+tpDXbVswc8xATc41iSIQjvIQpejzOcqVB8olsuNMnz9Etkqxm27IIMrNgE d17kJ+Dsis4JCVXW5iD+kFzcb3Y5hTC1ZGCcY+iLuCd4yhq4nC49yj8ZbTJUfpYzIf1Y S9Qw== X-Gm-Message-State: AOAM532EzoADmwxb/j2zWX4HCYPrbLQvYMZhyg81TxwQjU5za+5I+Qd/ NBLNypK4VL6Zwa+50BGfBFkFf4F/s8idfQ== X-Google-Smtp-Source: ABdhPJz6vjt260vYKwKTHe86rd12EzBSpR5TjchnQJCa04cjuxi1GBB0FX6/R4Es6xhBBMwD1mUhCg== X-Received: by 2002:a05:600c:21c8:: with SMTP id x8mr5989089wmj.173.1626908307703; Wed, 21 Jul 2021 15:58:27 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id g18sm23129818wmk.37.2021.07.21.15.58.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Jul 2021 15:58:27 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Jeff King , Felipe Contreras , Adam Spiers , Thomas Rast , Ilya Bobyr , Patrick Steinhardt , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v2 4/8] test-lib tests: don't provide a description for the sub-tests Date: Thu, 22 Jul 2021 00:57:43 +0200 Message-Id: X-Mailer: git-send-email 2.32.0.955.ge7c5360f7e7 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Change the $test_description provided for the generated subtests to be constant, since the only purpose of having it is that test-lib.sh will barf if it isn't supplied. The other purpose of having it was to effectively split up the test description between the argument to test_expect_success and the argument to "write_and_run_sub_test_lib_test". Let's only use one of the two. Signed-off-by: Ævar Arnfjörð Bjarmason --- t/lib-subtest.sh | 12 ++-- t/t0000-basic.sh | 142 +++++++++++++++++++++-------------------------- 2 files changed, 66 insertions(+), 88 deletions(-) diff --git a/t/lib-subtest.sh b/t/lib-subtest.sh index 727b0850e9b..7899518abb0 100644 --- a/t/lib-subtest.sh +++ b/t/lib-subtest.sh @@ -1,12 +1,8 @@ write_sub_test_lib_test () { - name="$1" descr="$2" # stdin is the body of the test code + name="$1" # stdin is the body of the test code mkdir "$name" && write_script "$name/$name.sh" "$TEST_SHELL_PATH" <<-EOF && - test_description='$descr (run in sub test-lib) - - This is run in a sub test-lib so that we do not get incorrect - passing metrics - ' + test_description='A test of test-lib.sh itself' # Point to the t/test-lib.sh, which isn't in ../ as usual . "\$TEST_DIRECTORY"/test-lib.sh @@ -15,8 +11,8 @@ write_sub_test_lib_test () { } _run_sub_test_lib_test_common () { - neg="$1" name="$2" descr="$3" # stdin is the body of the test code - shift 3 + neg="$1" name="$2" # stdin is the body of the test code + shift 2 # intercept pseudo-options at the front of the argument list that we # will not pass to child script diff --git a/t/t0000-basic.sh b/t/t0000-basic.sh index a7c5aaacab6..6fdd5f43cae 100755 --- a/t/t0000-basic.sh +++ b/t/t0000-basic.sh @@ -67,8 +67,8 @@ test_expect_success 'success is reported like this' ' : ' -test_expect_success 'pretend we have a fully passing test suite' ' - write_and_run_sub_test_lib_test full-pass "3 passing tests" <<-\EOF && +test_expect_success 'subtest: 3 passing tests' ' + write_and_run_sub_test_lib_test full-pass <<-\EOF && for i in 1 2 3 do test_expect_success "passing test #$i" "true" @@ -84,9 +84,8 @@ test_expect_success 'pretend we have a fully passing test suite' ' EOF ' -test_expect_success 'pretend we have a partially passing test suite' ' - write_and_run_sub_test_lib_test_err \ - partial-pass "2/3 tests passing" <<-\EOF && +test_expect_success 'subtest: 2/3 tests passing' ' + write_and_run_sub_test_lib_test_err partial-pass <<-\EOF && test_expect_success "passing test #1" "true" test_expect_success "failing test #2" "false" test_expect_success "passing test #3" "true" @@ -102,8 +101,8 @@ test_expect_success 'pretend we have a partially passing test suite' ' EOF ' -test_expect_success 'pretend we have a known breakage' ' - write_and_run_sub_test_lib_test failing-todo "A failing TODO test" <<-\EOF && +test_expect_success 'subtest: a failing TODO test' ' + write_and_run_sub_test_lib_test failing-todo <<-\EOF && test_expect_success "passing test" "true" test_expect_failure "pretend we have a known breakage" "false" test_done @@ -117,8 +116,8 @@ test_expect_success 'pretend we have a known breakage' ' EOF ' -test_expect_success 'pretend we have fixed a known breakage' ' - write_and_run_sub_test_lib_test passing-todo "A passing TODO test" <<-\EOF && +test_expect_success 'subtest: a passing TODO test' ' + write_and_run_sub_test_lib_test passing-todo <<-\EOF && test_expect_failure "pretend we have fixed a known breakage" "true" test_done EOF @@ -129,9 +128,8 @@ test_expect_success 'pretend we have fixed a known breakage' ' EOF ' -test_expect_success 'pretend we have fixed one of two known breakages (run in sub test-lib)' ' - write_and_run_sub_test_lib_test partially-passing-todos \ - "2 TODO tests, one passing" <<-\EOF && +test_expect_success 'subtest: 2 TODO tests, one passin' ' + write_and_run_sub_test_lib_test partially-passing-todos <<-\EOF && test_expect_failure "pretend we have a known breakage" "false" test_expect_success "pretend we have a passing test" "true" test_expect_failure "pretend we have fixed another known breakage" "true" @@ -148,9 +146,8 @@ test_expect_success 'pretend we have fixed one of two known breakages (run in su EOF ' -test_expect_success 'pretend we have a pass, fail, and known breakage' ' - write_and_run_sub_test_lib_test_err \ - mixed-results1 "mixed results #1" <<-\EOF && +test_expect_success 'subtest: mixed results: pass, failure and a TODO test' ' + write_and_run_sub_test_lib_test_err mixed-results1 <<-\EOF && test_expect_success "passing test" "true" test_expect_success "failing test" "false" test_expect_failure "pretend we have a known breakage" "false" @@ -167,9 +164,8 @@ test_expect_success 'pretend we have a pass, fail, and known breakage' ' EOF ' -test_expect_success 'pretend we have a mix of all possible results' ' - write_and_run_sub_test_lib_test_err \ - mixed-results2 "mixed results #2" <<-\EOF && +test_expect_success 'subtest: mixed results: a mixture of all possible results' ' + write_and_run_sub_test_lib_test_err mixed-results2 <<-\EOF && test_expect_success "passing test" "true" test_expect_success "passing test" "true" test_expect_success "passing test" "true" @@ -203,9 +199,8 @@ test_expect_success 'pretend we have a mix of all possible results' ' EOF ' -test_expect_success 'test --verbose' ' - write_and_run_sub_test_lib_test_err \ - t1234-verbose "test verbose" --verbose <<-\EOF && +test_expect_success 'subtest: --verbose option' ' + write_and_run_sub_test_lib_test_err t1234-verbose --verbose <<-\EOF && test_expect_success "passing test" true test_expect_success "test with output" "echo foo" test_expect_success "failing test" false @@ -230,9 +225,9 @@ test_expect_success 'test --verbose' ' EOF ' -test_expect_success 'test --verbose-only' ' +test_expect_success 'subtest: --verbose-only option' ' write_and_run_sub_test_lib_test_err \ - t2345-verbose-only-2 "test verbose-only=2" \ + t2345-verbose-only-2 \ --verbose-only=2 <<-\EOF && test_expect_success "passing test" true test_expect_success "test with output" "echo foo" @@ -253,10 +248,9 @@ test_expect_success 'test --verbose-only' ' EOF ' -test_expect_success 'GIT_SKIP_TESTS' ' +test_expect_success 'subtest: skip one with GIT_SKIP_TESTS' ' ( write_and_run_sub_test_lib_test git-skip-tests-basic \ - "GIT_SKIP_TESTS" \ --skip="git.2" <<-\EOF && for i in 1 2 3 do @@ -274,10 +268,9 @@ test_expect_success 'GIT_SKIP_TESTS' ' ) ' -test_expect_success 'GIT_SKIP_TESTS several tests' ' +test_expect_success 'subtest: skip several with GIT_SKIP_TESTS' ' ( write_and_run_sub_test_lib_test git-skip-tests-several \ - "GIT_SKIP_TESTS several tests" \ --skip="git.2 git.5" <<-\EOF && for i in 1 2 3 4 5 6 do @@ -298,10 +291,9 @@ test_expect_success 'GIT_SKIP_TESTS several tests' ' ) ' -test_expect_success 'GIT_SKIP_TESTS sh pattern' ' +test_expect_success 'subtest: sh pattern skipping with GIT_SKIP_TESTS' ' ( write_and_run_sub_test_lib_test git-skip-tests-sh-pattern \ - "GIT_SKIP_TESTS sh pattern" \ --skip="git.[2-5]" <<-\EOF && for i in 1 2 3 4 5 6 do @@ -322,10 +314,9 @@ test_expect_success 'GIT_SKIP_TESTS sh pattern' ' ) ' -test_expect_success 'GIT_SKIP_TESTS entire suite' ' +test_expect_success 'subtest: skip entire test suite with GIT_SKIP_TESTS' ' ( write_and_run_sub_test_lib_test git-skip-tests-entire-suite \ - "GIT_SKIP_TESTS entire suite" \ --skip="git" <<-\EOF && for i in 1 2 3 do @@ -339,10 +330,9 @@ test_expect_success 'GIT_SKIP_TESTS entire suite' ' ) ' -test_expect_success 'GIT_SKIP_TESTS does not skip unmatched suite' ' +test_expect_success 'subtest: GIT_SKIP_TESTS does not skip unmatched suite' ' ( write_and_run_sub_test_lib_test git-skip-tests-unmatched-suite \ - "GIT_SKIP_TESTS does not skip unmatched suite" \ --skip="notgit" <<-\EOF && for i in 1 2 3 do @@ -360,9 +350,8 @@ test_expect_success 'GIT_SKIP_TESTS does not skip unmatched suite' ' ) ' -test_expect_success '--run basic' ' - write_and_run_sub_test_lib_test run-basic \ - "--run basic" --run="1,3,5" <<-\EOF && +test_expect_success 'subtest: --run basic' ' + write_and_run_sub_test_lib_test run-basic --run="1,3,5" <<-\EOF && for i in 1 2 3 4 5 6 do test_expect_success "passing test #$i" "true" @@ -381,9 +370,9 @@ test_expect_success '--run basic' ' EOF ' -test_expect_success '--run with a range' ' +test_expect_success 'subtest: --run with a range' ' write_and_run_sub_test_lib_test run-range \ - "--run with a range" --run="1-3" <<-\EOF && + --run="1-3" <<-\EOF && for i in 1 2 3 4 5 6 do test_expect_success "passing test #$i" "true" @@ -402,9 +391,9 @@ test_expect_success '--run with a range' ' EOF ' -test_expect_success '--run with two ranges' ' +test_expect_success 'subtest: --run with two ranges' ' write_and_run_sub_test_lib_test run-two-ranges \ - "--run with two ranges" --run="1-2,5-6" <<-\EOF && + --run="1-2,5-6" <<-\EOF && for i in 1 2 3 4 5 6 do test_expect_success "passing test #$i" "true" @@ -423,9 +412,9 @@ test_expect_success '--run with two ranges' ' EOF ' -test_expect_success '--run with a left open range' ' +test_expect_success 'subtest: --run with a left open range' ' write_and_run_sub_test_lib_test run-left-open-range \ - "--run with a left open range" --run="-3" <<-\EOF && + --run="-3" <<-\EOF && for i in 1 2 3 4 5 6 do test_expect_success "passing test #$i" "true" @@ -444,9 +433,9 @@ test_expect_success '--run with a left open range' ' EOF ' -test_expect_success '--run with a right open range' ' +test_expect_success 'subtest: --run with a right open range' ' write_and_run_sub_test_lib_test run-right-open-range \ - "--run with a right open range" --run="4-" <<-\EOF && + --run="4-" <<-\EOF && for i in 1 2 3 4 5 6 do test_expect_success "passing test #$i" "true" @@ -465,9 +454,9 @@ test_expect_success '--run with a right open range' ' EOF ' -test_expect_success '--run with basic negation' ' +test_expect_success 'subtest: --run with basic negation' ' write_and_run_sub_test_lib_test run-basic-neg \ - "--run with basic negation" --run="!3" <<-\EOF && + --run="!3" <<-\EOF && for i in 1 2 3 4 5 6 do test_expect_success "passing test #$i" "true" @@ -486,9 +475,9 @@ test_expect_success '--run with basic negation' ' EOF ' -test_expect_success '--run with two negations' ' +test_expect_success 'subtest: --run with two negations' ' write_and_run_sub_test_lib_test run-two-neg \ - "--run with two negations" --run="!3,!6" <<-\EOF && + --run="!3,!6" <<-\EOF && for i in 1 2 3 4 5 6 do test_expect_success "passing test #$i" "true" @@ -507,9 +496,9 @@ test_expect_success '--run with two negations' ' EOF ' -test_expect_success '--run a range and negation' ' +test_expect_success 'subtest: --run a range and negation' ' write_and_run_sub_test_lib_test run-range-and-neg \ - "--run a range and negation" --run="-4,!2" <<-\EOF && + --run="-4,!2" <<-\EOF && for i in 1 2 3 4 5 6 do test_expect_success "passing test #$i" "true" @@ -528,9 +517,9 @@ test_expect_success '--run a range and negation' ' EOF ' -test_expect_success '--run range negation' ' +test_expect_success 'subtest: --run range negation' ' write_and_run_sub_test_lib_test run-range-neg \ - "--run range negation" --run="!1-3" <<-\EOF && + --run="!1-3" <<-\EOF && for i in 1 2 3 4 5 6 do test_expect_success "passing test #$i" "true" @@ -549,9 +538,8 @@ test_expect_success '--run range negation' ' EOF ' -test_expect_success '--run include, exclude and include' ' +test_expect_success 'subtest: --run include, exclude and include' ' write_and_run_sub_test_lib_test run-inc-neg-inc \ - "--run include, exclude and include" \ --run="1-5,!1-3,2" <<-\EOF && for i in 1 2 3 4 5 6 do @@ -571,9 +559,8 @@ test_expect_success '--run include, exclude and include' ' EOF ' -test_expect_success '--run include, exclude and include, comma separated' ' +test_expect_success 'subtest: --run include, exclude and include, comma separated' ' write_and_run_sub_test_lib_test run-inc-neg-inc-comma \ - "--run include, exclude and include, comma separated" \ --run=1-5,!1-3,2 <<-\EOF && for i in 1 2 3 4 5 6 do @@ -593,9 +580,8 @@ test_expect_success '--run include, exclude and include, comma separated' ' EOF ' -test_expect_success '--run exclude and include' ' +test_expect_success 'subtest: --run exclude and include' ' write_and_run_sub_test_lib_test run-neg-inc \ - "--run exclude and include" \ --run="!3-,5" <<-\EOF && for i in 1 2 3 4 5 6 do @@ -615,9 +601,8 @@ test_expect_success '--run exclude and include' ' EOF ' -test_expect_success '--run empty selectors' ' +test_expect_success 'subtest: --run empty selectors' ' write_and_run_sub_test_lib_test run-empty-sel \ - "--run empty selectors" \ --run="1,,3,,,5" <<-\EOF && for i in 1 2 3 4 5 6 do @@ -637,9 +622,8 @@ test_expect_success '--run empty selectors' ' EOF ' -test_expect_success '--run substring selector' ' +test_expect_success 'subtest: --run substring selector' ' write_and_run_sub_test_lib_test run-substring-selector \ - "--run empty selectors" \ --run="relevant" <<-\EOF && test_expect_success "relevant test" "true" for i in 1 2 3 4 5 6 @@ -661,9 +645,8 @@ test_expect_success '--run substring selector' ' EOF ' -test_expect_success '--run keyword selection' ' +test_expect_success 'subtest: --run keyword selection' ' write_and_run_sub_test_lib_test_err run-inv-range-start \ - "--run invalid range start" \ --run="a-5" <<-\EOF && test_expect_success "passing test #1" "true" test_done @@ -676,9 +659,8 @@ test_expect_success '--run keyword selection' ' EOF_ERR ' -test_expect_success '--run invalid range end' ' +test_expect_success 'subtest: --run invalid range end' ' write_and_run_sub_test_lib_test_err run-inv-range-end \ - "--run invalid range end" \ --run="1-z" <<-\EOF && test_expect_success "passing test #1" "true" test_done @@ -691,8 +673,8 @@ test_expect_success '--run invalid range end' ' EOF_ERR ' -test_expect_success 'tests respect prerequisites' ' - write_and_run_sub_test_lib_test prereqs "tests respect prereqs" <<-\EOF && +test_expect_success 'subtest: tests respect prerequisites' ' + write_and_run_sub_test_lib_test prereqs <<-\EOF && test_set_prereq HAVEIT test_expect_success HAVEIT "prereq is satisfied" "true" @@ -721,8 +703,8 @@ test_expect_success 'tests respect prerequisites' ' EOF ' -test_expect_success 'tests respect lazy prerequisites' ' - write_and_run_sub_test_lib_test lazy-prereqs "respect lazy prereqs" <<-\EOF && +test_expect_success 'subtest: tests respect lazy prerequisites' ' + write_and_run_sub_test_lib_test lazy-prereqs <<-\EOF && test_lazy_prereq LAZY_TRUE true test_expect_success LAZY_TRUE "lazy prereq is satisifed" "true" @@ -745,8 +727,8 @@ test_expect_success 'tests respect lazy prerequisites' ' EOF ' -test_expect_success 'nested lazy prerequisites' ' - write_and_run_sub_test_lib_test nested-lazy "nested lazy prereqs" <<-\EOF && +test_expect_success 'subtest: nested lazy prerequisites' ' + write_and_run_sub_test_lib_test nested-lazy <<-\EOF && test_lazy_prereq NESTED_INNER " >inner && @@ -771,9 +753,9 @@ test_expect_success 'nested lazy prerequisites' ' EOF ' -test_expect_success 'lazy prereqs do not turn off tracing' ' +test_expect_success 'subtest: lazy prereqs do not turn off tracing' ' write_and_run_sub_test_lib_test lazy-prereq-and-tracing \ - "lazy prereqs and -x" -v -x <<-\EOF && + -v -x <<-\EOF && test_lazy_prereq LAZY true test_expect_success lazy "test_have_prereq LAZY && echo trace" @@ -784,8 +766,8 @@ test_expect_success 'lazy prereqs do not turn off tracing' ' grep "echo trace" lazy-prereq-and-tracing/err ' -test_expect_success 'tests clean up after themselves' ' - write_and_run_sub_test_lib_test cleanup "test with cleanup" <<-\EOF && +test_expect_success 'subtest: tests clean up after themselves' ' + write_and_run_sub_test_lib_test cleanup <<-\EOF && clean=no test_expect_success "do cleanup" " test_when_finished clean=yes @@ -804,9 +786,9 @@ test_expect_success 'tests clean up after themselves' ' EOF ' -test_expect_success 'tests clean up even on failures' ' +test_expect_success 'subtest: tests clean up even on failures' ' write_and_run_sub_test_lib_test_err \ - failing-cleanup "Failing tests with cleanup commands" <<-\EOF && + failing-cleanup <<-\EOF && test_expect_success "tests clean up even after a failure" " touch clean-after-failure && test_when_finished rm clean-after-failure && @@ -833,9 +815,9 @@ test_expect_success 'tests clean up even on failures' ' EOF ' -test_expect_success 'test_atexit is run' ' +test_expect_success 'subtest: test_atexit is run' ' write_and_run_sub_test_lib_test_err \ - atexit-cleanup "Run atexit commands" -i <<-\EOF && + atexit-cleanup -i <<-\EOF && test_expect_success "tests clean up even after a failure" " > ../../clean-atexit && test_atexit rm ../../clean-atexit && From patchwork Wed Jul 21 22:57: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: 12392429 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 5E691C6377A for ; Wed, 21 Jul 2021 22:58:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4700C61249 for ; Wed, 21 Jul 2021 22:58:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230409AbhGUWR4 (ORCPT ); Wed, 21 Jul 2021 18:17:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60588 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230407AbhGUWRy (ORCPT ); Wed, 21 Jul 2021 18:17:54 -0400 Received: from mail-wm1-x336.google.com (mail-wm1-x336.google.com [IPv6:2a00:1450:4864:20::336]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1A7BEC0613D5 for ; Wed, 21 Jul 2021 15:58:30 -0700 (PDT) Received: by mail-wm1-x336.google.com with SMTP id w13so2228469wmc.3 for ; Wed, 21 Jul 2021 15:58:30 -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=+KpR4DiYOQ8aH6/kIri6SWokPd9pTbyWMmnU2CkHSz8=; b=YfoWHPGqmpxJsQDoNXhD4SHpHFLP7HNvNmHL7XEWyiP0CgKGrIEfdqiVqlnJ23LIio AL5g9RW+GbyIbGvC6b44/UL/12gdQlZbYxeehZG+fi4MLAJFKlLsfj9MgC2tYIZb6flS iVYPL4uBtDIAAq5lkgqI5CBv8clHhYGY6hfkp/Z1FXg50Dk7mWmv5SA/an5NozqCimvz uzCXGk6qtBvRLZtU3N2cHRvjYy7TL9r6kWgygmuKVwjhw6Tyfl8NtCDwOIeHlWnE1E69 6u/UzBgx8X5e6CFNVUwvmVQsj/sBEY+HaI1o6tMM9IK5etWps7nhHTWiNiu3bcZgT7t1 rYyA== 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=+KpR4DiYOQ8aH6/kIri6SWokPd9pTbyWMmnU2CkHSz8=; b=feIQLd/5BhnAu6hXBRszkpMCiQIHDI5JW+E8rx9upSBdQMKllqATiMEU4duVIco7dJ F5qQyypKZjDjwgfG5u4DMZIb1bKhY/8WZ4+jkblpgon+28uDepZYQPSB6Fg1+pY4kR3X Va+0ktz7U7LgtgxM77gZOr4KakI3Y5RqlBOweWw5Fz2fPAcM8BKKPl3k3EZpooxVZv/G vYG9J3qNZKtEm6DQhEn0qKhMPo1fgi0TnagmT7EcPbgLRIDWVl61/r+PeJdlJgFwELmr qhdoym7hEfsDgN2YKVl2JSx6u+GkJHMrRmrIBs0LkCUqLzUe3AENxkMMu3F84jRQhPQo hUsg== X-Gm-Message-State: AOAM530th4q887171S7t1L8oC9aLMmqTtlpS2XF9C5XPkxPPoEYT12Hp 9vyGyXbptOkOF2ddQxFTxynG3Dfdrsk26A== X-Google-Smtp-Source: ABdhPJw5gBRCXMdTowQPgwsQ03h6qTgdzI8v4AgUecFiNG3wxU4wnj50oQN+ax3d8VknmN4dBoTPRg== X-Received: by 2002:a05:600c:5106:: with SMTP id o6mr6071551wms.18.1626908308413; Wed, 21 Jul 2021 15:58:28 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id g18sm23129818wmk.37.2021.07.21.15.58.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Jul 2021 15:58:27 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Jeff King , Felipe Contreras , Adam Spiers , Thomas Rast , Ilya Bobyr , Patrick Steinhardt , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v2 5/8] test-lib tests: get rid of copy/pasted mock test code Date: Thu, 22 Jul 2021 00:57:44 +0200 Message-Id: X-Mailer: git-send-email 2.32.0.955.ge7c5360f7e7 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Now that we've split up the write_sub_test_lib_test*() and run_sub_test_lib_test*() functions let's fix those tests in t0000-basic.sh that were verbosely copy/pasting earlier tests. I'm (ab)using writing a tag object under a ref-name that's content-addressable from the content of the test script. If we can update-ref that it's unique, if not we've got a duplicate. The tag object stores the name of the earlier test for reporting the error. Signed-off-by: Ævar Arnfjörð Bjarmason --- t/lib-subtest.sh | 34 ++++++- t/t0000-basic.sh | 228 +++++++++++++---------------------------------- 2 files changed, 93 insertions(+), 169 deletions(-) diff --git a/t/lib-subtest.sh b/t/lib-subtest.sh index 7899518abb0..d98390606b8 100644 --- a/t/lib-subtest.sh +++ b/t/lib-subtest.sh @@ -1,3 +1,34 @@ +_assert_unique_sub_test () { + name=$1 && + + # Alert about the copy/paste programming + hash=$(git hash-object -w "$name") && + cat >tag.sig <<-EOF && + object $hash + type blob + tag $hash + tagger . <> 0 +0000 + + duplicate script detected! + + This test script was already written as: + + $name + + You can just re-use its test code with your own + run_sub_test_lib_test*() + EOF + + tag=$(git mktag /dev/null + then + msg=$(git for-each-ref refs/tags/blob-$hash \ + --format='%(contents)' refs/tags/blob-$hash) + error "on write of $name: $msg" + return 1 + fi +} + write_sub_test_lib_test () { name="$1" # stdin is the body of the test code mkdir "$name" && @@ -7,7 +38,8 @@ write_sub_test_lib_test () { # Point to the t/test-lib.sh, which isn't in ../ as usual . "\$TEST_DIRECTORY"/test-lib.sh EOF - cat >>"$name/$name.sh" + cat >>"$name/$name.sh" && + _assert_unique_sub_test "$name/$name.sh" } _run_sub_test_lib_test_common () { diff --git a/t/t0000-basic.sh b/t/t0000-basic.sh index 6fdd5f43cae..a0b99d83349 100755 --- a/t/t0000-basic.sh +++ b/t/t0000-basic.sh @@ -226,18 +226,13 @@ test_expect_success 'subtest: --verbose option' ' ' test_expect_success 'subtest: --verbose-only option' ' - write_and_run_sub_test_lib_test_err \ - t2345-verbose-only-2 \ - --verbose-only=2 <<-\EOF && - test_expect_success "passing test" true - test_expect_success "test with output" "echo foo" - test_expect_success "failing test" false - test_done - EOF - check_sub_test_lib_test t2345-verbose-only-2 <<-\EOF + run_sub_test_lib_test_err \ + t1234-verbose \ + --verbose-only=2 && + check_sub_test_lib_test t1234-verbose <<-\EOF > ok 1 - passing test > Z - > expecting success of 2345.2 '\''test with output'\'': echo foo + > expecting success of 1234.2 '\''test with output'\'': echo foo > foo > ok 2 - test with output > Z @@ -250,15 +245,9 @@ test_expect_success 'subtest: --verbose-only option' ' test_expect_success 'subtest: skip one with GIT_SKIP_TESTS' ' ( - write_and_run_sub_test_lib_test git-skip-tests-basic \ - --skip="git.2" <<-\EOF && - for i in 1 2 3 - do - test_expect_success "passing test #$i" "true" - done - test_done - EOF - check_sub_test_lib_test git-skip-tests-basic <<-\EOF + run_sub_test_lib_test full-pass \ + --skip="full.2" && + check_sub_test_lib_test full-pass <<-\EOF > ok 1 - passing test #1 > ok 2 # skip passing test #2 (GIT_SKIP_TESTS) > ok 3 - passing test #3 @@ -293,15 +282,9 @@ test_expect_success 'subtest: skip several with GIT_SKIP_TESTS' ' test_expect_success 'subtest: sh pattern skipping with GIT_SKIP_TESTS' ' ( - write_and_run_sub_test_lib_test git-skip-tests-sh-pattern \ - --skip="git.[2-5]" <<-\EOF && - for i in 1 2 3 4 5 6 - do - test_expect_success "passing test #$i" "true" - done - test_done - EOF - check_sub_test_lib_test git-skip-tests-sh-pattern <<-\EOF + run_sub_test_lib_test git-skip-tests-several \ + --skip="git.[2-5]" && + check_sub_test_lib_test git-skip-tests-several <<-\EOF > ok 1 - passing test #1 > ok 2 # skip passing test #2 (GIT_SKIP_TESTS) > ok 3 # skip passing test #3 (GIT_SKIP_TESTS) @@ -316,15 +299,10 @@ test_expect_success 'subtest: sh pattern skipping with GIT_SKIP_TESTS' ' test_expect_success 'subtest: skip entire test suite with GIT_SKIP_TESTS' ' ( - write_and_run_sub_test_lib_test git-skip-tests-entire-suite \ - --skip="git" <<-\EOF && - for i in 1 2 3 - do - test_expect_success "passing test #$i" "true" - done - test_done - EOF - check_sub_test_lib_test git-skip-tests-entire-suite <<-\EOF + GIT_SKIP_TESTS="git" && export GIT_SKIP_TESTS && + run_sub_test_lib_test git-skip-tests-several \ + --skip="git" && + check_sub_test_lib_test git-skip-tests-several <<-\EOF > 1..0 # SKIP skip all tests in git EOF ) @@ -332,15 +310,10 @@ test_expect_success 'subtest: skip entire test suite with GIT_SKIP_TESTS' ' test_expect_success 'subtest: GIT_SKIP_TESTS does not skip unmatched suite' ' ( - write_and_run_sub_test_lib_test git-skip-tests-unmatched-suite \ - --skip="notgit" <<-\EOF && - for i in 1 2 3 - do - test_expect_success "passing test #$i" "true" - done - test_done - EOF - check_sub_test_lib_test git-skip-tests-unmatched-suite <<-\EOF + GIT_SKIP_TESTS="notgit" && export GIT_SKIP_TESTS && + run_sub_test_lib_test full-pass \ + --skip="notfull" && + check_sub_test_lib_test full-pass <<-\EOF > ok 1 - passing test #1 > ok 2 - passing test #2 > ok 3 - passing test #3 @@ -351,14 +324,8 @@ test_expect_success 'subtest: GIT_SKIP_TESTS does not skip unmatched suite' ' ' test_expect_success 'subtest: --run basic' ' - write_and_run_sub_test_lib_test run-basic --run="1,3,5" <<-\EOF && - for i in 1 2 3 4 5 6 - do - test_expect_success "passing test #$i" "true" - done - test_done - EOF - check_sub_test_lib_test run-basic <<-\EOF + run_sub_test_lib_test git-skip-tests-several --run="1,3,5" && + check_sub_test_lib_test git-skip-tests-several <<-\EOF > ok 1 - passing test #1 > ok 2 # skip passing test #2 (--run) > ok 3 - passing test #3 @@ -371,15 +338,9 @@ test_expect_success 'subtest: --run basic' ' ' test_expect_success 'subtest: --run with a range' ' - write_and_run_sub_test_lib_test run-range \ - --run="1-3" <<-\EOF && - for i in 1 2 3 4 5 6 - do - test_expect_success "passing test #$i" "true" - done - test_done - EOF - check_sub_test_lib_test run-range <<-\EOF + run_sub_test_lib_test git-skip-tests-several \ + --run="1-3" && + check_sub_test_lib_test git-skip-tests-several <<-\EOF > ok 1 - passing test #1 > ok 2 - passing test #2 > ok 3 - passing test #3 @@ -392,15 +353,9 @@ test_expect_success 'subtest: --run with a range' ' ' test_expect_success 'subtest: --run with two ranges' ' - write_and_run_sub_test_lib_test run-two-ranges \ - --run="1-2,5-6" <<-\EOF && - for i in 1 2 3 4 5 6 - do - test_expect_success "passing test #$i" "true" - done - test_done - EOF - check_sub_test_lib_test run-two-ranges <<-\EOF + run_sub_test_lib_test git-skip-tests-several \ + --run="1-2,5-6" && + check_sub_test_lib_test git-skip-tests-several <<-\EOF > ok 1 - passing test #1 > ok 2 - passing test #2 > ok 3 # skip passing test #3 (--run) @@ -413,15 +368,9 @@ test_expect_success 'subtest: --run with two ranges' ' ' test_expect_success 'subtest: --run with a left open range' ' - write_and_run_sub_test_lib_test run-left-open-range \ - --run="-3" <<-\EOF && - for i in 1 2 3 4 5 6 - do - test_expect_success "passing test #$i" "true" - done - test_done - EOF - check_sub_test_lib_test run-left-open-range <<-\EOF + run_sub_test_lib_test git-skip-tests-several \ + --run="-3" && + check_sub_test_lib_test git-skip-tests-several <<-\EOF > ok 1 - passing test #1 > ok 2 - passing test #2 > ok 3 - passing test #3 @@ -434,15 +383,9 @@ test_expect_success 'subtest: --run with a left open range' ' ' test_expect_success 'subtest: --run with a right open range' ' - write_and_run_sub_test_lib_test run-right-open-range \ - --run="4-" <<-\EOF && - for i in 1 2 3 4 5 6 - do - test_expect_success "passing test #$i" "true" - done - test_done - EOF - check_sub_test_lib_test run-right-open-range <<-\EOF + run_sub_test_lib_test git-skip-tests-several \ + --run="4-" && + check_sub_test_lib_test git-skip-tests-several <<-\EOF > ok 1 # skip passing test #1 (--run) > ok 2 # skip passing test #2 (--run) > ok 3 # skip passing test #3 (--run) @@ -455,15 +398,9 @@ test_expect_success 'subtest: --run with a right open range' ' ' test_expect_success 'subtest: --run with basic negation' ' - write_and_run_sub_test_lib_test run-basic-neg \ - --run="!3" <<-\EOF && - for i in 1 2 3 4 5 6 - do - test_expect_success "passing test #$i" "true" - done - test_done - EOF - check_sub_test_lib_test run-basic-neg <<-\EOF + run_sub_test_lib_test git-skip-tests-several \ + --run="!3" && + check_sub_test_lib_test git-skip-tests-several <<-\EOF > ok 1 - passing test #1 > ok 2 - passing test #2 > ok 3 # skip passing test #3 (--run) @@ -476,15 +413,9 @@ test_expect_success 'subtest: --run with basic negation' ' ' test_expect_success 'subtest: --run with two negations' ' - write_and_run_sub_test_lib_test run-two-neg \ - --run="!3,!6" <<-\EOF && - for i in 1 2 3 4 5 6 - do - test_expect_success "passing test #$i" "true" - done - test_done - EOF - check_sub_test_lib_test run-two-neg <<-\EOF + run_sub_test_lib_test git-skip-tests-several \ + --run="!3,!6" && + check_sub_test_lib_test git-skip-tests-several <<-\EOF > ok 1 - passing test #1 > ok 2 - passing test #2 > ok 3 # skip passing test #3 (--run) @@ -497,15 +428,9 @@ test_expect_success 'subtest: --run with two negations' ' ' test_expect_success 'subtest: --run a range and negation' ' - write_and_run_sub_test_lib_test run-range-and-neg \ - --run="-4,!2" <<-\EOF && - for i in 1 2 3 4 5 6 - do - test_expect_success "passing test #$i" "true" - done - test_done - EOF - check_sub_test_lib_test run-range-and-neg <<-\EOF + run_sub_test_lib_test git-skip-tests-several \ + --run="-4,!2" && + check_sub_test_lib_test git-skip-tests-several <<-\EOF > ok 1 - passing test #1 > ok 2 # skip passing test #2 (--run) > ok 3 - passing test #3 @@ -518,15 +443,9 @@ test_expect_success 'subtest: --run a range and negation' ' ' test_expect_success 'subtest: --run range negation' ' - write_and_run_sub_test_lib_test run-range-neg \ - --run="!1-3" <<-\EOF && - for i in 1 2 3 4 5 6 - do - test_expect_success "passing test #$i" "true" - done - test_done - EOF - check_sub_test_lib_test run-range-neg <<-\EOF + run_sub_test_lib_test git-skip-tests-several \ + --run="!1-3" && + check_sub_test_lib_test git-skip-tests-several <<-\EOF > ok 1 # skip passing test #1 (--run) > ok 2 # skip passing test #2 (--run) > ok 3 # skip passing test #3 (--run) @@ -539,15 +458,9 @@ test_expect_success 'subtest: --run range negation' ' ' test_expect_success 'subtest: --run include, exclude and include' ' - write_and_run_sub_test_lib_test run-inc-neg-inc \ - --run="1-5,!1-3,2" <<-\EOF && - for i in 1 2 3 4 5 6 - do - test_expect_success "passing test #$i" "true" - done - test_done - EOF - check_sub_test_lib_test run-inc-neg-inc <<-\EOF + run_sub_test_lib_test git-skip-tests-several \ + --run="1-5,!1-3,2" && + check_sub_test_lib_test git-skip-tests-several <<-\EOF > ok 1 # skip passing test #1 (--run) > ok 2 - passing test #2 > ok 3 # skip passing test #3 (--run) @@ -560,15 +473,9 @@ test_expect_success 'subtest: --run include, exclude and include' ' ' test_expect_success 'subtest: --run include, exclude and include, comma separated' ' - write_and_run_sub_test_lib_test run-inc-neg-inc-comma \ - --run=1-5,!1-3,2 <<-\EOF && - for i in 1 2 3 4 5 6 - do - test_expect_success "passing test #$i" "true" - done - test_done - EOF - check_sub_test_lib_test run-inc-neg-inc-comma <<-\EOF + run_sub_test_lib_test git-skip-tests-several \ + --run=1-5,!1-3,2 && + check_sub_test_lib_test git-skip-tests-several <<-\EOF > ok 1 # skip passing test #1 (--run) > ok 2 - passing test #2 > ok 3 # skip passing test #3 (--run) @@ -581,15 +488,9 @@ test_expect_success 'subtest: --run include, exclude and include, comma separate ' test_expect_success 'subtest: --run exclude and include' ' - write_and_run_sub_test_lib_test run-neg-inc \ - --run="!3-,5" <<-\EOF && - for i in 1 2 3 4 5 6 - do - test_expect_success "passing test #$i" "true" - done - test_done - EOF - check_sub_test_lib_test run-neg-inc <<-\EOF + run_sub_test_lib_test git-skip-tests-several \ + --run="!3-,5" && + check_sub_test_lib_test git-skip-tests-several <<-\EOF > ok 1 - passing test #1 > ok 2 - passing test #2 > ok 3 # skip passing test #3 (--run) @@ -602,15 +503,9 @@ test_expect_success 'subtest: --run exclude and include' ' ' test_expect_success 'subtest: --run empty selectors' ' - write_and_run_sub_test_lib_test run-empty-sel \ - --run="1,,3,,,5" <<-\EOF && - for i in 1 2 3 4 5 6 - do - test_expect_success "passing test #$i" "true" - done - test_done - EOF - check_sub_test_lib_test run-empty-sel <<-\EOF + run_sub_test_lib_test git-skip-tests-several \ + --run="1,,3,,,5" && + check_sub_test_lib_test git-skip-tests-several <<-\EOF > ok 1 - passing test #1 > ok 2 # skip passing test #2 (--run) > ok 3 - passing test #3 @@ -660,12 +555,9 @@ test_expect_success 'subtest: --run keyword selection' ' ' test_expect_success 'subtest: --run invalid range end' ' - write_and_run_sub_test_lib_test_err run-inv-range-end \ - --run="1-z" <<-\EOF && - test_expect_success "passing test #1" "true" - test_done - EOF - check_sub_test_lib_test_err run-inv-range-end \ + run_sub_test_lib_test_err run-inv-range-start \ + --run="1-z" && + check_sub_test_lib_test_err run-inv-range-start \ <<-\EOF_OUT 3<<-EOF_ERR > FATAL: Unexpected exit with code 1 EOF_OUT From patchwork Wed Jul 21 22:57: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: 12392435 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 3D46BC6377A for ; Wed, 21 Jul 2021 22:58:40 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2C7D861249 for ; Wed, 21 Jul 2021 22:58:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230425AbhGUWSA (ORCPT ); Wed, 21 Jul 2021 18:18:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60590 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230408AbhGUWRy (ORCPT ); Wed, 21 Jul 2021 18:17:54 -0400 Received: from mail-wm1-x32f.google.com (mail-wm1-x32f.google.com [IPv6:2a00:1450:4864:20::32f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BCFCFC061796 for ; Wed, 21 Jul 2021 15:58:30 -0700 (PDT) Received: by mail-wm1-x32f.google.com with SMTP id o30-20020a05600c511eb029022e0571d1a0so1851740wms.5 for ; Wed, 21 Jul 2021 15:58:30 -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=HRsddE9U+TLcTdxYSZ5Cb133KMYDZ1JObsBO+6/1MjQ=; b=di53IarjNnU6tOgGPl4DTtA3rOVkhNaKNskvmrEAT4v9if7Lk1lNaDWFKf7y4IGZ5d BxryJ2JoH3CSd/rsZdSezxUszl4oUA86//Ym9tO5WPSKKIabONuteB3kRigUaKpcg0L0 3iSYbSVIp7Ktky9SAhXGugHSzDvfZixiTZ9AjeN01jK5/DT5Ggpi/1gj9bOHtZvP+ETL tXla0Qmb6LI9kSPyJIX7k7ZAr/ZNkrSbEgnq098YPWDlf6EqoaTFTvzTwKMMTf6fTU06 B6i6NzjNs1rbMBP32kMnEjGseUvjfEyRlGliImNR+oXxucHCfuGhCqrkILJLeOLRoha8 lhUQ== 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=HRsddE9U+TLcTdxYSZ5Cb133KMYDZ1JObsBO+6/1MjQ=; b=nXRcIwJGzp3IsdZhwIHksqwr0rlS32WDKkTxr8fdmOB/c3Hc09BTXfAV1A3vEEfqNa ZqSA3fzLuZx860tEbpXCvsLtjRN6d26SrtCyDo6q+IdNINusFfaIal/ATVHf4QPwMzTT dyctGcYHGyAJ5/MMBsJpmRhm0KEohDVOWjr1YkIsX/MU2rGPZVvbxcbmJoJXf+soNWGR zMS3YpUY84v28yFlr7J0nbVBiMGYpm5WrobbWi6lJrx9oUaF+jfrYpaUqlG0kIUc1BqL r3NLEScFYcrkT36mne/DWHaGNQ6sxgc/MT/lu6DvkzgcDcBoQS8Y/9Jp1oJpj7E74scJ qpbg== X-Gm-Message-State: AOAM530yQTAgiqe/3WzlBxBQrkftCkTep3g7yvDfoDdQO/DBof5TGUAK HLjSD0OAM7Y8h6gSJeQ9OPQRQO5Mj9f3Lw== X-Google-Smtp-Source: ABdhPJx3vMve7mKsAEvnuujLO7gen/zpXrKM6aVsmTLPGC2PsDb1m4CnANWmBXRizTCD+qkqSh5H9g== X-Received: by 2002:a7b:c251:: with SMTP id b17mr6074399wmj.83.1626908309201; Wed, 21 Jul 2021 15:58:29 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id g18sm23129818wmk.37.2021.07.21.15.58.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Jul 2021 15:58:28 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Jeff King , Felipe Contreras , Adam Spiers , Thomas Rast , Ilya Bobyr , Patrick Steinhardt , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v2 6/8] test-lib tests: avoid subshell for "test_cmp" for readability Date: Thu, 22 Jul 2021 00:57:45 +0200 Message-Id: X-Mailer: git-send-email 2.32.0.955.ge7c5360f7e7 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org The use of a sub-shell for running the test_cmp of stdout/stderr for the test author was introduced in this form in 565b6fa87bb (tests: refactor mechanics of testing in a sub test-lib, 2012-12-16), but from looking at the history that seemed to have diligently copied my original ad-hoc implementation in 7b905119703 (t/t0000-basic.sh: Run the passing TODO test inside its own test-lib, 2010-08-19). There's no reason to use a subshell here, we try to avoid it in general. It also improves readability, if the test fails we print out the relative path in the trash directory that needs to be looked at. Before that was mostly obscured, since the "write_sub_test_lib_test" will pick the directory for you from the test name. Signed-off-by: Ævar Arnfjörð Bjarmason --- t/lib-subtest.sh | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/t/lib-subtest.sh b/t/lib-subtest.sh index d98390606b8..96a4e6e259a 100644 --- a/t/lib-subtest.sh +++ b/t/lib-subtest.sh @@ -111,23 +111,17 @@ run_sub_test_lib_test_err () { check_sub_test_lib_test () { name="$1" # stdin is the expected output from the test - ( - cd "$name" && - test_must_be_empty err && - sed -e 's/^> //' -e 's/Z$//' >expect && - test_cmp expect out - ) + test_must_be_empty "$name"/err && + sed -e 's/^> //' -e 's/Z$//' >"$name"/expect && + test_cmp "$name/"expect "$name"/out } check_sub_test_lib_test_err () { name="$1" # stdin is the expected output from the test # expected error output is in descriptor 3 - ( - cd "$name" && - sed -e 's/^> //' -e 's/Z$//' >expect.out && - test_cmp expect.out out && - sed -e 's/^> //' -e 's/Z$//' <&3 >expect.err && - test_cmp expect.err err - ) + sed -e 's/^> //' -e 's/Z$//' >"$name"/expect.out && + test_cmp "$name"/expect.out "$name"/out && + sed -e 's/^> //' -e 's/Z$//' <&3 >"$name"/expect.err && + test_cmp "$name"/expect.err "$name"/err } From patchwork Wed Jul 21 22:57: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: 12392437 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 D7A7AC6377C for ; Wed, 21 Jul 2021 22:58:40 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C60B761263 for ; Wed, 21 Jul 2021 22:58:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230433AbhGUWSB (ORCPT ); Wed, 21 Jul 2021 18:18:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60596 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230397AbhGUWRz (ORCPT ); Wed, 21 Jul 2021 18:17:55 -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 9DE27C061575 for ; Wed, 21 Jul 2021 15:58:31 -0700 (PDT) Received: by mail-wr1-x433.google.com with SMTP id d2so3878776wrn.0 for ; Wed, 21 Jul 2021 15:58:31 -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=trXAgveWKvc/T7VHAkLmpfOcSo7Zd8J0v99WO/Opktk=; b=PuX/brNBDB3joCl20CEjkUJwEZeuICvacVPfieb9T8uH11M/ahwlmiMJc/9sXi+9SV qF3kqwqiVlAVxvRFKsmWEhCx7K+0dCeb9eQScnnzCNVcLUp+WfUqI4WIaGWx5sqBUkhc xiCCWPc25HogAmKyzLfPFNXzuFilEawxZhJh7Dk5RcTJBqUYjNSVUb3y+bBWOjIuA8e6 T7AHo2cAj4rQDnjZ68RZXsi3J2x0lPGg1Dr+9Nb9LHT8cXh2Fs6aDpiqagdKS+80WnNw HMDPyPa7pcXR+/oToklDv+hQjDyYPKS2i9X+PcidvL7/TiZuNpQFpwyVNc12TF2UccDr 8cjw== 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=trXAgveWKvc/T7VHAkLmpfOcSo7Zd8J0v99WO/Opktk=; b=FAzCYR8m/HZ+Tpe3pz8JYhNJ7e7dMyA+aTfYeYUmTO4k/jwkF/f4gGvqYpvMWyCXpo EjTDPVQ5wr2FofYYd/dRxNUgYr/+RxvwB4QBt58m7DCfAz7C7e0olrBOLUJyCNfdq8Pm oSdig4iRkzuL4TIKp7cjhEpZ1qi/JjfuRkEYa7biw2/IP4LDnWOwApb3jLb5zD98O8cl e/60hdx2AozJlg4VLe3Ne85/38NBc2la4J5Bvc/PCJ7qzf/G7qAFqyYVQdLFKtZUYhsR wSkcLwNu8y87yd4D/ImjARAOGH1l9DtRelpx5cVsSnAfYK3h7yJxlLXn6BOP+/3ud7dw /+4g== X-Gm-Message-State: AOAM531PiBXvv52PAo+nsSSHwiVUxLmd7zZ1HmKJ79cxAI/9U/4EFDUX WOTRlaqnUYtlux7BzpoQ16VT+pNGhJaw6g== X-Google-Smtp-Source: ABdhPJzSQaDyPQMds9K4iG+EbEFWPQGRzGuua1u4rBsLiKy6L8L1oBB+wyLwT65P+hWFb1YPsth/ug== X-Received: by 2002:a5d:55c1:: with SMTP id i1mr45522636wrw.77.1626908310024; Wed, 21 Jul 2021 15:58:30 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id g18sm23129818wmk.37.2021.07.21.15.58.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Jul 2021 15:58:29 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Jeff King , Felipe Contreras , Adam Spiers , Thomas Rast , Ilya Bobyr , Patrick Steinhardt , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v2 7/8] test-lib tests: refactor common part of check_sub_test_lib_test*() Date: Thu, 22 Jul 2021 00:57:46 +0200 Message-Id: X-Mailer: git-send-email 2.32.0.955.ge7c5360f7e7 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Refactor the two check_sub_test_lib_test*() functions to avoid duplicating the same comparison they did of stdout. This duplication was initially added when check_sub_test_lib_test_err() was added in 0445e6f0a12 (test-lib: '--run' to run only specific tests, 2014-04-30). Signed-off-by: Ævar Arnfjörð Bjarmason --- t/lib-subtest.sh | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/t/lib-subtest.sh b/t/lib-subtest.sh index 96a4e6e259a..2fde75e8863 100644 --- a/t/lib-subtest.sh +++ b/t/lib-subtest.sh @@ -109,18 +109,22 @@ run_sub_test_lib_test_err () { _run_sub_test_lib_test_common '!' "$@" } +_check_sub_test_lib_test_common () { + name="$1" && + sed -e 's/^> //' -e 's/Z$//' >"$name"/expect.out && + test_cmp "$name"/expect.out "$name"/out +} + check_sub_test_lib_test () { name="$1" # stdin is the expected output from the test - test_must_be_empty "$name"/err && - sed -e 's/^> //' -e 's/Z$//' >"$name"/expect && - test_cmp "$name/"expect "$name"/out + _check_sub_test_lib_test_common "$name" && + test_must_be_empty "$name"/err } check_sub_test_lib_test_err () { name="$1" # stdin is the expected output from the test + _check_sub_test_lib_test_common "$name" && # expected error output is in descriptor 3 - sed -e 's/^> //' -e 's/Z$//' >"$name"/expect.out && - test_cmp "$name"/expect.out "$name"/out && sed -e 's/^> //' -e 's/Z$//' <&3 >"$name"/expect.err && test_cmp "$name"/expect.err "$name"/err } From patchwork Wed Jul 21 22:57:47 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: 12392439 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 C25B1C6377D for ; Wed, 21 Jul 2021 22:58:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 998D461264 for ; Wed, 21 Jul 2021 22:58:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230422AbhGUWSC (ORCPT ); Wed, 21 Jul 2021 18:18:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60600 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230363AbhGUWR5 (ORCPT ); Wed, 21 Jul 2021 18:17:57 -0400 Received: from mail-wr1-x431.google.com (mail-wr1-x431.google.com [IPv6:2a00:1450:4864:20::431]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 67517C061757 for ; Wed, 21 Jul 2021 15:58:32 -0700 (PDT) Received: by mail-wr1-x431.google.com with SMTP id c12so3831318wrt.3 for ; Wed, 21 Jul 2021 15:58:32 -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=ca7gPfBflFJKt+Ja0OgoxM033TuU7eqZBTOXoCvk1dM=; b=daYOtWTka/DQPJL1G6tm7ofOCb27jiK/6I6KM2f3gE/oFegK5YQi5PdtGxg/Kr2apx J/jD7VVJqzissMJKmT2mIqhQu7tuVBZDYzL0BKkiW6KsngB2ZK8b/pSIYePDNl6/8b5/ jA2DaIp1a5FPqquh94/UyTlrYsWkiyMgvFoCqKlNofYDl3Boe7Qil+KO/IVDJS/RcuTP JDN3mhmawENSxBmp+S/aW0bHXkb/DrfuK+Z2Ku2rVfOKXG0iH+SCKdBqVwy7MiWIaAIW 1kKCgqZUmkN3Wb/eo6whe0GAhxwKfegWWNOUzioVov0E1jaE0vgxggUUSrQ8AGlhQATA esKg== 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=ca7gPfBflFJKt+Ja0OgoxM033TuU7eqZBTOXoCvk1dM=; b=Oko4i0q/PhLJhQLyHcZ/wH9y3aj0unVQDXjRIuVkcBvlrtf7ddlG7bMvqGXgGdIpEW CQijNtkv4SLb+hHRCk8d155sphcUUZXtyn29PcaLGF7BQu04RYwmImf/T7Gh6mx6vC/J QDupsziFfASi3Z94WH9iQa6lfXGfCfsz52tfVw+A+MeRvv2TDM8/Ifpl496e4R2yPpgE NV4xMj7q7pOpXXUlBYk+gIWINVu558oDYsJKKu0ia4SATonTzTH2ZLeVMucfDjZQSUoO JwlXgZRtvZFORWf7l/Ym+fCj+xcneleSFkkQ+vgyFVm377OWglsAN40n75L6VDATToSR w6DQ== X-Gm-Message-State: AOAM530MO1Ot7EyDkIil3qOwESarJWGBP2/Tgd1r2VeGF8XuyYCWrM5y V4iZ528q8QmafFE/wPoTA8Ayib4ruvNVpg== X-Google-Smtp-Source: ABdhPJwJRGrhUS0e44U5CQp4qw/ITCK3eNFWypuw4wDlQAQV84oHmR1dnZmyvPHTO9Ed/FiCOPK/6A== X-Received: by 2002:a5d:4a4c:: with SMTP id v12mr44483387wrs.256.1626908310810; Wed, 21 Jul 2021 15:58:30 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id g18sm23129818wmk.37.2021.07.21.15.58.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Jul 2021 15:58:30 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Jeff King , Felipe Contreras , Adam Spiers , Thomas Rast , Ilya Bobyr , Patrick Steinhardt , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v2 8/8] test-lib tests: assert 1 exit code, not non-zero Date: Thu, 22 Jul 2021 00:57:47 +0200 Message-Id: X-Mailer: git-send-email 2.32.0.955.ge7c5360f7e7 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Improve the testing for test-lib.sh itself to assert that we have a exit code of 1, not any non-zero. Improves code added in 0445e6f0a12 (test-lib: '--run' to run only specific tests, 2014-04-30). Signed-off-by: Ævar Arnfjörð Bjarmason --- t/lib-subtest.sh | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/t/lib-subtest.sh b/t/lib-subtest.sh index 2fde75e8863..f7ad7bc7d7d 100644 --- a/t/lib-subtest.sh +++ b/t/lib-subtest.sh @@ -43,8 +43,8 @@ write_sub_test_lib_test () { } _run_sub_test_lib_test_common () { - neg="$1" name="$2" # stdin is the body of the test code - shift 2 + cmp_op="$1" want_code="$2" name="$3" # stdin is the body of the test code + shift 3 # intercept pseudo-options at the front of the argument list that we # will not pass to child script @@ -80,33 +80,30 @@ _run_sub_test_lib_test_common () { GIT_SKIP_TESTS=$skip && export GIT_SKIP_TESTS && sane_unset GIT_TEST_FAIL_PREREQS && - if test -z "$neg" - then - ./"$name.sh" "$@" >out 2>err - else - ! ./"$name.sh" "$@" >out 2>err - fi + ./"$name.sh" "$@" >out 2>err; + ret=$? && + test "$ret" "$cmp_op" "$want_code" ) } write_and_run_sub_test_lib_test () { name="$1" descr="$2" # stdin is the body of the test code write_sub_test_lib_test "$@" || return 1 - _run_sub_test_lib_test_common '' "$@" + _run_sub_test_lib_test_common -eq 0 "$@" } write_and_run_sub_test_lib_test_err () { name="$1" descr="$2" # stdin is the body of the test code write_sub_test_lib_test "$@" || return 1 - _run_sub_test_lib_test_common '!' "$@" + _run_sub_test_lib_test_common -eq 1 "$@" } run_sub_test_lib_test () { - _run_sub_test_lib_test_common '' "$@" + _run_sub_test_lib_test_common -eq 0 "$@" } run_sub_test_lib_test_err () { - _run_sub_test_lib_test_common '!' "$@" + _run_sub_test_lib_test_common -eq 1 "$@" } _check_sub_test_lib_test_common () {