From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-Status: No, score=-3.8 required=3.0 tests=AWL,BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_PASS, SPF_PASS shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by dcvr.yhbt.net (Postfix) with ESMTP id 6826C1F66F for ; Fri, 20 Nov 2020 00:24:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726474AbgKTAWt (ORCPT ); Thu, 19 Nov 2020 19:22:49 -0500 Received: from cloud.peff.net ([104.130.231.41]:36228 "EHLO cloud.peff.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726192AbgKTAWt (ORCPT ); Thu, 19 Nov 2020 19:22:49 -0500 Received: (qmail 525 invoked by uid 109); 20 Nov 2020 00:22:49 -0000 Received: from Unknown (HELO peff.net) (10.0.1.2) by cloud.peff.net (qpsmtpd/0.94) with ESMTP; Fri, 20 Nov 2020 00:22:49 +0000 Authentication-Results: cloud.peff.net; auth=none Received: (qmail 1341 invoked by uid 111); 20 Nov 2020 00:22:48 -0000 Received: from coredump.intra.peff.net (HELO sigill.intra.peff.net) (10.0.0.2) by peff.net (qpsmtpd/0.94) with (TLS_AES_256_GCM_SHA384 encrypted) ESMTPS; Thu, 19 Nov 2020 19:22:48 -0500 Authentication-Results: peff.net; auth=none Date: Thu, 19 Nov 2020 19:22:47 -0500 From: Jeff King To: Junio C Hamano Cc: SZEDER =?utf-8?B?R8OhYm9y?= , git@vger.kernel.org, Johannes Schindelin Subject: [PATCH 3/4] t0000: run cleaning test inside sub-test Message-ID: <20201120002247.GC307112@coredump.intra.peff.net> References: <20201120001458.GA274082@coredump.intra.peff.net> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20201120001458.GA274082@coredump.intra.peff.net> Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Our check of test_when_finished is done directly in the main script, and if we failed to clean, we complain and exit immediately. It's nicer to signal a test failure here, for a few reasons: - this gives better output to the user when run under a TAP harness like "prove" - constency; it's the only test left in the file that behaves this way - half of its "if" conditional is nonsense anyway; it picked up a reference to GIT_TEST_FAIL_PREREQS internal in dfe1a17df9 (tests: add a special setup where prerequisites fail, 2019-05-13) along with its neighbors, even though it has nothing to do with that flag We could actually do this without a sub-test at all, and just put our two tests (one to do cleanup, and one to check that it happened) in the main script. But doing it in a subtest is conceptually cleaner (from the perspective of the main test script, we are checking only one thing), and it remains consistent with the "cleanup when failing" test directly after it, which has to happen in a sub-test (to avoid the main script complaining of the failed test). Signed-off-by: Jeff King --- t/t0000-basic.sh | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/t/t0000-basic.sh b/t/t0000-basic.sh index 3d36a87610..502375bdf6 100755 --- a/t/t0000-basic.sh +++ b/t/t0000-basic.sh @@ -852,16 +852,25 @@ test_expect_success 'lazy prereqs do not turn off tracing' " grep 'echo trace' lazy-prereq-and-tracing/err " -clean=no test_expect_success 'tests clean up after themselves' ' - test_when_finished clean=yes -' + run_sub_test_lib_test cleanup "test with cleanup" <<-\EOF && + clean=no + test_expect_success "do cleanup" " + test_when_finished clean=yes + " + test_expect_success "cleanup happened" " + test $clean = yes + " + test_done + EOF -if test -z "$GIT_TEST_FAIL_PREREQS_INTERNAL" -a $clean != yes -then - say "bug in test framework: basic cleanup command does not work reliably" - exit 1 -fi + check_sub_test_lib_test cleanup <<-\EOF + ok 1 - do cleanup + ok 2 - cleanup happened + # passed all 2 test(s) + 1..2 + EOF +' test_expect_success 'tests clean up even on failures' " run_sub_test_lib_test_err \ -- 2.29.2.730.g3e418f96ba