From patchwork Thu Aug 5 10:37:20 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: 12420785 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 9D53DC432BE for ; Thu, 5 Aug 2021 10:37:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7AC00610CC for ; Thu, 5 Aug 2021 10:37:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240483AbhHEKhw (ORCPT ); Thu, 5 Aug 2021 06:37:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45154 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240451AbhHEKht (ORCPT ); Thu, 5 Aug 2021 06:37:49 -0400 Received: from mail-wr1-x42f.google.com (mail-wr1-x42f.google.com [IPv6:2a00:1450:4864:20::42f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9218CC0613D5 for ; Thu, 5 Aug 2021 03:37:34 -0700 (PDT) Received: by mail-wr1-x42f.google.com with SMTP id d8so5885502wrm.4 for ; Thu, 05 Aug 2021 03:37:34 -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=45ZJCHAoA8WMIAkk9sQ3qHCRDCj4NfQvBgXUK6pD24Q=; b=diUZbzapP54WN0d4Ld+AfiPnP5JxPoOAObhKM8DBMRnHvR8ZiLEBjHc6C9sbcQxQI+ ESnTZHaRXHt5E/YVoWW8qkXIm7VeLkg6nMKRL7FIHFug055E+2CwKUfYSysjm5ZdNYg1 8RvSLoVbU64wNHaKtslgKd5PDgQ/y4dtf6YWY0+Y9Q9Epdd4cA5a0j7U9tmX1h1mfq4h qbFUg+bRqiZj9Fp673BXkfr3mjjZrNlW4gNC7MznyuZtEnVdyWFpYE6aTucD9lAbEvGl czcWZOAAVK5JjEO5NS7WyZEqlkdFfAUjJpH+BZ92/EZ6zpCfBtXvNF+2CvtDoAKRtuPh c45w== 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=45ZJCHAoA8WMIAkk9sQ3qHCRDCj4NfQvBgXUK6pD24Q=; b=lIYqO5IEYipFvng5LwubNIs/o3gnf6O0Qb64aKLF+d0zmth8iH2nN9AfAESh6q6IZ1 f6ecymVCz9lMS83OpZXGSQBYL+/d46XiUYOJAAOi7JltkIUYXMFz/bzK6iato4f+Uqle L87iZm982CUzZhiXPoWj3uFggvbYjV3qXzVIXj4vE+kWZMow5wqXqxkUcwVFt6lO2k7X 281tjOZQrgA4yuVOjl1TKt2jvWwAUcX68TSHD2ASULmHao4fupBvi5Cd6bIEKoQhq+Gc P2wagKHQ7pz6ncz7OSJL/zUnshdYZBnaTo2jdioIBwZGaBSa1sYbYaYhSyOmXmzEKtwu YtKg== X-Gm-Message-State: AOAM533epuL97EGl0XOgZWhkcSQrBXR8JASIQOtAtzJm+Py21FiG0ipd m9ODvScgpuBzu8/9Z8Ak9bndrLPn0rTx3g== X-Google-Smtp-Source: ABdhPJwCcIa9h9H1Rd586dcfbiRudvNLJqSW39kP9ZwTm3PAyOnt3cQmwEQ43zVfa5kune8cD8hplg== X-Received: by 2002:a05:6000:1ce:: with SMTP id t14mr4470446wrx.83.1628159852964; Thu, 05 Aug 2021 03:37:32 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id e6sm5106152wme.6.2021.08.05.03.37.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Aug 2021 03:37:32 -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 v3 1/9] test-lib tests: move "run_sub_test" to a new lib-subtest.sh Date: Thu, 5 Aug 2021 12:37:20 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.rc0.635.g0ab9d6d3b5a 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 0000000000..3cfe09911a --- /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 cb87768513..a3865dd77b 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 Thu Aug 5 10:37:21 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: 12420789 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 DFCDAC4338F for ; Thu, 5 Aug 2021 10:37:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C112360F02 for ; Thu, 5 Aug 2021 10:37:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240492AbhHEKhy (ORCPT ); Thu, 5 Aug 2021 06:37:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45160 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240469AbhHEKhu (ORCPT ); Thu, 5 Aug 2021 06:37:50 -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 56515C061765 for ; Thu, 5 Aug 2021 03:37:35 -0700 (PDT) Received: by mail-wm1-x32a.google.com with SMTP id h24-20020a1ccc180000b029022e0571d1a0so3336790wmb.5 for ; Thu, 05 Aug 2021 03:37:35 -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=m3Z5UZ5+Jd518Au/Icsmny+d7L2xSSM2fohX4XUMpGY=; b=EZFOchmCqASQPGyT/ixlF6mF0fZdV0Dbd8zQlxLHWpoXBPjI5PfwekWBW6jjjQLcxK EBepNXcR3V9pwBr6yrUne9faZI7Onw4hYCZSLW6TV+XsWLcyK2mvg9EtzSDZR38HG1PH JWDnhVsXW6r4J3nFyqdTqBkliSGkU3nyUVimXj9ppdD/msZnfCP0i5QF6nIpPomv7rOu e3tW2Vznyg+WgNE8kpwTWtLyLf6B7o08k3ZFC5ilW9cbFtP2n/OYyHmZj2L2T5gOCAvz fWmWHL12Rvt6xlDChobjRCLrt+IsfsFL9b8Do07z5vpNpWF5CO4VWCBmMw0fNPoMQqdN sdYQ== 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=m3Z5UZ5+Jd518Au/Icsmny+d7L2xSSM2fohX4XUMpGY=; b=OWyOHRC7urZhceYPXSdWSJU3pfy6t6F0wd0o/qeMTcu/WSgOW845Z9ECqI5IjVBDbQ QL7KrIs7/BtiC65y47eFurWq1d0FqH3BDjtucUK/uNuC0URvrpa5cAiuxkMkb2sBHGz1 6upYKjTGnyVCEA3LUCU0TX3KoJFPRf5pGyGzhXAPxOc+xe2YUPrytVQxI/EWptxDFWw9 bzUVU4sl6v1ubDwg36EYqkkyDhxBPdSXa9bo5CzX1xqNJh2jD7j4ghsOEuMXLlsv2yqY cvwWoTPDiGnTc92rjcWqDaY37+C0a9OQaDfbZDwru5FgOYOr3q4nyuRdEDwrhkLtc5Nr 0Xww== X-Gm-Message-State: AOAM532RTP0JfwS6viMFsDbdAcG/dS5Y1jZ9Ekqdo4+K8dw++CNGczi2 0h3tdT94KC2ebc1lqEjUF6lZmLomWTu87w== X-Google-Smtp-Source: ABdhPJy+F0PyGRn52JZCYpX1wMOQthzbMoI+L8UtoRcAOSqEt0mA+o3VcXgWBcLU/EdZgtm9ELSv6A== X-Received: by 2002:a1c:1b14:: with SMTP id b20mr4282893wmb.170.1628159853660; Thu, 05 Aug 2021 03:37:33 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id e6sm5106152wme.6.2021.08.05.03.37.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Aug 2021 03:37:33 -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 v3 2/9] test-lib tests: split up "write and run" into two functions Date: Thu, 5 Aug 2021 12:37:21 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.rc0.635.g0ab9d6d3b5a 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 | 45 +++++++++++++++++++++-------- t/t0000-basic.sh | 74 ++++++++++++++++++++++++------------------------ 2 files changed, 70 insertions(+), 49 deletions(-) diff --git a/t/lib-subtest.sh b/t/lib-subtest.sh index 3cfe09911a..58ae316ad5 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 '' "$@" } diff --git a/t/t0000-basic.sh b/t/t0000-basic.sh index a3865dd77b..a7c5aaacab 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 Thu Aug 5 10:37:22 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: 12420787 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 7B5FAC4320A for ; Thu, 5 Aug 2021 10:37:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 629426105A for ; Thu, 5 Aug 2021 10:37:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240490AbhHEKhz (ORCPT ); Thu, 5 Aug 2021 06:37:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45162 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240436AbhHEKhu (ORCPT ); Thu, 5 Aug 2021 06:37:50 -0400 Received: from mail-wr1-x435.google.com (mail-wr1-x435.google.com [IPv6:2a00:1450:4864:20::435]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1448DC061798 for ; Thu, 5 Aug 2021 03:37:36 -0700 (PDT) Received: by mail-wr1-x435.google.com with SMTP id d8so5885586wrm.4 for ; Thu, 05 Aug 2021 03:37:36 -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=7R6TW02iBkZDktVvO42XekI9nG/RnDASGSTtRnos/Dw=; b=mAwiqGEHNIbpkoa3cwhQv7BOPSXe7bp015pBgdvHyBores5aK6cl9SHEujWN1iMhKU L9Xnx5QrR1NRLE953y460uJxh+rsVx/8xoat+CkkTrZv19IqYbc5cPjUcGFsDhnjRoBo RThWbDsKZk7BrRx4IlFnFQD/Nqv1VhDuS62NsM47awRO5kYaKxCht1PZtKQmKRgMFzDU rVvAkBZPrNILOWDpae0GPNsDe5poI3GgSCucTBmNBocGTaISno8+23IF//5CsEb1fp4E RLd8QntpVMie1tSp9bJG61mhqU+5FhcqGuUqdFySO+gQvn9a8GlpXhifK9JSzvzlqrFz HR9w== 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=7R6TW02iBkZDktVvO42XekI9nG/RnDASGSTtRnos/Dw=; b=Q8dnfZdlrwEz73IV8V9Xaln4COs5oIPiy6YlI6FSAEpWZ0902DMGALXrv5mL6lYE+R J1DIf6fgZe+O668gGSheSChzjz7RDV3JB7JVPtQBHMPj4ib6iounvZgH4sAHUvcqzAsC wudVVr60abZm/fhwmLFkK6oaxyO+8NI1x75tH4569p3T3VcUF2AbKPf4IzQTm1KTQ5H5 nzuwItvWqoGyjRidNY9+pd5MkcOc1Kdlfe+vx5+D/4P9lnUYy78C/JE1Su8bnGroauOa qb5Q1ad8FrrLenJxE9DpPOIvLttRx2NK3T5AJM6aIGsCwKrFRPBhZ65z0WLbCmmO5ePa QTQw== X-Gm-Message-State: AOAM532X9PWQ4zOkQtgmnjo+AW2FF90tJLbx1A0lbztNfFsc3exQa5rF LZ1rlV69hwjs702zrEz6PI8RXA+Vguam8g== X-Google-Smtp-Source: ABdhPJx3tD/CbyNcIBGFqUh/SG3Nvmwth9/v4DLKxcmNvTFnIpwA+tkJKwsJ10tXOp8ELieLYEdXog== X-Received: by 2002:a5d:4dc7:: with SMTP id f7mr4552956wru.118.1628159854497; Thu, 05 Aug 2021 03:37:34 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id e6sm5106152wme.6.2021.08.05.03.37.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Aug 2021 03:37:33 -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 v3 3/9] test-lib tests: stop using a subshell in write_sub_test_lib_test() Date: Thu, 5 Aug 2021 12:37:22 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.rc0.635.g0ab9d6d3b5a 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 58ae316ad5..21fa570d0b 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 Thu Aug 5 10:37:23 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: 12420793 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 D9D72C4338F for ; Thu, 5 Aug 2021 10:37:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B257E610CC for ; Thu, 5 Aug 2021 10:37:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240511AbhHEKh7 (ORCPT ); Thu, 5 Aug 2021 06:37:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45172 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240485AbhHEKhw (ORCPT ); Thu, 5 Aug 2021 06:37:52 -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 E8D6AC061765 for ; Thu, 5 Aug 2021 03:37:36 -0700 (PDT) Received: by mail-wm1-x333.google.com with SMTP id l34-20020a05600c1d22b02902573c214807so5955067wms.2 for ; Thu, 05 Aug 2021 03:37:36 -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=RKODqEJEtJYp9aUk2z9L83NdCy97u7BPgi0uYJ93eOM=; b=rLh5+I8rz8+GqpEDtXitgZVT6K5vmiFrY10yBfnifydThCkhfku7PpuoE17FbJrwNP ZIqe+tQkJRSCOkoZStq36+8cv8m6s9SJqwrkwQJuiupiBQRU6eu5HdVbiPxJJk5aCF9T Vg98WoZs0b/gcivaswv+H5oXcZRRld68EbrJcrUTFyn1cVHvbpUsGhZ4OaNXAGA3OWDY 8QZs7eHJKgTal9jYekQybZHYZxtAPTMT7Dgqjlbt3pdjb0GEgE6omVX0hai9SVJ+Nr7+ 5M2n+jzDZskEgwTN9WRgocec9eoxL1jDcjArrKo3Pnn4e7hj3t852/6eL81VNnx8n8TZ +vRw== 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=RKODqEJEtJYp9aUk2z9L83NdCy97u7BPgi0uYJ93eOM=; b=YlE9aXRApzDmFbn/3Gc5fV65TSlgt8juaZ85Oe2pmVBtIz8X9/NjxJnzWaEjdFbD2x 2eJxxT+3SGdbz3TCPX6pQw8MAls4j2m/U0t9PieopUnSeG+vhGyCV22VvyRUa1JLiKTT fFOnIEQN0D3xeTSyASvkj4EGfQhlJqyW9eCDT4Qx3RkRlpftFq7gGM/iAbqzAgURut86 7GQoplRT92+c1v7LYdjh5eQ2ZJf8yjlEQTbhin6GCVHuT4eWedxNUieFZcDZNnP6EJJq Ex/QUn64Nd5ohPmDHnxjluGpu7SOCMZWj202N1zhQfBY1FmOOGtaKR5ukbgGMpLtDYtN Vj+g== X-Gm-Message-State: AOAM531GoshEVhFKlN7TJDH/x5PzVwVvN+1IEogKsIqUae1PwPfX2f/d f923NC0qxGgtFw1pmuzNp2zGDSxWe6JMiQ== X-Google-Smtp-Source: ABdhPJx1y0P/FItAw28TML9RiBaa07GwlbLqXOpdOJ1RmcyHFQDse5BNn3FA0oIN9P2oO6dmecDXag== X-Received: by 2002:a1c:7402:: with SMTP id p2mr14510194wmc.111.1628159855259; Thu, 05 Aug 2021 03:37:35 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id e6sm5106152wme.6.2021.08.05.03.37.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Aug 2021 03:37:34 -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 v3 4/9] test-lib tests: don't provide a description for the sub-tests Date: Thu, 5 Aug 2021 12:37:23 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.rc0.635.g0ab9d6d3b5a 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 21fa570d0b..cdbc2d9332 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 a7c5aaacab..6fdd5f43ca 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 Thu Aug 5 10:37:24 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: 12420791 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 16E2EC432BE for ; Thu, 5 Aug 2021 10:37:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E66466105A for ; Thu, 5 Aug 2021 10:37:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240504AbhHEKh5 (ORCPT ); Thu, 5 Aug 2021 06:37:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45174 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240484AbhHEKhw (ORCPT ); Thu, 5 Aug 2021 06:37:52 -0400 Received: from mail-wm1-x335.google.com (mail-wm1-x335.google.com [IPv6:2a00:1450:4864:20::335]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 01642C0613D5 for ; Thu, 5 Aug 2021 03:37:37 -0700 (PDT) Received: by mail-wm1-x335.google.com with SMTP id l4-20020a05600c1d04b02902506f89ad2dso5262056wms.1 for ; Thu, 05 Aug 2021 03:37:37 -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=0eWJ+K3YqTrZE46FRPm/8WAmEnI5R0kcdXsZEv4n6fY=; b=Bhri7vkVoz1BoyPpMsrhjlju9bcApxmyq7amVJkoJl6dvVX5Hw/LUf2W0ebAtOJJ7I rj7aNzqkp/xXmHoD/MHPsJOoKQHhLnbR8G8UL701UrEG3O6pmgky3B3Tr8ujWoXah+Tk sjfzhUWCH2Bh+Kf21f2qskEQVllMnWu1wdI2Wo0Qv1Xpats7c24hfiS2iL/1kIfuFNmj ZkBle73pyYeNxgkyl68fKtjgt5wNobS9ramNzhWe07+TOxHEWqMwqSCQ1oH3wfHapwQc k/Zv3Tg/LxmQa3qliltmpVoNNeH1nDxJhN/w+VFlGuSZ4SHsVHr/W6qp+Z4oMEfbXmkH j/4A== 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=0eWJ+K3YqTrZE46FRPm/8WAmEnI5R0kcdXsZEv4n6fY=; b=XQTfCp+qzn9sIJMoR2vnsWQPQGXgR6hSxZRDBd3h9XgrbbLee28fyp/DOTv7FUlD0P 0gAflzfTCvTcsJvsTXehGTqxCbzFE995XD7aRpP3VseZfyipq0dbPUl8PQ1vPmCxsJP+ 2OMkgs0+iTS47JZmabC92PfZHE93MVdqcPOAERnjU6gel9mP3GJaTTJ5wScm4jadUo3B uNU4jp5B/eSZhzjBs7mLHm0cu5Ow973vN+/zJ8zQUF9pmUuw+J3uSDiPnTfIOQleOa60 m+FTuFnyAt8Ax7YLai+IythMpOT0vlWmwUCy8foydczOS78IRrhd6XD6KFf8jHfGkg1G W90w== X-Gm-Message-State: AOAM530y/cmDwuMDMUoSyMLOg+xmDBGn47ZpSRn1gZYvB8wgDKXSAi4b x2DAn+Ks1gD5BLrb1Wk3i83jXM3lenexQg== X-Google-Smtp-Source: ABdhPJzAoFZcbhyyma05pxhf31Yo9XcZJviD2yWMlgiEpcaVmP5/R9tgiwGM8dKxJRU1vGBpuNJcPg== X-Received: by 2002:a05:600c:4f8d:: with SMTP id n13mr14667111wmq.14.1628159856251; Thu, 05 Aug 2021 03:37:36 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id e6sm5106152wme.6.2021.08.05.03.37.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Aug 2021 03:37:35 -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 v3 5/9] test-lib tests: get rid of copy/pasted mock test code Date: Thu, 5 Aug 2021 12:37:24 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.rc0.635.g0ab9d6d3b5a 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. In a subsequent commit we'll add an assertion to check whether we caught all of the copy/pasting. Signed-off-by: Ævar Arnfjörð Bjarmason --- t/t0000-basic.sh | 228 +++++++++++++---------------------------------- 1 file changed, 60 insertions(+), 168 deletions(-) diff --git a/t/t0000-basic.sh b/t/t0000-basic.sh index 6fdd5f43ca..a0b99d8334 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 Thu Aug 5 10:37:25 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: 12420795 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 AA212C432BE for ; Thu, 5 Aug 2021 10:37:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 925BA60F02 for ; Thu, 5 Aug 2021 10:37:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240513AbhHEKiA (ORCPT ); Thu, 5 Aug 2021 06:38:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45178 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240486AbhHEKhx (ORCPT ); Thu, 5 Aug 2021 06:37:53 -0400 Received: from mail-wr1-x42d.google.com (mail-wr1-x42d.google.com [IPv6:2a00:1450:4864:20::42d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A594BC061798 for ; Thu, 5 Aug 2021 03:37:38 -0700 (PDT) Received: by mail-wr1-x42d.google.com with SMTP id c9so5856263wri.8 for ; Thu, 05 Aug 2021 03:37:38 -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=piozFKr93/kXTBzcc9Aljkv4Wd/3p/FY6kbHHwm1ZuI=; b=O6Q8GjHyIUzXxGn44Y1vWNBh3pPj/DCBya5MjQ3JXP4SHiOuHxO9VqfweNGdbv76lx w/jnOnftW4pvglDcQTcb/5nas3nbj5X9s6FNh+tFJCWgS41wSDes89LYP8R8yTuCUUWB uNd62kSeIvb2oPSWAxPU76PnvZP7U5ASGHAJ76bYhNnh5E6UnJ+bc+Uk5CUNmB2NSDhe 3W4rU576hMvgHeiORqcbGIeG7R8Caqk9/KdtxJRBw4Lcbcgwq++8z8us8nP+JCH/bKfm RtZ5OBChNB0i4itsFfkPK/0+D7eMsg/f7nCfVE5PBnmktVhqPBCHBziDR3FIc3KIqr8b xVIw== 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=piozFKr93/kXTBzcc9Aljkv4Wd/3p/FY6kbHHwm1ZuI=; b=Yfbk6BNjQRKkXPCOCBqWnRY4zSW8GFMpXMXZiAfi7DHTifcWK3JpCL4o3CyILkT1v8 gX15+C5mBTSqGuUgydKk7urMrRym7CBuvuMEfsGcV/Ty8InW3L9jnhBUkDYC6UeOtJ5Y DlZFeAYXt/uoG1/TC74irtku9B075GlJ+p5k/sV7MxN150qunselUpucDOpFdOqM8FPL IvSc559+erlnN3JilsZRIWJU69yO6MHr9yrccOmX4WEiOvv+sgOfKO/TZvgj4kN5edo+ Y9CbuqfyBCo+ehGI9IoIVuUw+UhIgi0EHs2eIqj8BpRCJL2Jo6LJ5APK3UuT6uSRlxZM NXpg== X-Gm-Message-State: AOAM531Ulwzmek+vnmubzTJSzaTiFU51MsAuHFC9PvajgyeyU29EXRdG a+9sUYCwcGMVZj67jZN9a0BJW7AP8g5hVQ== X-Google-Smtp-Source: ABdhPJzklnM9ej35/YdNLYPLhNNNtuIJbfL5Bt262NBck3u+9xD6/VF5qtWGDZXVG4wk3mwls+ecxw== X-Received: by 2002:a5d:420c:: with SMTP id n12mr4480001wrq.58.1628159857059; Thu, 05 Aug 2021 03:37:37 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id e6sm5106152wme.6.2021.08.05.03.37.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Aug 2021 03:37:36 -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 v3 6/9] test-lib tests: assert no copy/pasted mock test code Date: Thu, 5 Aug 2021 12:37:25 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.rc0.635.g0ab9d6d3b5a In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org In the preceding commit we got rid of a bunch of copy/pasted test code from t0000-basic.sh in favor of re-using earlier already set up tests. Since copy/pasting the tests is likely to be something done by mistake in the future, let's add an assertion that detects whether this has happened. Now that we don't provide a unique test_description="" to these tests we can rely on the content written out being the same in this case. Let's use the object store to hash it, and attempt to create a "blob-" tag. If another test has already written out the same content we'll fail, and the tag envelope will provide an error message pointing us in the right direction.. Signed-off-by: Ævar Arnfjörð Bjarmason --- t/lib-subtest.sh | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/t/lib-subtest.sh b/t/lib-subtest.sh index cdbc2d9332..6857afdaa5 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 () { From patchwork Thu Aug 5 10:37:26 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: 12420797 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 3CEA3C4320A for ; Thu, 5 Aug 2021 10:37:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1F10C60F02 for ; Thu, 5 Aug 2021 10:37:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240517AbhHEKiB (ORCPT ); Thu, 5 Aug 2021 06:38:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45180 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240491AbhHEKhy (ORCPT ); Thu, 5 Aug 2021 06:37:54 -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 56082C0613D5 for ; Thu, 5 Aug 2021 03:37:39 -0700 (PDT) Received: by mail-wm1-x333.google.com with SMTP id e25-20020a05600c4b99b0290253418ba0fbso3349677wmp.1 for ; Thu, 05 Aug 2021 03:37:39 -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=HObluCioIghhWS08ajLUNwADuIdpVouuMyqbQ/ZKngg=; b=ejh7IOe9zEMeYTSldKsrSi1lwsx/S7xmYsdzpj8aZNowYMSbs26D/vKwuYxnnMRnFW dZGqhPnQd4P9n6zfyJ8Uvg+KktPWPhwEE5KEfNBelwLfdr9ZW/TRi+Vid8k0Q3u3JfhH FQ/FKhMcpH5BnKFwI5qKpHX8pRFt70OhjReNlYlysK09dNyeUoUIWhWb/CN4nCISiPyK m9ZCNEsDxkjZcu/6220lb1fYmYFdb6yKc7Bzn24PUYjrgLoi+cZjBoRu2URGiYhdIb1H 0tqpRIRFYoIbHjUt0W5R/Wl1wAX5oK75OpE9DixRxltXTCVkd/WzbioLDK2i+j403EGL ChZg== 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=HObluCioIghhWS08ajLUNwADuIdpVouuMyqbQ/ZKngg=; b=heQ5ozDXqxO/SMMsleQ3GRg2kxPW1RY6+yJqIziobLjBAjoyaV/36J6Z3DV5zUkNUl BWZJZnRmyiRKmBvR3OkujKH0ILV9yatugf4fuUsXSmWe1y1FHVE0mfpvyE+cbG8EBfS1 fxQA2/N41iW0LDpanE3+ms3umjDcdQisqfJyY8sMQ7e6AQu+UKHHSJ1mgCMoTZDzPgPp HwzIS7OI1uTeh9qsFrYAnioqkEpIivV49e78pDLRgIMm2IjTu1kg9GjzsKcZ3A+6Jmwr c/EgEwNVkMfq6m6How3E4UC5a58vwYwNMLr3Uycte+5rZSb7GGBiGRojtICD4HK3Uo3w 0Qng== X-Gm-Message-State: AOAM533Vsp4u1i+DXw2oZ4ukWaPQKnmDBPyiKPJyJg6kNu/qY8Wfdj/c l9Wq/u2gyE9cfzFcbwia6o99cxcjKxBewA== X-Google-Smtp-Source: ABdhPJz4cydt59YkXInrguTQFZG07/gvKXKU+wG5vg8IyUi3Aoz5shk0sYN6dosn2ZUvaMneINrgCw== X-Received: by 2002:a05:600c:3b8d:: with SMTP id n13mr3104002wms.69.1628159857800; Thu, 05 Aug 2021 03:37:37 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id e6sm5106152wme.6.2021.08.05.03.37.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Aug 2021 03:37:37 -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 v3 7/9] test-lib tests: avoid subshell for "test_cmp" for readability Date: Thu, 5 Aug 2021 12:37:26 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.rc0.635.g0ab9d6d3b5a 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 6857afdaa5..529f3a4d08 100644 --- a/t/lib-subtest.sh +++ b/t/lib-subtest.sh @@ -111,22 +111,16 @@ 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 Thu Aug 5 10:37:27 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: 12420799 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 73367C4338F for ; Thu, 5 Aug 2021 10:37:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 59AFF60F02 for ; Thu, 5 Aug 2021 10:37:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240540AbhHEKiE (ORCPT ); Thu, 5 Aug 2021 06:38:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45186 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240497AbhHEKhz (ORCPT ); Thu, 5 Aug 2021 06:37:55 -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 18F08C061799 for ; Thu, 5 Aug 2021 03:37:40 -0700 (PDT) Received: by mail-wm1-x32a.google.com with SMTP id m19so3056387wms.0 for ; Thu, 05 Aug 2021 03:37:40 -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=GDSs9BlWCzFZ0RpOvDk9UWgqFVpD7P+2gAqvWk65xp0=; b=Nzf07hou8Z26izP7vENaFwUP1Ne9nb7YKUTMqESIeBDabXoNQdfJEzstkIECnqd/hu xbVesX/WQT+YCpz/LtO7GPchMXubDIxUvemh2PKs2m4ltjjrVPS0zIeT1oYmajkMhASX 3oWTbP5c/fVS77ws0BepHZIeCh0UBV8jMCdSUpWqws6Yxeqi52xCQsYbuytX4vr7ifeO 2old/YDy0/IAs0YQdbJcXt0NRzNpAAGJ+fUo7BHbwtnbgnTuRhycELx4c6nxEF5+sCWN NlGKfI8l68bnzbjdNbG124JK597outMVawl1hT9xA4keHgI/x4dEU6JdQqZJkcTCLFIa bpSQ== 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=GDSs9BlWCzFZ0RpOvDk9UWgqFVpD7P+2gAqvWk65xp0=; b=ilJyFfDEDwQvHD1cSnB2LqzRwFHBO2wtHqI2rNm9prg8oMDtYQpxGA8qOFQ82Y1kJT HuUXcA8oYx0EdCeaE9/Z8wpRtYvK627Z760tMConnjvTP6xDmrBaQSgEITFjdrt4kBNL ca+T6tsifBjaDPWvtNYvh/fLAtpYnVSiXivfSnGjUWhzyJisVqw3GyKp/iUFM99b4q+I J5/uVKt8D5CGGeNCdTTN7+SSm3/mqYian54Em2db8FwswCldpYzBJUL2Z8Kr+E/k4ylw +KL+cdM+TuGy55yt+Kli2eB5U/wW9alaonjkqf5ZTpNKnqMv0vKwmUpE7CR/5/Z4nWyN cQqg== X-Gm-Message-State: AOAM533cXm+pKzSWyowaUoSMCzBwpxav4Sw/qNKmnNeI/Lv+S8jTwa5K TsXl3RJu4JyRi1o2jFbjUH5S164V3uRqaQ== X-Google-Smtp-Source: ABdhPJw04A2d0B7JnU5mLbjsVQ3Ue5xGChdthdDGiCE/TbEKHHBT5Mtre9RxPmBmvIwXkPLhNwoSqQ== X-Received: by 2002:a7b:c083:: with SMTP id r3mr4347596wmh.65.1628159858542; Thu, 05 Aug 2021 03:37:38 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id e6sm5106152wme.6.2021.08.05.03.37.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Aug 2021 03:37:38 -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 v3 8/9] test-lib tests: refactor common part of check_sub_test_lib_test*() Date: Thu, 5 Aug 2021 12:37:27 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.rc0.635.g0ab9d6d3b5a 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 529f3a4d08..0b9ecdb6db 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 Thu Aug 5 10:37:28 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: 12420801 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 2F5BBC432BE for ; Thu, 5 Aug 2021 10:37:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1397D6105A for ; Thu, 5 Aug 2021 10:37:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240508AbhHEKiF (ORCPT ); Thu, 5 Aug 2021 06:38:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45178 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240499AbhHEKh4 (ORCPT ); Thu, 5 Aug 2021 06:37:56 -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 DFA8BC061765 for ; Thu, 5 Aug 2021 03:37:40 -0700 (PDT) Received: by mail-wm1-x336.google.com with SMTP id e25-20020a05600c4b99b0290253418ba0fbso3349716wmp.1 for ; Thu, 05 Aug 2021 03:37:40 -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=BQHV0IFhtdQgvc85qfOX4IyivFVjIQQqVEkMNXgFZuA=; b=ULwppCl09mwfLXccD54xgcMp2qhWgR8Qot8yF5gSrAppFqgtj7iI2lad29sgvE3iAU JT39FW3dT8uAPctDg/4Rp7R9Je5qNLn/IUaIeXMvZY2qICzxD6IXoCijb41xtnI9FaVR pz4mpaozIo/uEVYxoipJI+Q9pr5TAHSa6MHfpNI6jKiba4BNKn85eiE4zGpcrKU+q3NY FqKENbShiW5Ki/E+KwAXFTaLqvzreqxno80rfHNW/Hq3F4Dh8QRZNeYbeeHcZr4oM0uC xfjDNmaA3og+DC5UQXzeb39U+tufbycafMqblt83GQUZC9IMFqCtgpe4YGMmhXYuaPiV Uk7A== 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=BQHV0IFhtdQgvc85qfOX4IyivFVjIQQqVEkMNXgFZuA=; b=OwDthkYkF/GXTvusSSeN6aqwBchL2je3h6L8NYLp9OJFOH79Odnqz2S8O4dddmnibt DVU1RJbHUsvhFOA14IC3br0//gAdaLygGtpGszFV2pWc+6aks/lAgabpNazGs3SpR3zs wK2ednaXeP7gjSPbiBluuOrk0Zzx3y6QuPprWyUiMdpFIc0oo/OULQiBae6cMCEWB0Px Efcp7DVfE+ompK8UPAc9F4Njjv5zzw0xRbugsJJzJ+xDJXf1OuV/C4hP1oEWKCBguI1m g43So6uPnNeJflsIPuKVtKXv6ya2vpCXYoVFK+i1zECCxGFYbC/m8sqWvUGCwmQzudjX spDw== X-Gm-Message-State: AOAM532m0fIBn75adgVMTpuDmC+M60D5VBs4kd4aFWB7if5+CdLuhHYD IjGvU6tP3iR1PWdFiXvJotPbeERHx0ykEw== X-Google-Smtp-Source: ABdhPJyPVBQSwrH5N2eKWD9PSVOqfxiO3mqCfmoYr+cax3mYPX94ZxUSVP3xcTC4INaiePPyvRafwQ== X-Received: by 2002:a05:600c:5108:: with SMTP id o8mr4246248wms.97.1628159859312; Thu, 05 Aug 2021 03:37:39 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id e6sm5106152wme.6.2021.08.05.03.37.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Aug 2021 03:37:38 -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 v3 9/9] test-lib tests: assert 1 exit code, not non-zero Date: Thu, 5 Aug 2021 12:37:28 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.rc0.635.g0ab9d6d3b5a 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 0b9ecdb6db..d6b625d397 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 () {