From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp2 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id 2AqMGMEKCGHJ7wAAgWs5BA (envelope-from ) for ; Mon, 02 Aug 2021 17:09:53 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp2 with LMTPS id OO8oFMEKCGEFagAAB5/wlQ (envelope-from ) for ; Mon, 02 Aug 2021 15:09:53 +0000 Received: from mail.notmuchmail.org (nmbug.tethera.net [IPv6:2607:5300:201:3100::1657]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 1790D7A0E for ; Mon, 2 Aug 2021 17:09:53 +0200 (CEST) Received: from nmbug.tethera.net (localhost [127.0.0.1]) by mail.notmuchmail.org (Postfix) with ESMTP id 18ADC2C050; Mon, 2 Aug 2021 11:09:39 -0400 (EDT) Received: from fethera.tethera.net (fethera.tethera.net [198.245.60.197]) by mail.notmuchmail.org (Postfix) with ESMTP id 9C14C2C03C for ; Mon, 2 Aug 2021 11:09:33 -0400 (EDT) Received: by fethera.tethera.net (Postfix, from userid 1001) id 9463B5FD5C; Mon, 2 Aug 2021 11:09:33 -0400 (EDT) Received: (nullmailer pid 3234752 invoked by uid 1000); Mon, 02 Aug 2021 15:09:30 -0000 From: David Bremner To: notmuch@notmuchmail.org Cc: David Bremner Subject: [PATCH 4/8] test: add test_expect_equal_file_nonempty Date: Mon, 2 Aug 2021 12:09:18 -0300 Message-Id: <20210802150922.3234616-5-david@tethera.net> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210802150922.3234616-1-david@tethera.net> References: <87bl9lx864.fsf@kisara.moe> <20210802150922.3234616-1-david@tethera.net> MIME-Version: 1.0 Message-ID-Hash: MXTRHRM3HYMQWTSKVAFDDBMB4MKPEUBJ X-Message-ID-Hash: MXTRHRM3HYMQWTSKVAFDDBMB4MKPEUBJ 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=1627916993; 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=SYypAb3Y8Y8OgCWo85Fgrx8w2S68Jkkv0pTmeJoguao=; b=pAHxR8Jse2yPvn8NKfco69i8OC5UkiDdpEw9OmSqOphRavJuQESyXZzgs7D2CNOtTVkGxE TbqNEEihHTHJiTNfJwidJeg1xpboH+zZuPuLEmZ72lMdVWa8CoI/NMyLQ245oULRZXniwo O5V75+r1UWV/vVC2bCOIotw5w1yonsAP9a+HWRtBqo80503QX4wLdfsZnCyJqJWTlkVpyG LFlgVJk5PuGAPIl61QaxNGdXvNLBT9S2Hfet8LavZUP9Eyme3EzhtNcao8ybtRjJNCzEfh 5H1y1LpqBE/UITSsxu5NgbFZfAYMXmKvhsSkQZ40QMBYIbHRBaZHXhCOiO3Y7w== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1627916993; a=rsa-sha256; cv=none; b=G8f4PR7JHixZPNc8BMDcel63m5tlvDtziZwwvnQvYGPkWpBPOmV9Hyn07rGRVnJO+AcRzp SzOyJo1XVwcoFyxykRTrayMht6MAzbtLvQ9pMjQlwwbA4AqKMdLLt9Jeqk51lBYR7eOa3c 74PCXyyDL+FKEj1/1BGSIRjBOUli2K0jwzIs6iob5jVS9ys8/IofhHaABPdu02b9DUDyja xsT7SVkB/w5nm4a4g5K9IoQE+Lpayi6sqfagPqVSP1DsES2C+d0kdhc9ULRyZNnPKjimto jLFeQsM54S1OAVMvN68elhr9p47fdr4p3eOGac2CfWIvaAP6teqKRGQ2c6Hk9g== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=none; dmarc=none; spf=pass (aspmx1.migadu.com: domain of notmuch-bounces@notmuchmail.org designates 2607:5300:201:3100::1657 as permitted sender) smtp.mailfrom=notmuch-bounces@notmuchmail.org X-Migadu-Spam-Score: 0.53 Authentication-Results: aspmx1.migadu.com; dkim=none; dmarc=none; spf=pass (aspmx1.migadu.com: domain of notmuch-bounces@notmuchmail.org designates 2607:5300:201:3100::1657 as permitted sender) smtp.mailfrom=notmuch-bounces@notmuchmail.org X-Migadu-Queue-Id: 1790D7A0E X-Spam-Score: 0.53 X-Migadu-Scanner: scn0.migadu.com X-TUID: 7Lbn2zoOJEPF 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 | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/test/test-lib.sh b/test/test-lib.sh index a8e57e51..4865032d 100644 --- a/test/test-lib.sh +++ b/test/test-lib.sh @@ -434,6 +434,25 @@ 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" + 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