From patchwork Tue Aug 6 14:15:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13754955 Received: from fhigh7-smtp.messagingengine.com (fhigh7-smtp.messagingengine.com [103.168.172.158]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C99961BD50B for ; Tue, 6 Aug 2024 14:15:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.158 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722953709; cv=none; b=eiKh9NsIIu3OiDRoG1NMSx7J1M+m7NPpFyICd86wqheOcPwMN+CjKyFsUpZtP6CCMTBrJFM+/00VwfFo1L7Ami9ti8uKkdDNwmXwU90i0uJ7TznzTDKV2DK4oc1Xbs2xFVZklBBz8OLahAUa/ip2Ziu4GqAi8figltsowGO4kAo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722953709; c=relaxed/simple; bh=TCZUJ8PkHQnejbvTwFFOZPk8pq8ZFDayLJDIVRMNjbs=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=oyehWlZR9IIoxJTwSgvQZZ4OVwyD52gFCGguaacJkwAHBNCDUf9s8xB/FWz8Q+DwXvrBL7qDRTjSZuO4nphqOX6SJahgA5SeCnzS6IdNS3mR7hpPZJ+rPP294zmlFr6VpJoO9F9tuA2fy+4W5L3UWC0U3WJMzyrGWW7FI5Rb+PA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im; spf=pass smtp.mailfrom=pks.im; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b=VQU0cPBz; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=HtVNvRin; arc=none smtp.client-ip=103.168.172.158 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pks.im Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b="VQU0cPBz"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="HtVNvRin" Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailfhigh.nyi.internal (Postfix) with ESMTP id 1FA391150E15; Tue, 6 Aug 2024 10:15:07 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute3.internal (MEProxy); Tue, 06 Aug 2024 10:15:07 -0400 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:subject :subject:to:to; s=fm3; t=1722953707; x=1723040107; bh=mIR+Yf6LL4 CHjUL/ZjnuzzaFFDTA0GT8kQun/0/x7wA=; b=VQU0cPBzgS0bO3BuncDei+O2E0 lgm3ajGKkXD39f7KNeu2P5sWreQ8n4PIt7Oapf0QqWeyj/YwP/SK/nIEupCw9GfL IQ3NbigBr2GWdrNabhoQp7I8bdEE69ejUcqt+I/1nGMmq3Y0qtRB6r+cd8IE3Fby kTkKyC++NPyMDETr6qeMS9FztvqbTQMR09LbHCVUybvd7/bJj6HjNkxyQW+r4472 VlYUnzwaRWY7+WEzbZzDFmxnQxZ41hEYjsXliheC+HILjfbnB4cb2n71r8TxvRH0 ZpXWnkzRsIH09lwOxyptLOm1E2AlqBKmUueHGPkzH0//1Y3TKTMTBsA2IKaA== 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:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; t=1722953707; x=1723040107; bh=mIR+Yf6LL4CHjUL/ZjnuzzaFFDTA 0GT8kQun/0/x7wA=; b=HtVNvRin2vLi2QnJWayWg7gfDY4QviIsGwjpNh5Iygak SWAjd3K7Ekxv4LWDBUDoR7RjgU4TwpxPkarCk0C1gZqZZqiYh7kXeeLGF4BTTI3W Tmq9NgYwILDnE0a9QgtCdr7AtiAIN9QbLgH0I7iMS03ZuzRdmKjvn+Hue8FY7T78 sTx8iX1bNEvsWh8lNf08hr3c8/HJc0fgbnKGx5atiUIw8QRBeb3jet4BrcCQW71I kKPGvJ53OXSQR0EQtcLoHc08ZKLM9uOZ1tDesWUEpKCQNYM0wv5RX5PUjL0mBBn2 zNJe6XkipOg4WmE3C94N8EiLr5Oy+tgdPiNo/fbqeQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrkeekgdejgecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpeffhffvvefukfhfgggtuggjsehgtderredttddvnecuhfhrohhmpefrrghtrhhi tghkucfuthgvihhnhhgrrhguthcuoehpshesphhkshdrihhmqeenucggtffrrghtthgvrh hnpeeukedtvedtffevleejtefgheehieegkeeluddvfeefgeehgfeltddtheejleffteen ucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehpshesph hkshdrihhmpdhnsggprhgtphhtthhopedt X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 6 Aug 2024 10:15:05 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id cccb6dee (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Tue, 6 Aug 2024 14:15:02 +0000 (UTC) Date: Tue, 6 Aug 2024 16:15:03 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: =?utf-8?b?UmVuw6k=?= Scharfe , Junio C Hamano , Kyle Lippincott , Phillip Wood , Josh Steadmon , rsbecker@nexbridge.com, Edward Thomson Subject: [RFC PATCH v2 7/7] t/unit-tests: convert ctype tests to use clar Message-ID: <238de33b9381dceaa8c4175251b3d25c2ef78777.1722952908.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: Convert the ctype tests to use the new clar unit testing framework. Signed-off-by: Patrick Steinhardt --- Makefile | 2 +- t/unit-tests/{t-ctype.c => ctype.c} | 71 +++++++++++++++++++++++------ 2 files changed, 59 insertions(+), 14 deletions(-) rename t/unit-tests/{t-ctype.c => ctype.c} (71%) diff --git a/Makefile b/Makefile index cf76f9b353..aa2bd5cec1 100644 --- a/Makefile +++ b/Makefile @@ -1334,13 +1334,13 @@ THIRD_PARTY_SOURCES += sha1dc/% THIRD_PARTY_SOURCES += $(UNIT_TEST_DIR)/clar/% THIRD_PARTY_SOURCES += $(UNIT_TEST_DIR)/clar/clar/% +UNIT_TESTS_SUITES += ctype UNIT_TESTS_SUITES += strvec UNIT_TESTS_PROG = $(UNIT_TEST_BIN)/unit-tests$(X) UNIT_TESTS_OBJS = $(patsubst %,$(UNIT_TEST_DIR)/%.o,$(UNIT_TESTS_SUITES)) UNIT_TESTS_OBJS += $(UNIT_TEST_DIR)/clar/clar.o UNIT_TESTS_OBJS += $(UNIT_TEST_DIR)/unit-test.o -UNIT_TEST_PROGRAMS += t-ctype UNIT_TEST_PROGRAMS += t-example-decorate UNIT_TEST_PROGRAMS += t-hash UNIT_TEST_PROGRAMS += t-mem-pool diff --git a/t/unit-tests/t-ctype.c b/t/unit-tests/ctype.c similarity index 71% rename from t/unit-tests/t-ctype.c rename to t/unit-tests/ctype.c index d6ac1fe678..311df3a539 100644 --- a/t/unit-tests/t-ctype.c +++ b/t/unit-tests/ctype.c @@ -1,18 +1,12 @@ -#include "test-lib.h" +#include "unit-test.h" #define TEST_CHAR_CLASS(class, string) do { \ size_t len = ARRAY_SIZE(string) - 1 + \ BUILD_ASSERT_OR_ZERO(ARRAY_SIZE(string) > 0) + \ BUILD_ASSERT_OR_ZERO(sizeof(string[0]) == sizeof(char)); \ - int skip = test__run_begin(); \ - if (!skip) { \ - for (int i = 0; i < 256; i++) { \ - if (!check_int(class(i), ==, !!memchr(string, i, len)))\ - test_msg(" i: 0x%02x", i); \ - } \ - check(!class(EOF)); \ - } \ - test__run_end(!skip, TEST_LOCATION(), #class " works"); \ + for (int i = 0; i < 256; i++) \ + cl_assert_equal_i(class(i), !!memchr(string, i, len)); \ + cl_assert(!class(EOF)); \ } while (0) #define DIGIT "0123456789" @@ -33,21 +27,72 @@ "\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f" \ "\x7f" -int cmd_main(int argc, const char **argv) { +void test_ctype__isspace(void) +{ TEST_CHAR_CLASS(isspace, " \n\r\t"); +} + +void test_ctype__isdigit(void) +{ TEST_CHAR_CLASS(isdigit, DIGIT); +} + +void test_ctype__isalpha(void) +{ TEST_CHAR_CLASS(isalpha, LOWER UPPER); +} + +void test_ctype__isalnum(void) +{ TEST_CHAR_CLASS(isalnum, LOWER UPPER DIGIT); +} + +void test_ctype__is_glob_special(void) +{ TEST_CHAR_CLASS(is_glob_special, "*?[\\"); +} + +void test_ctype__is_regex_special(void) +{ TEST_CHAR_CLASS(is_regex_special, "$()*+.?[\\^{|"); +} + +void test_ctype__is_pathspec_magic(void) +{ TEST_CHAR_CLASS(is_pathspec_magic, "!\"#%&',-/:;<=>@_`~"); +} + +void test_ctype__isascii(void) +{ TEST_CHAR_CLASS(isascii, ASCII); +} + +void test_ctype__islower(void) +{ TEST_CHAR_CLASS(islower, LOWER); +} + +void test_ctype__isupper(void) +{ TEST_CHAR_CLASS(isupper, UPPER); +} + +void test_ctype__iscntrl(void) +{ TEST_CHAR_CLASS(iscntrl, CNTRL); +} + +void test_ctype__ispunct(void) +{ TEST_CHAR_CLASS(ispunct, PUNCT); +} + +void test_ctype__isxdigit(void) +{ TEST_CHAR_CLASS(isxdigit, DIGIT "abcdefABCDEF"); - TEST_CHAR_CLASS(isprint, LOWER UPPER DIGIT PUNCT " "); +} - return test_done(); +void test_ctype__isprint(void) +{ + TEST_CHAR_CLASS(isprint, LOWER UPPER DIGIT PUNCT " "); }