From patchwork Mon Dec 11 09:07:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13486857 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b="RVqA1L5e"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="pNf6SHDY" Received: from wout2-smtp.messagingengine.com (wout2-smtp.messagingengine.com [64.147.123.25]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A2B0AC3 for ; Mon, 11 Dec 2023 01:07:34 -0800 (PST) Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.west.internal (Postfix) with ESMTP id 997F13202629; Mon, 11 Dec 2023 04:07:33 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute1.internal (MEProxy); Mon, 11 Dec 2023 04:07:34 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc:cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:sender :subject:subject:to:to; s=fm1; t=1702285653; x=1702372053; bh=MP Px12L6ZY4rNKw5Pnejundaqx57AtRza1Skh5nhY9M=; b=RVqA1L5epVoMOueHKq womMqcK4TjE/vDjlmQ+9duB3b8Zf97zzEKx5nQ5mqZI7wWkoBlVlrKdm7wMVaDtA BnKyTt9hz5cPJzPGKuvGlVGim7WIZfcplIU8/PyiI7ByMzJwNmjFEl5D8M5fXkji P7GjIgOLrXrYOkdwTq/8bMO3gP2WV1lkbEZEehPPEYY69Hhb5oHCQ+nzZ355Y/Ce AiagE/+gTjOuJ2YLxAlz9IYfiFElBSOOZctJqVM0W/pLyL9VgmEMWaCWy9AlG1uv eHe0Nk/Wp+ZXcGVYVo6s2wjGw5+d6UhMHTxEQfCKhc7IbRLD2/tT83H1FPTb8FqA mCeQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:sender:subject :subject:to:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm1; t=1702285653; x=1702372053; bh=MPPx12L6ZY4rN Kw5Pnejundaqx57AtRza1Skh5nhY9M=; b=pNf6SHDYtO4DytvT3j8oz9Z9Z2DB9 izYAGDI8KVxsvR7S71ERnyFGlJS7lGgtkbcCAZGkDdUcItvB2oltcUX6HSBu664e z9qkvCEvuukH4auziN73UNC/JIvr/+SM32qvVZAWWeRbBCwGOt+De9ZZbM0h3P9K LV7AdMH+I757VykvGZSnkWkYgghnaoHldeb+nu3wgWwiotyR+8NlYSlvl7vmhwKr PXkm+MBeMdR7tQrKHB3dvJjQC2aR0eLqKYWrZ69OH9qkdzoI6v1p/8CAEe3cspA9 M0/4H5kab7UFISXz1tENb3twQ0CmZ2/5gWBO+oYOyk9PcZMz+px+pjpcQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvkedrudeluddguddvlecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpeffhffvvefukfhfgggtuggjsehgtderredttddvnecuhfhrohhmpefrrght rhhitghkucfuthgvihhnhhgrrhguthcuoehpshesphhkshdrihhmqeenucggtffrrghtth gvrhhnpeeukedtvedtffevleejtefgheehieegkeeluddvfeefgeehgfeltddtheejleff teenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehpsh esphhkshdrihhm X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 11 Dec 2023 04:07:31 -0500 (EST) Received: by vm-mail (OpenSMTPD) with ESMTPSA id e701bf95 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Mon, 11 Dec 2023 09:05:55 +0000 (UTC) Date: Mon, 11 Dec 2023 10:07:29 +0100 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Han-Wen Nienhuys , Jonathan Nieder , Taylor Blau , Eric Sunshine Subject: [PATCH v3 01/11] reftable: wrap EXPECT macros in do/while Message-ID: <5b2a64ca9fa1d290b5b7838ad15c0894b65ae777.1702285387.git.ps@pks.im> References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: The `EXPECT` macros used by the reftable test framework are all using a single `if` statement with the actual condition. This results in weird syntax when using them in if/else statements like the following: ``` if (foo) EXPECT(foo == 2) else EXPECT(bar == 2) ``` Note that there need not be a trailing semicolon. Furthermore, it is not immediately obvious whether the else now belongs to the `if (foo)` or whether it belongs to the expanded `if (foo == 2)` from the macro. Fix this by wrapping the macros in a do/while loop. Signed-off-by: Patrick Steinhardt --- reftable/test_framework.h | 58 +++++++++++++++++++++------------------ 1 file changed, 32 insertions(+), 26 deletions(-) diff --git a/reftable/test_framework.h b/reftable/test_framework.h index 774cb275bf..ee44f735ae 100644 --- a/reftable/test_framework.h +++ b/reftable/test_framework.h @@ -12,32 +12,38 @@ license that can be found in the LICENSE file or at #include "system.h" #include "reftable-error.h" -#define EXPECT_ERR(c) \ - if (c != 0) { \ - fflush(stderr); \ - fflush(stdout); \ - fprintf(stderr, "%s: %d: error == %d (%s), want 0\n", \ - __FILE__, __LINE__, c, reftable_error_str(c)); \ - abort(); \ - } - -#define EXPECT_STREQ(a, b) \ - if (strcmp(a, b)) { \ - fflush(stderr); \ - fflush(stdout); \ - fprintf(stderr, "%s:%d: %s (%s) != %s (%s)\n", __FILE__, \ - __LINE__, #a, a, #b, b); \ - abort(); \ - } - -#define EXPECT(c) \ - if (!(c)) { \ - fflush(stderr); \ - fflush(stdout); \ - fprintf(stderr, "%s: %d: failed assertion %s\n", __FILE__, \ - __LINE__, #c); \ - abort(); \ - } +#define EXPECT_ERR(c) \ + do { \ + if (c != 0) { \ + fflush(stderr); \ + fflush(stdout); \ + fprintf(stderr, "%s: %d: error == %d (%s), want 0\n", \ + __FILE__, __LINE__, c, reftable_error_str(c)); \ + abort(); \ + } \ + } while (0) + +#define EXPECT_STREQ(a, b) \ + do { \ + if (strcmp(a, b)) { \ + fflush(stderr); \ + fflush(stdout); \ + fprintf(stderr, "%s:%d: %s (%s) != %s (%s)\n", __FILE__, \ + __LINE__, #a, a, #b, b); \ + abort(); \ + } \ + } while (0) + +#define EXPECT(c) \ + do { \ + if (!(c)) { \ + fflush(stderr); \ + fflush(stdout); \ + fprintf(stderr, "%s: %d: failed assertion %s\n", __FILE__, \ + __LINE__, #c); \ + abort(); \ + } \ + } while (0) #define RUN_TEST(f) \ fprintf(stderr, "running %s\n", #f); \