From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp0 ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id QLNiMUtvCmElAQEAgWs5BA (envelope-from ) for ; Wed, 04 Aug 2021 12:43:23 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp0 with LMTPS id EJssLUtvCmHXGQAA1q6Kng (envelope-from ) for ; Wed, 04 Aug 2021 10:43:23 +0000 Received: from mail.notmuchmail.org (nmbug.tethera.net [144.217.243.247]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 81AA3A4F1 for ; Wed, 4 Aug 2021 12:43:23 +0200 (CEST) Received: from nmbug.tethera.net (localhost [127.0.0.1]) by mail.notmuchmail.org (Postfix) with ESMTP id 58DCD2C0F2; Wed, 4 Aug 2021 06:43:00 -0400 (EDT) Received: from fethera.tethera.net (fethera.tethera.net [IPv6:2607:5300:60:c5::1]) by mail.notmuchmail.org (Postfix) with ESMTP id 23E9F2C0DB for ; Wed, 4 Aug 2021 06:42:49 -0400 (EDT) Received: by fethera.tethera.net (Postfix, from userid 1001) id 1C6395FD5C; Wed, 4 Aug 2021 06:42:49 -0400 (EDT) Received: (nullmailer pid 3986523 invoked by uid 1000); Wed, 04 Aug 2021 10:42:42 -0000 From: David Bremner To: notmuch@notmuchmail.org Cc: David Bremner Subject: [PATCH 3/7] test: add test_expect_equal_file_nonempty Date: Wed, 4 Aug 2021 07:42:32 -0300 Message-Id: <20210804104236.3986362-4-david@tethera.net> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210804104236.3986362-1-david@tethera.net> References: <20210804104236.3986362-1-david@tethera.net> MIME-Version: 1.0 Message-ID-Hash: T2NPQAAX2BFLKJG36CUNHHFQGIGEMJGC X-Message-ID-Hash: T2NPQAAX2BFLKJG36CUNHHFQGIGEMJGC X-MailFrom: bremner@tethera.net X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-notmuch.notmuchmail.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header X-Mailman-Version: 3.2.1 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Help: List-Post: List-Subscribe: List-Unsubscribe: Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Migadu-Flow: FLOW_IN ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1628073803; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=lkAU97kX3C06N+dg4LOD4NfFMBf9a4PUlJNur0RG6SI=; b=dk7Dljd6EhKirjPfC4fzCupJIFZjqga7/6Bl0ZwDfRqlhntcRLp+En7d9gfcEeiyulx+jV ukODfLHEB6ft6H9V3X1BRE/gFrJhiLKWFBnlc8YGdM+FhKGrCITyqu+KHR/Vwc/ahZz0zl MYyr9ioJX00UDRcBpUBEc1xlO0JBPyZSXMkYsoj+wvv7cRsc1nRjNdv6UuUiHW3LIm1tj9 9uUFSEA11RWO9mfHoGBPUhE69JiswEvF2ZXyGXFuiPO/N4hf2fdkL9gcc2QWSjRXoenZuZ HjDmA3HQN6D6hJRQs3FmHbOxg30usHEqcdnM2l6/M7E5EkowcDvS85bqycfLlA== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1628073803; a=rsa-sha256; cv=none; b=koVgTskho7nrZIND9YFS/NnGZJC0umJdgwtFdUbsLgRIDAcP4xEqZjJKiYGuGfGBFEf6ey i+jd3Qr4pzvWiYOifDH8lK1NLLpMm44WoW12DXb8P2WCLlu1YL61ZHAAeFEf5woLzmPrQ5 gvgxkGMk2X4b8jW/X+LcYQYm1QxvAZ7bQ5fZZ8qxFWMy1mNDejY59bEyJ5MaRuILY+n+kr /dCIiBcU5syfArzzmNL3kLV1eU7eYyRGQMbvahyAz1kyJKO6lNNA1cT+wWa3dSIuYM2Amy GlBeVhMLNfc85MGp4Zn4dNTn8GUnqY/EEE3/6HuWC0Auk7jXtHeCiOOEQrHnkQ== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=none; dmarc=none; spf=pass (aspmx1.migadu.com: domain of notmuch-bounces@notmuchmail.org designates 144.217.243.247 as permitted sender) smtp.mailfrom=notmuch-bounces@notmuchmail.org X-Migadu-Spam-Score: -1.02 Authentication-Results: aspmx1.migadu.com; dkim=none; dmarc=none; spf=pass (aspmx1.migadu.com: domain of notmuch-bounces@notmuchmail.org designates 144.217.243.247 as permitted sender) smtp.mailfrom=notmuch-bounces@notmuchmail.org X-Migadu-Queue-Id: 81AA3A4F1 X-Spam-Score: -1.02 X-Migadu-Scanner: scn0.migadu.com X-TUID: xTX6EuQ2Tg8i A common bug in tests is that the code used to generate the EXPECTED file fails, generating no output. When the code generating the OUTPUT file fails in the same way, the test passes, even though there is a failure being hidden. Add a new test function that guards against this. --- test/test-lib.sh | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/test/test-lib.sh b/test/test-lib.sh index 6f4bb47f..dc4962f5 100644 --- a/test/test-lib.sh +++ b/test/test-lib.sh @@ -434,6 +434,26 @@ test_expect_equal_file () { test_diff_file_ "$1" "$2" } +# Like test_expect_equal, but takes two filenames. Fails if either is empty +test_expect_equal_file_nonempty () { + exec 1>&6 2>&7 # Restore stdout and stderr + if [ -z "$inside_subtest" ]; then + error "bug in the test script: test_expect_equal_file_nonempty without test_begin_subtest" + fi + inside_subtest= + test "$#" = 2 || + error "bug in the test script: not 2 parameters to test_expect_equal_file_nonempty" + + for file in "$1" "$2"; do + if [ ! -s "$file" ]; then + test_failure_ "Missing or zero length file: $file" + return $? + fi + done + + test_diff_file_ "$1" "$2" +} + # Like test_expect_equal, but arguments are JSON expressions to be # canonicalized before diff'ing. If an argument cannot be parsed, it # is used unchanged so that there's something to diff against. -- 2.30.2