From patchwork Mon Jun 14 10:48:07 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: 12318611 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 8C17AC2B9F4 for ; Mon, 14 Jun 2021 10:54:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 773B4619A5 for ; Mon, 14 Jun 2021 10:54:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233396AbhFNK4I (ORCPT ); Mon, 14 Jun 2021 06:56:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35536 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234654AbhFNKyC (ORCPT ); Mon, 14 Jun 2021 06:54:02 -0400 Received: from mail-wm1-x32f.google.com (mail-wm1-x32f.google.com [IPv6:2a00:1450:4864:20::32f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D1CBCC061198 for ; Mon, 14 Jun 2021 03:48:21 -0700 (PDT) Received: by mail-wm1-x32f.google.com with SMTP id l18-20020a1ced120000b029014c1adff1edso12702961wmh.4 for ; Mon, 14 Jun 2021 03:48:21 -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=KckFsgAJ784WiKcsCjXvcbeAZh2NWCdyNvrwqK6wpd8=; b=MFnBn6ZUNego8SlE21XqKLKgrrGdmC1UsG+0bK8O8SiFYyhN/pbsurH2LsW3Z8+odS cu9IA+vLGjANlsRm+IxPum4SOU/S1gsu99x9Z42DSUAhU26Agf7/ErwjXKEw7mUi7nmE fklIw9K8riC3LZSzBvJ50FOsF8kc/RQYnzOZDOsEGLFcUqMuYdym9sT2aRPJUpmura3k eoF6rYiHc5c0qcA5queKwbTXeWquh1j8TfUHwC5JDNckDvaerfZttX96spWHb2LH5VPa LLBYCIXLFdk6pUb0mmMRnhMtfz563M+3UCLmFPsAsmo/dSCZBDUhiJs/Nl0kC146gKca q4Pg== 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=KckFsgAJ784WiKcsCjXvcbeAZh2NWCdyNvrwqK6wpd8=; b=tUKVmoEAZxntgyzcvqTCsOV9D4cUI539CObGqKWP65DGKWeE7DvSc7MI7t1MnK8V95 tMhXqd/8JmsVahbhRpQzIh72bHnPUYb7ewNgKP6q8WUQ83NtWgI1w6Lvi/ktt71Avly7 6uieSWetp547BLDgfTwWSOSEQ9NJI46lcacq7lhN/Tt/W3Rv6C6mp5xjv4CBZ8Jb3aCm JMIDHhEwXYLwAAYWgX40Pwn7Rh+XBDb6+pCO+YDhga99uNwuvdIrxALdKe1kiufYMVsZ RNYniTd/8JILDGKJcoZM7OcnvDlscDY3MwBH9u03Hmw84A8JVBKq9gSd8uKmWkKLJU2X hEww== X-Gm-Message-State: AOAM530+gByF96G8JAjXGmIAc9HEyWSF5fFBbIzda8yJG9oywtyFFSA6 XsGNSrxm0Finuwio4poqAc8K7MhMDvT25Q== X-Google-Smtp-Source: ABdhPJz97Bg8XikE/dAaAaMxjMKLdOIvJj8OLVYnsI9/Gl3qZSRNoZGPFVErv4lwoPUuEtrv/pVXwg== X-Received: by 2002:a05:600c:2dcf:: with SMTP id e15mr32170354wmh.117.1623667700268; Mon, 14 Jun 2021 03:48:20 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id m23sm15153732wms.2.2021.06.14.03.48.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Jun 2021 03:48:19 -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 , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFy?= =?utf-8?b?bWFzb24=?= Subject: [PATCH 1/8] test-lib tests: move "run_sub_test" to a new lib-subtest.sh Date: Mon, 14 Jun 2021 12:48:07 +0200 Message-Id: X-Mailer: git-send-email 2.32.0.rc3.434.gd8aed1f08a7 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 | 64 ++++++++++++++++++++++++++++++++++++++++++++++ t/t0000-basic.sh | 66 +----------------------------------------------- 2 files changed, 65 insertions(+), 65 deletions(-) create mode 100644 t/lib-subtest.sh diff --git a/t/lib-subtest.sh b/t/lib-subtest.sh new file mode 100644 index 00000000000..0c613e00da3 --- /dev/null +++ b/t/lib-subtest.sh @@ -0,0 +1,64 @@ +_run_sub_test_lib_test_common () { + neg="$1" name="$2" descr="$3" # stdin is the body of the test code + shift 3 + 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 && + TEST_OUTPUT_DIRECTORY=$(pwd) && + export TEST_OUTPUT_DIRECTORY && + 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 2c6e34b9478..72809477645 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,71 +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 - 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 && - TEST_OUTPUT_DIRECTORY=$(pwd) && - export TEST_OUTPUT_DIRECTORY && - 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 Mon Jun 14 10:48:08 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: 12318619 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 C45E9C2B9F4 for ; Mon, 14 Jun 2021 10:55:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id AC83561483 for ; Mon, 14 Jun 2021 10:55:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234109AbhFNK5v (ORCPT ); Mon, 14 Jun 2021 06:57:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35544 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234657AbhFNKyD (ORCPT ); Mon, 14 Jun 2021 06:54:03 -0400 Received: from mail-wr1-x432.google.com (mail-wr1-x432.google.com [IPv6:2a00:1450:4864:20::432]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AEB77C0611BC for ; Mon, 14 Jun 2021 03:48:23 -0700 (PDT) Received: by mail-wr1-x432.google.com with SMTP id y7so14018912wrh.7 for ; Mon, 14 Jun 2021 03:48:23 -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=vaqN14/dIx+z+r/B3AUyC/dZScH5hKlO1jayX68baxM=; b=t9O0E1Hz57quVB4JFV8cVl9zhhfNlmU4zCS5eXnIV/ysIKezctYQgIiyMhwTNOcsD6 oCRcAtdJsPWLs7ObsmDvk7XKRihQIZ3NFM6wE3aw8l4kbZaTntPlIcI1sCjje3Qywzlv ZQ7Xka7RDueIrfQSayhpBOrpfAH7Xu8fwSN5ipLTkV4wM3kxx7YsNPSg6M5LNbokUaeH 3dhoFG+13APA/8i05/aazAffyNQs3mIAEgSo8BLyjdsyrf6bWzidhQj1bIHztR6lfZjE gqNJK3F6IFYZV1yeYvRbSpISC5zLGwJv5h2cEJov9Yt17BN78XbPFI2zabdHmw+XG75s I0aw== 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=vaqN14/dIx+z+r/B3AUyC/dZScH5hKlO1jayX68baxM=; b=cmh7ym1gFvS6fnfD6QW2tzl0ZOaUFG6nkb86f+TqjIdjsGmkYiEICYuQ2XGLM6dXbc sBlGYgdhncB8m/Enrh+HT+dzE19ug7iOzmAz3YqiJJSDDWw8Wy8qfzkELsbdZJhX/HA7 zomVcjfuKilAyO6IDyrFzVf6jlXsy1o26hp4BRIndycC5TQDtY8wZZPpJztCh6ryHwy+ txo6G8ZzWNlhUcywBAYANcCkltQ9WUnYBAFQnDt6+/jepF9fS8MxIPf1si2GV2XEOfNU ozajewmNWp4vSHYgKlUgIyFnD6jcBBbdLW5zSYw2rDXrjCZZVnxKcpZfA8XeA9OK5oVq Xqzw== X-Gm-Message-State: AOAM5330FAUAJQU3QIjJ3GEIBSOUhT+IHYLe3kEXiaHvtnnt/ox96HFb obEPaIWGCr1e0TxgmuuvGlGrg8KfGYXf3A== X-Google-Smtp-Source: ABdhPJyvDy6c9biVRGC+DJMmto+I2LORc1Sxe9fDPq0RMKOONSDfeO5LsY+ksv8ORBKM7Ln3jHstEQ== X-Received: by 2002:adf:f90e:: with SMTP id b14mr18433923wrr.248.1623667701146; Mon, 14 Jun 2021 03:48:21 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id m23sm15153732wms.2.2021.06.14.03.48.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Jun 2021 03:48:20 -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 , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFy?= =?utf-8?b?bWFzb24=?= Subject: [PATCH 2/8] test-lib tests: split up "write and run" into two functions Date: Mon, 14 Jun 2021 12:48:08 +0200 Message-Id: X-Mailer: git-send-email 2.32.0.rc3.434.gd8aed1f08a7 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 | 39 +++++++++++++++++++------ t/t0000-basic.sh | 74 ++++++++++++++++++++++++------------------------ 2 files changed, 67 insertions(+), 46 deletions(-) diff --git a/t/lib-subtest.sh b/t/lib-subtest.sh index 0c613e00da3..0ece41c0e5f 100644 --- a/t/lib-subtest.sh +++ b/t/lib-subtest.sh @@ -1,13 +1,7 @@ -_run_sub_test_lib_test_common () { - neg="$1" name="$2" descr="$3" # stdin is the body of the test code - shift 3 +write_sub_test_lib_test () { + name="$1" descr="$2" # stdin is the body of the test code 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) @@ -19,7 +13,22 @@ _run_sub_test_lib_test_common () { # Point to the t/test-lib.sh, which isn't in ../ as usual . "\$TEST_DIRECTORY"/test-lib.sh EOF - cat >>"$name.sh" && + 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 + ( + 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 && + export TEST_DIRECTORY && TEST_OUTPUT_DIRECTORY=$(pwd) && export TEST_OUTPUT_DIRECTORY && @@ -33,6 +42,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 72809477645..7f6714a5fc5 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 @@ -256,7 +256,7 @@ test_expect_success 'test --verbose-only' ' test_expect_success 'GIT_SKIP_TESTS' ' ( GIT_SKIP_TESTS="git.2" && export 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" <<-\EOF && for i in 1 2 3 do @@ -277,7 +277,7 @@ test_expect_success 'GIT_SKIP_TESTS' ' test_expect_success 'GIT_SKIP_TESTS several tests' ' ( GIT_SKIP_TESTS="git.2 git.5" && export GIT_SKIP_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" <<-\EOF && for i in 1 2 3 4 5 6 do @@ -301,7 +301,7 @@ test_expect_success 'GIT_SKIP_TESTS several tests' ' test_expect_success 'GIT_SKIP_TESTS sh pattern' ' ( GIT_SKIP_TESTS="git.[2-5]" && export GIT_SKIP_TESTS && - 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" <<-\EOF && for i in 1 2 3 4 5 6 do @@ -325,7 +325,7 @@ test_expect_success 'GIT_SKIP_TESTS sh pattern' ' test_expect_success 'GIT_SKIP_TESTS entire suite' ' ( GIT_SKIP_TESTS="git" && export GIT_SKIP_TESTS && - 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" <<-\EOF && for i in 1 2 3 do @@ -342,7 +342,7 @@ test_expect_success 'GIT_SKIP_TESTS entire suite' ' test_expect_success 'GIT_SKIP_TESTS does not skip unmatched suite' ' ( GIT_SKIP_TESTS="notgit" && export GIT_SKIP_TESTS && - 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" <<-\EOF && for i in 1 2 3 do @@ -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 Mon Jun 14 10:48:09 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: 12318613 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 35FE9C4743C for ; Mon, 14 Jun 2021 10:55:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 22414614A7 for ; Mon, 14 Jun 2021 10:55:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234520AbhFNK5b (ORCPT ); Mon, 14 Jun 2021 06:57:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35542 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234732AbhFNKyR (ORCPT ); Mon, 14 Jun 2021 06:54:17 -0400 Received: from mail-wm1-x32b.google.com (mail-wm1-x32b.google.com [IPv6:2a00:1450:4864:20::32b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 896DFC0611BD for ; Mon, 14 Jun 2021 03:48:23 -0700 (PDT) Received: by mail-wm1-x32b.google.com with SMTP id s70-20020a1ca9490000b02901a589651424so9140459wme.0 for ; Mon, 14 Jun 2021 03:48:23 -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=ANLM2U1RrQ+E65WNgvnj4IGfQkSMGs1u66iP9WTO9YA=; b=ntrk+K82+3W6hHW5zQ4SnB8L27s1hKS/9VNZVQSXeMJqB8Aopo8HpttN1sTirpkhCC lQH322tIqEFx/ET3KkaPHfz6CBaxRphU9TRb26Ltwy5choSmiBBWCdBTvgCb+HuwbDc+ +fGWijN+moW8qAfYIPgqA+w2oyfMW43sIPjWBRWRlLCl/of5DmkVSZL3kyJ47IcriLNt el9dMeoXuU6LgLN000zk+eYDXK1NsqVWn6YaklYYg4O9A8+tmkQpgzio76FmdD4readY Zc3n0zMNjz3tjotl9cEIU7ZrgA5OkN/aOF1P3lpGnw+dLA2VAU0otBJQ16Og6ZQvsCx4 cULA== 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=ANLM2U1RrQ+E65WNgvnj4IGfQkSMGs1u66iP9WTO9YA=; b=SLaDkN0skoP+Kz3p+VknJ1wCw2d/Qq/M55funTlKUEIG+mrITOJPOJZmjeZ4QQtgJs YvP44rW4WHghGJaBqaa/yy9OuQWRzvid0hhs9JSLdC7ONhilSJa7cXeZJB6x2Jr5BAiB j9eUjnsC556oqq5WOGpE6oHybHmxn2VruAIjp9VXHpPTWOxHvmYCQnKopHnRdVX1veao eEm8uMs0ee+SFYrcA3alzDN6bjdtEpbVKZugisZPggxUxNKsBVWwFIYVpqAoIGQpocX1 FZid5l4gS71vB6lLMnBLZ1WXKW7EpexXwUojxl3XQtc8k0ZBksBB2EaBSR2rgL1jFZbv Pmng== X-Gm-Message-State: AOAM532AD53n8rvL27cM/dPl0vq81ia2c3SrscTFOC7fffizMe6BPqcJ 25llTYBZs58ePpVo0JI8xtwU/ITMKKcqMw== X-Google-Smtp-Source: ABdhPJyiF4k4PXeS2jTaRFWjO8rkRzvJ3zYNHvCLEcjHyVGicHP4ylS4ovJ2M0T4tAABCWv/Umw4rA== X-Received: by 2002:a05:600c:2103:: with SMTP id u3mr16097985wml.0.1623667701913; Mon, 14 Jun 2021 03:48:21 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id m23sm15153732wms.2.2021.06.14.03.48.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Jun 2021 03:48:21 -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 , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFy?= =?utf-8?b?bWFzb24=?= Subject: [PATCH 3/8] test-lib tests: stop using a subshell in write_sub_test_lib_test() Date: Mon, 14 Jun 2021 12:48:09 +0200 Message-Id: X-Mailer: git-send-email 2.32.0.rc3.434.gd8aed1f08a7 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 0ece41c0e5f..465f8f373e9 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 Mon Jun 14 10:48:10 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: 12318601 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 B4673C2B9F4 for ; Mon, 14 Jun 2021 10:51:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9654361984 for ; Mon, 14 Jun 2021 10:51:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234441AbhFNKxm (ORCPT ); Mon, 14 Jun 2021 06:53:42 -0400 Received: from mail-wr1-f44.google.com ([209.85.221.44]:37707 "EHLO mail-wr1-f44.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234437AbhFNKvj (ORCPT ); Mon, 14 Jun 2021 06:51:39 -0400 Received: by mail-wr1-f44.google.com with SMTP id i94so13994194wri.4 for ; Mon, 14 Jun 2021 03:49:23 -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=ccH+UBBs/WOCDSFkHZ0Qq+wnWbKlcJSWzwl169Tzlv8=; b=Ix0NuIjAViQZD/MhHIx0RlgVLVgyzeDDyVXXAx5bMu4s0s3iGTPE7E+Vc3g0RMPQQK NFMFs1h4r0SXQmM4qoGMiCxyv2IN8Fkjk4JkoniJKbxaZcJdwR+st+Fy+PgIEOfLAl8O h8bRFh1EshCxRqCzrgkMI1xcRDgBJ7eb+n3ahFmG/Cq7exdvk8fo5l4b3XxLMXmVAdSN HEZLPNcqL1az0PuoZYjSL6MGJQcyf3aLkESsSGjgVc3GuaSO0ZnQgY3MHq7zYh/T4Tf2 JYDjJGOolU/0Dn1SfwQ1r8EIe9Hnj4yEkkdPxnNoqSSJXo47g40Iyinefa/C67DuzH+I KSGw== 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=ccH+UBBs/WOCDSFkHZ0Qq+wnWbKlcJSWzwl169Tzlv8=; b=qjOIYE8O2al/MH4hR/fNij3TpZAhfy85EhU1rwa3Ah7PtIr5UP7jCfhI3IETixR95A ygsngw8ia1qLN8b7/BtKtqGgUjtZKW7LlTQE41GIdT98fBuNYM9ag0NV1SgMoCZDngN1 AV+bnMyoi29IgAyaKKLvqNK5K4Xgkd0VHu0MiCRc+Fi4z+ld+ZB5zD+po0GO4RsVkjFZ WkekBIZMGXqZLloxbxPCII7rkQyK/TzfEYE7r8saASOaMZpxNp7qZtlUhB1sf6jlMfkx +T+LbBFiD7NNXmZPxSLNEmW6d3aPir5hyeEOjZ6RoHYVZAnVn2LzUwGMR669C4KRIDeT QC5g== X-Gm-Message-State: AOAM530IZqORPI4pyDH5zLmjk2bk2v3oUv7aZ6syRCRQXIbx03UnqrEQ aWso1wcTfxNVSdick710lEtCgmfCkIWojw== X-Google-Smtp-Source: ABdhPJyAAwPU9xKHefJXKL/a+J2jIfgXyMclPwcaAudTvbBhShtlOHdnVWZyjI7IIDunYKTl7XKpiQ== X-Received: by 2002:a5d:5084:: with SMTP id a4mr18381866wrt.286.1623667702775; Mon, 14 Jun 2021 03:48:22 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id m23sm15153732wms.2.2021.06.14.03.48.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Jun 2021 03:48:22 -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 , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFy?= =?utf-8?b?bWFzb24=?= Subject: [PATCH 4/8] test-lib tests: don't provide a description for the sub-tests Date: Mon, 14 Jun 2021 12:48:10 +0200 Message-Id: X-Mailer: git-send-email 2.32.0.rc3.434.gd8aed1f08a7 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 | 147 +++++++++++++++++++++-------------------------- 2 files changed, 71 insertions(+), 88 deletions(-) diff --git a/t/lib-subtest.sh b/t/lib-subtest.sh index 465f8f373e9..4a50e380506 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 ( cd "$name" && diff --git a/t/t0000-basic.sh b/t/t0000-basic.sh index 7f6714a5fc5..b93a8ced7f6 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,11 +248,11 @@ test_expect_success 'test --verbose-only' ' EOF ' -test_expect_success 'GIT_SKIP_TESTS' ' +test_expect_success 'subtest: skip one with GIT_SKIP_TESTS' ' ( GIT_SKIP_TESTS="git.2" && export GIT_SKIP_TESTS && write_and_run_sub_test_lib_test git-skip-tests-basic \ - "GIT_SKIP_TESTS" <<-\EOF && + <<-\EOF && for i in 1 2 3 do test_expect_success "passing test #$i" "true" @@ -274,11 +269,11 @@ test_expect_success 'GIT_SKIP_TESTS' ' ) ' -test_expect_success 'GIT_SKIP_TESTS several tests' ' +test_expect_success 'subtest: skip several with GIT_SKIP_TESTS' ' ( GIT_SKIP_TESTS="git.2 git.5" && export GIT_SKIP_TESTS && write_and_run_sub_test_lib_test git-skip-tests-several \ - "GIT_SKIP_TESTS several tests" <<-\EOF && + <<-\EOF && for i in 1 2 3 4 5 6 do test_expect_success "passing test #$i" "true" @@ -298,11 +293,11 @@ 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' ' ( GIT_SKIP_TESTS="git.[2-5]" && export GIT_SKIP_TESTS && write_and_run_sub_test_lib_test git-skip-tests-sh-pattern \ - "GIT_SKIP_TESTS sh pattern" <<-\EOF && + <<-\EOF && for i in 1 2 3 4 5 6 do test_expect_success "passing test #$i" "true" @@ -322,11 +317,11 @@ 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' ' ( GIT_SKIP_TESTS="git" && export GIT_SKIP_TESTS && write_and_run_sub_test_lib_test git-skip-tests-entire-suite \ - "GIT_SKIP_TESTS entire suite" <<-\EOF && + <<-\EOF && for i in 1 2 3 do test_expect_success "passing test #$i" "true" @@ -339,11 +334,11 @@ 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' ' ( GIT_SKIP_TESTS="notgit" && export GIT_SKIP_TESTS && write_and_run_sub_test_lib_test git-skip-tests-unmatched-suite \ - "GIT_SKIP_TESTS does not skip unmatched suite" <<-\EOF && + <<-\EOF && for i in 1 2 3 do test_expect_success "passing test #$i" "true" @@ -360,9 +355,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 +375,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 +396,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 +417,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 +438,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 +459,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 +480,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 +501,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 +522,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 +543,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 +564,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 +585,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 +606,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 +627,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 +650,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 +664,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 +678,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 +708,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 +732,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 +758,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 +771,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 +791,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 +820,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 Mon Jun 14 10:48:11 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: 12318597 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 3F6CAC2B9F4 for ; Mon, 14 Jun 2021 10:51:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 20B1361987 for ; Mon, 14 Jun 2021 10:51:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234599AbhFNKx3 (ORCPT ); Mon, 14 Jun 2021 06:53:29 -0400 Received: from mail-wm1-f45.google.com ([209.85.128.45]:43930 "EHLO mail-wm1-f45.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234237AbhFNKv1 (ORCPT ); Mon, 14 Jun 2021 06:51:27 -0400 Received: by mail-wm1-f45.google.com with SMTP id 3-20020a05600c0243b029019f2f9b2b8aso12508776wmj.2 for ; Mon, 14 Jun 2021 03:49:24 -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=2hfFWnrIrrbnye23rfpaXd/uXBw/QoB2rASfcepf894=; b=XdzjTRUweb53zL9gjQ5znkKA29am6yZPjhqBaODTp4Vy358G6syLQGc4dxlMqFqwqc zuklMYosmATQrrg2sQdRZnVEFIknzrGp1iu8rrFYrMqFL5X9WgKtxCvNXt8eFAnEURRd 0QcXRwawQ2zWutIkpooMj+lFsAIdENzA4EOYvnYEmlYKjvYJsIhyoeaDd0f4KQmWag6h 9Pv3nO/6QdbURQ1+vW+J4Cu5lkkBm7zdfzLLFGJEzwNHd4xay6eiKEApmSbWvH8br6dH SGPaMF0Q6BaTGwgkQesKOhDIcs48X32GkD4IfxeMFZVUDA59WcoWLV5AV53I4ziFviw5 fWtQ== 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=2hfFWnrIrrbnye23rfpaXd/uXBw/QoB2rASfcepf894=; b=chS8Xj0m1yHoazEt9WQ0VTgMaVFBnA8NWWtEUJksip1jzD67WZvOeAUsZ49f5iSLxQ kONxpFi8/6YBGmu6JbIzZlbnZkvgzlBqQx0EXKmzUTcbs9F14kwVt7EcWGJTBiysZiPi rYPJ9X3G0+FvTtrsBj0s/hm0Pyp2f6hnI6xFqr84hzaorLhDTykfKPVTlNUd1jMgs5sp G2xuJeygHW5ajqx7oGKeYs8wiIOm1KLHCnvjaaiNpJvXsozSx5dYY3YiYO6GwNZ/4DmI u1fFdSxBsBUhGzCDRa7VkCQpW4n3CnTVhlyCEv+IQHwDFtre6g9ZnlCMq3DnSO06GcQB IdJw== X-Gm-Message-State: AOAM533gRXwUetfI17thUg7m6/0d2s1blM9ajeneTM0YL1YTbPWllogR ZoD2zL8Tp81aP6qRtg8Pi6h7GH/7LlkDSw== X-Google-Smtp-Source: ABdhPJyLmMhODkmNZSvRu8ifGv1uQP+pqSOrKuh/vUIv98zuOGIjoZT/AghSWRwK4dQRw21/4M+91A== X-Received: by 2002:a1c:a382:: with SMTP id m124mr15406299wme.40.1623667703691; Mon, 14 Jun 2021 03:48:23 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id m23sm15153732wms.2.2021.06.14.03.48.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Jun 2021 03:48:23 -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 , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFy?= =?utf-8?b?bWFzb24=?= Subject: [PATCH 5/8] test-lib tests: get rid of copy/pasted mock test code Date: Mon, 14 Jun 2021 12:48:11 +0200 Message-Id: X-Mailer: git-send-email 2.32.0.rc3.434.gd8aed1f08a7 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Now that we've split up the write_sub_test_lib_test*() and run_sub_test_lib_test*() functions let's fix those tests in t0000-basic.sh that were verbosely copy/pasting earlier tests. I'm (ab)using writing a tag object under a ref-name that's content-addressable from the content of the test script. If we can update-ref that it's unique, if not we've got a duplicate. The tag object stores the name of the earlier test for reporting the error. Signed-off-by: Ævar Arnfjörð Bjarmason --- t/lib-subtest.sh | 34 ++++++- t/t0000-basic.sh | 224 ++++++++++++----------------------------------- 2 files changed, 88 insertions(+), 170 deletions(-) diff --git a/t/lib-subtest.sh b/t/lib-subtest.sh index 4a50e380506..4834db6c4ca 100644 --- a/t/lib-subtest.sh +++ b/t/lib-subtest.sh @@ -1,3 +1,34 @@ +_assert_unique_sub_test () { + name=$1 && + + # Alert about the copy/paste programming + hash=$(git hash-object -w "$name") && + cat >tag.sig <<-EOF && + object $hash + type blob + tag $hash + tagger . <> 0 +0000 + + duplicate script detected! + + This test script was already written as: + + $name + + You can just re-use its test code with your own + run_sub_test_lib_test*() + EOF + + tag=$(git mktag /dev/null + then + msg=$(git for-each-ref refs/tags/blob-$hash \ + --format='%(contents)' refs/tags/blob-$hash) + error "on write of $name: $msg" + return 1 + fi +} + write_sub_test_lib_test () { name="$1" # stdin is the body of the test code mkdir "$name" && @@ -7,7 +38,8 @@ write_sub_test_lib_test () { # Point to the t/test-lib.sh, which isn't in ../ as usual . "\$TEST_DIRECTORY"/test-lib.sh EOF - cat >>"$name/$name.sh" + cat >>"$name/$name.sh" && + _assert_unique_sub_test "$name/$name.sh" } _run_sub_test_lib_test_common () { diff --git a/t/t0000-basic.sh b/t/t0000-basic.sh index b93a8ced7f6..886329d1f8e 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,16 +245,9 @@ test_expect_success 'subtest: --verbose-only option' ' test_expect_success 'subtest: skip one with GIT_SKIP_TESTS' ' ( - GIT_SKIP_TESTS="git.2" && export GIT_SKIP_TESTS && - write_and_run_sub_test_lib_test git-skip-tests-basic \ - <<-\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 + GIT_SKIP_TESTS="full.2" && export GIT_SKIP_TESTS && + run_sub_test_lib_test full-pass && + 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 @@ -296,15 +284,8 @@ test_expect_success 'subtest: skip several with GIT_SKIP_TESTS' ' test_expect_success 'subtest: sh pattern skipping with GIT_SKIP_TESTS' ' ( GIT_SKIP_TESTS="git.[2-5]" && export GIT_SKIP_TESTS && - write_and_run_sub_test_lib_test git-skip-tests-sh-pattern \ - <<-\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 && + 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) @@ -320,15 +301,8 @@ test_expect_success 'subtest: sh pattern skipping with GIT_SKIP_TESTS' ' test_expect_success 'subtest: skip entire test suite with GIT_SKIP_TESTS' ' ( GIT_SKIP_TESTS="git" && export GIT_SKIP_TESTS && - write_and_run_sub_test_lib_test git-skip-tests-entire-suite \ - <<-\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 + run_sub_test_lib_test git-skip-tests-several && + check_sub_test_lib_test git-skip-tests-several <<-\EOF > 1..0 # SKIP skip all tests in git EOF ) @@ -337,15 +311,8 @@ test_expect_success 'subtest: skip entire test suite with GIT_SKIP_TESTS' ' test_expect_success 'subtest: GIT_SKIP_TESTS does not skip unmatched suite' ' ( GIT_SKIP_TESTS="notgit" && export GIT_SKIP_TESTS && - write_and_run_sub_test_lib_test git-skip-tests-unmatched-suite \ - <<-\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 + run_sub_test_lib_test full-pass && + check_sub_test_lib_test full-pass <<-\EOF > ok 1 - passing test #1 > ok 2 - passing test #2 > ok 3 - passing test #3 @@ -356,14 +323,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 @@ -376,15 +337,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 @@ -397,15 +352,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) @@ -418,15 +367,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 @@ -439,15 +382,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) @@ -460,15 +397,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) @@ -481,15 +412,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) @@ -502,15 +427,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 @@ -523,15 +442,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) @@ -544,15 +457,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) @@ -565,15 +472,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) @@ -586,15 +487,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) @@ -607,15 +502,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 @@ -665,12 +554,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 Mon Jun 14 10:48:12 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: 12318615 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 0C71BC2B9F4 for ; Mon, 14 Jun 2021 10:55:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E44F0613F5 for ; Mon, 14 Jun 2021 10:55:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234323AbhFNK5d (ORCPT ); Mon, 14 Jun 2021 06:57:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35582 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234468AbhFNKyK (ORCPT ); Mon, 14 Jun 2021 06:54:10 -0400 Received: from mail-wr1-x42b.google.com (mail-wr1-x42b.google.com [IPv6:2a00:1450:4864:20::42b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1674AC0619F6 for ; Mon, 14 Jun 2021 03:48:26 -0700 (PDT) Received: by mail-wr1-x42b.google.com with SMTP id c9so14013780wrt.5 for ; Mon, 14 Jun 2021 03:48:25 -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=Tq9OQUaO5L8L+PfdMbxMlXsuFQSlHnVpPqwMUeEPegM=; b=BBQneYHtr+LjXTY4hsmkbCUC+7ptgV1qpwltipR6bJnWAnC7DTl5vQeaxH2LhoT6j9 aQrFVtIceciMgviGRys+B/08YQ6H1tE3z+OVebSTCkkYapqHOrnGdupY6q/pmJQbRFjD nP+/kxpaAOS96HmLHZfNg5758meeQ5WNgy3HxjiPpTUlbEwCDAmyCG3inXoXwizlM8Yt Cv7c97UKRV3mQ+dkGOf4M4QH54XAn4ARmh5kwm5z1bGa74GFxiKBDcyxYik1aFu8AB3y g5VJGrM9DeDaTniqvnodOSpg92IrpRWGtA1uN85vcBJ3nTqgfyfjbEGrRTY9pQbSq2Ts Tv5g== 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=Tq9OQUaO5L8L+PfdMbxMlXsuFQSlHnVpPqwMUeEPegM=; b=hr+in3so+ZLxVyWQAhnJ7HZUdOXCBmGxe0a1cJV5Mirh7mejx13UFBvcKr+CbtZXc1 D4F5jHsl5/nsd50sQQANqKo1HZ8vzKv+rSeyFUbZ9P9gguxfOWn0KYjoWmm7ZWOHyIk/ 1VAEt4NGSGSQ0eqqRs2k0euEe4O8E7F5Rj/ci+ejv6M00FFxpMboB4tpdW+a3ldvFBnu 99r9yWrSn3emIiUklmKqWtPcoW5OoPxqwmQ+HkPJ8f3Hn3T2F0fvutlyN0Dy0xDtdaK3 p87YgVigatjuc0UzC55780ikEctV5QVHbYTz8Mf+GG/vc7Z8Y3iUCyjb7EKW5P9MAEC2 1AWw== X-Gm-Message-State: AOAM533J469JNaDIflGN7luo0IAj+GtR2esAyzXTlLqV0WOTQRyaeTKN Cb39gJAqyemXMVjILVPHxiv4dl2J1H5TdQ== X-Google-Smtp-Source: ABdhPJzj6NW9QRYo90apAx7hLkaRx5oesN3rh2I94cTcFQB82Q6gw8THPF7fksGjMj+87pj2HtZ8eg== X-Received: by 2002:adf:a291:: with SMTP id s17mr17866630wra.399.1623667704446; Mon, 14 Jun 2021 03:48:24 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id m23sm15153732wms.2.2021.06.14.03.48.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Jun 2021 03:48:24 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Jeff King , Felipe Contreras , Adam Spiers , Thomas Rast , Ilya Bobyr , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFy?= =?utf-8?b?bWFzb24=?= Subject: [PATCH 6/8] test-lib tests: avoid subshell for "test_cmp" for readability Date: Mon, 14 Jun 2021 12:48:12 +0200 Message-Id: X-Mailer: git-send-email 2.32.0.rc3.434.gd8aed1f08a7 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 4834db6c4ca..8f4935faf43 100644 --- a/t/lib-subtest.sh +++ b/t/lib-subtest.sh @@ -89,22 +89,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 Mon Jun 14 10:48:13 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: 12318617 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 53319C2B9F4 for ; Mon, 14 Jun 2021 10:55:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3D18961574 for ; Mon, 14 Jun 2021 10:55:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234414AbhFNK5i (ORCPT ); Mon, 14 Jun 2021 06:57:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35580 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234675AbhFNKyK (ORCPT ); Mon, 14 Jun 2021 06:54:10 -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 D081AC0611BE for ; Mon, 14 Jun 2021 03:48:26 -0700 (PDT) Received: by mail-wm1-x336.google.com with SMTP id h22-20020a05600c3516b02901a826f84095so12497959wmq.5 for ; Mon, 14 Jun 2021 03:48:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=7MG4ZQ4gKCciMaU2Ld1S7Jt4tLEBck9dAjSmNV89Poc=; b=gAFQy3UCjnDFlCeO1gr40gdF78Q7rxtu6xK3TUV+14S8URBkVvy/wsXW0Y8ZlhhtYU k+X6CyAtnvnQaaInDV3DosfxV05rjs39Aq9m9Z0aJPUAZ7Stp0xpIBEAkV+b0DuKHBW7 z8VKCO1h1DpSwsLKndeTHErKjI1LOi+sWR25lKTmaGGLDssk7GTRurDclJa2ZpxfBMYM YtIldXNvd+YSz7XpblurBGmE7SMsNe9jWt617wTkmRhN58yP2SKu3W5uOV/uoLX7NGZj nCOL+F0bkkAS9OT/QUDulAgGqj/H8e+YouiorzpHclWoDFSRPhR61uuiDjRijgPv8wSK hkHw== 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=7MG4ZQ4gKCciMaU2Ld1S7Jt4tLEBck9dAjSmNV89Poc=; b=qfDXMR/tKSpHSOCNT3+cxfzHlzUU3o/xbgq5LzCfwBl1IeYhUvt/s2dmfXCVTAz885 FOrSqES7N5CUVlTX7r51AyxekamoDA1CqEm8ikEDyib5YoUSw+EP0lNQP8JeO1RceKbS ukDLifBnlGJhBHbD/Zd2YP/uePVl3OSG3k7/Kia8yohr14T0xBaS6MMIB2UPmCdYOC61 4pq6kCda+MwXmms3SydcPliIVTdG5N7N2xUnZYyFxspG0JOA7vV9JdyyYlxOYIcbF5vc ktbfEQ1xi0sRx/4404leqUkdWrTykhyvDukdicGPWiMcJkH58MWPXSpklg3PX0DL/Yo2 n5dA== X-Gm-Message-State: AOAM5330zZqOGMT2MicjbMGqv2VD4anktHq75y3XQEmhFxO//tMAGD2v mnlbZlURYVimWIubVYogpbWRUL6h39Y07g== X-Google-Smtp-Source: ABdhPJxCwv8j1W9HuCQNIq1lDbhJAEaUAH4wX1xMGwOXHiQv8Ik/TQaPl8+G+oxl8+54hsEMgNmoBA== X-Received: by 2002:a1c:ed14:: with SMTP id l20mr31453705wmh.20.1623667705257; Mon, 14 Jun 2021 03:48:25 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id m23sm15153732wms.2.2021.06.14.03.48.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Jun 2021 03:48:24 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Jeff King , Felipe Contreras , Adam Spiers , Thomas Rast , Ilya Bobyr , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFy?= =?utf-8?b?bWFzb24=?= Subject: [PATCH 7/8] test-lib tests: refactor common part of check_sub_test_lib_test*() Date: Mon, 14 Jun 2021 12:48:13 +0200 Message-Id: X-Mailer: git-send-email 2.32.0.rc3.434.gd8aed1f08a7 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 8f4935faf43..02864c9d0e0 100644 --- a/t/lib-subtest.sh +++ b/t/lib-subtest.sh @@ -87,18 +87,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 Mon Jun 14 10:48:14 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: 12318599 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 3E3E2C2B9F4 for ; Mon, 14 Jun 2021 10:51:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2ABA16146E for ; Mon, 14 Jun 2021 10:51:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232797AbhFNKxa (ORCPT ); Mon, 14 Jun 2021 06:53:30 -0400 Received: from mail-wr1-f52.google.com ([209.85.221.52]:35645 "EHLO mail-wr1-f52.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233635AbhFNKv3 (ORCPT ); Mon, 14 Jun 2021 06:51:29 -0400 Received: by mail-wr1-f52.google.com with SMTP id m18so14030167wrv.2 for ; Mon, 14 Jun 2021 03:49:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=BS0ULjgZdgeRfiDjOjmJCMuxP6qf3m+5a2iu1mhKxrY=; b=JvfqZ2D8dte/gPuJP8836Ijckiu0XkAr/p9lFF/gljfctOXz/14641W+9Lgd22vFSe UV8RrVT02QNx5Twspeh+jDh7by6s52maP1pihyCCAZFusPBF0oItTzZyz8VMa5gmBES/ De4U1/Ui3VhrBuT8ITYT7FbjcZKY0rkYD/331w2aQAlTHMuLjoDsrSiSMt+dbZPa9tI5 Cnb9Iojk6uNEOWbkdvlNmNWKLC/kg/VKJ1KsL/3w1U9k6dDzv9XvvPc37BRyaejqNSFk b3uk6xMxNpHSDX6q73cpuaJwLxw36Enxyha7B6AFpim9N8FFleWDWhg434h8GnaTRlM0 H4Pg== 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=BS0ULjgZdgeRfiDjOjmJCMuxP6qf3m+5a2iu1mhKxrY=; b=BRIbK9dD3GDp2VGZxOd40bT1m7/816TFDxUmDZzTr8fKkGMS73/xiHPti3RTw2+Vl3 sogogr4oAC8g8xUdEpJyjZ5C0XBro8hAazBWwlEb8+UBt0hgV91lxHuZwxQqnnVXbJcF Mln/mBY5pUDlQxZdJbdeMbQ0b1ws3Rgf9YB/N3TE7WzPC0DzHnHHgqstQpie0I+YFjp8 tfa+VoouRVX53u3+m3/7xjYU4drBZtPvicQYCfJWtNfM6nwI2+CYQcQ15BmRzh9I2y69 +VoDZPt4Y8Kfs3uxzbQXRDbaNVhqa5KPvMYfsKNC4NBs6Zi31+kzyMWVga9yAHlxw+jd MX9w== X-Gm-Message-State: AOAM531PGAoIM1tUcSsdi49r9clJVCACG935h8rPCMP996kcbWDeMOLz JffCWJDbD6OjdidmVebW0ksYrPnNG7Y7fQ== X-Google-Smtp-Source: ABdhPJy5+2Cz6xfbXDeuTgIE/s6uHtN/MfnyNGcYTNwzUn7Ko5PYA06LMUAt8kti57gBx8LJVoJXvQ== X-Received: by 2002:a5d:6c6d:: with SMTP id r13mr17800141wrz.350.1623667705982; Mon, 14 Jun 2021 03:48:25 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id m23sm15153732wms.2.2021.06.14.03.48.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Jun 2021 03:48:25 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Jeff King , Felipe Contreras , Adam Spiers , Thomas Rast , Ilya Bobyr , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFy?= =?utf-8?b?bWFzb24=?= Subject: [PATCH 8/8] test-lib tests: assert 1 exit code, not non-zero Date: Mon, 14 Jun 2021 12:48:14 +0200 Message-Id: X-Mailer: git-send-email 2.32.0.rc3.434.gd8aed1f08a7 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 02864c9d0e0..bb7153ac9e5 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 ( cd "$name" && @@ -58,33 +58,30 @@ _run_sub_test_lib_test_common () { TEST_OUTPUT_DIRECTORY=$(pwd) && export TEST_OUTPUT_DIRECTORY && 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 () {