From patchwork Mon Oct 21 10:56:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13843908 Received: from fout-a2-smtp.messagingengine.com (fout-a2-smtp.messagingengine.com [103.168.172.145]) (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 9D3FF1E633C for ; Mon, 21 Oct 2024 10:56:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.145 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729508202; cv=none; b=UdYXa22mhUu3pN8N2RzVc0aIKB6aXa/FYLFLw6A8mvdimRP51FWSG1ileZ9V+IxnLB+0BWOnSbmoDhwe3UUyhh3SRXY5yBbQBZTWjQqW/ICNgHBVamV3U7L1F3i1fYNkwK4veZay9p5dyVLp91an3+xFa7U4YbOA5Uzu6OmfL/o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729508202; c=relaxed/simple; bh=mNQbVqzDdm0uRWJRJOxPFwnmK8/saw5VLcKhWsf/Bks=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=dVZ0XNIPth0hCX1QEz7yV6dkZmPpTrfZ+WBhJ2QqubtEXT5JbaoAV4+iFuefdx6d91UjHJlq72qLIKvdVDj2POOA+qWpNtVV5HFAt5OEdyamoyzqe0b+c5RbEZjVdahz2J21mGpS85J6X+PJmjbqKLy/TMKDX8rf/zuyyrSW99s= 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=k2MOmrr1; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=bsnrm1hz; arc=none smtp.client-ip=103.168.172.145 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="k2MOmrr1"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="bsnrm1hz" Received: from phl-compute-07.internal (phl-compute-07.phl.internal [10.202.2.47]) by mailfout.phl.internal (Postfix) with ESMTP id AD9A2138004F; Mon, 21 Oct 2024 06:56:38 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-07.internal (MEProxy); Mon, 21 Oct 2024 06:56:38 -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=1729508198; x=1729594598; bh=59FEiJEGsL er7dWKhH3/rL1jTjAI/fgjPWeYY0RT0ws=; b=k2MOmrr1vPwUcBvHvlCqTLOqAF iD58LvYlZZnNgOrSUjM9BBiF5q0+ZYngDHF4Vh81v+uQsOgrPGjs7jpMIGy+sgTL IEEwqWPvSVNP6KTu2WiwpwETy+sAixxniU5QbPg7yH2vAApk72KiRwqq/krX2Cqk u5pjX/tg/DWrH3aNlGhWtOtuebFNuEigyLY//zbwBM5yficHQv7qcChktkr8c6uT Dt6xWnXXEvt/cfMceih0JWaTJEaZwYHrlnX1keef1I78ADWK27X3W/t1Vec/fYGx HW+XdbBdPsbIChOQUmVm4UrZPMzfHYtmt3MjKQTzlFtq0zBMlhqu+h4yhdCg== 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=1729508198; x=1729594598; bh=59FEiJEGsLer7dWKhH3/rL1jTjAI /fgjPWeYY0RT0ws=; b=bsnrm1hzhf9CQ5C9pbPXC4aXmc07WVXRiG+UoL2TSDwx Mg+sUYtgRr0E238m2pKVzJWX7jZRmWOiENKQxFEgf7izMZlwHWoLd9vMt0W7aSy+ h8HGi6ChHU9zFOqCiia8mDIwSXpNLyItHwHxfbz6ZUeiQGfjCtVcE288TkidI46J F2MdqjfyAMM8OD2/IDL6NFlHUN8/RAlJwmuyqUVELQUEKWUsnUVRJxA0ODB5ftJg cRbEk0LMXa7b6h8WBQa2gcgf0weKxYko0fRoMnRE3znLzA0aZhRIcMCjVmMNcorn rq9Znqgg0ui2GOMaR3uIunn499Lpu+xe+CioGUDUzw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrvdehledgfeegucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvden ucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimh eqnecuggftrfgrthhtvghrnhepveekkeffhfeitdeludeigfejtdetvdelvdduhefgueeg udfghfeukefhjedvkedtnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrg hilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohepuddtpdhmohguvgep shhmthhpohhuthdprhgtphhtthhopehsrghnuggrlhhssegtrhhushhthihtohhothhhph grshhtvgdrnhgvthdprhgtphhtthhopehgihhtsehvghgvrhdrkhgvrhhnvghlrdhorhhg pdhrtghpthhtohepsghonhgvthesghhrvghnohgslhgvrdgtnhhrshdrfhhrpdhrtghpth htohepjhhohhgrnhhnvghsrdhstghhihhnuggvlhhinhesghhmgidruggvpdhrtghpthht ohepsggrghgrshguohhtmhgvsehgmhgrihhlrdgtohhmpdhrtghpthhtohepphgvfhhfse hpvghffhdrnhgvthdprhgtphhtthhopegvughrvggvlhesghhmrghilhdrtghomhdprhgt phhtthhopegrshgvuggvnhhosehmihhtrdgvughupdhrtghpthhtohepthhoohhnsehioh httghlrdgtohhm X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 21 Oct 2024 06:56:36 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id c6e1e08b (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Mon, 21 Oct 2024 10:55:08 +0000 (UTC) Date: Mon, 21 Oct 2024 12:56:33 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Alejandro =?utf-8?q?R=2E_Sede=C3=B1o?= , Toon Claes , Taylor Blau , Ed Reel , Johannes Schindelin , Bagas Sanjaya , Edgar Bonet , Jeff King , "brian m. carlson" Subject: [PATCH v2 1/5] t/unit-tests: update clar to 206accb Message-ID: <06145a141dd3485f183bcf8248de0db61a7203db.1729506329.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: Update clar from: - 1516124 (Merge pull request #97 from pks-t/pks-whitespace-fixes, 2024-08-15). To: - 206accb (Merge pull request #108 from pks-t/pks-uclibc-without-wchar, 2024-10-21) This update includes a bunch of fixes and improvements that we have discussed in Git when initial support for clar was merged: - There is a ".editorconfig" file now. - Compatibility with Windows has been improved so that the clar compiles on this platform without an issue. This has been tested with Cygwin, MinGW and Microsoft Visual Studio. - clar now uses CMake. This does not impact us at all as we wire up the clar into our own build infrastructure anyway. This conversion was done such that we can easily run CI jobs against Windows. - Allocation failures are now checked for consistently. - We now define feature test macros in "clar.c", which fixes compilation on some platforms that didn't previously pull in non-standard functions like lstat(3p) or strdup(3p). This was reported by a user of OpenSUSE Leap. - We stop using `struct timezone`, which is undefined behaviour nowadays and results in a compilation error on some platforms. - We now use the combination of mktemp(3) and mkdir(3) on SunOS, same as we do on NonStop. - We now support uClibc without support for . The most important bits here are the improved platform compatibility with Windows, OpenSUSE, SunOS and uClibc. Signed-off-by: Patrick Steinhardt --- t/unit-tests/clar/.editorconfig | 13 +++ t/unit-tests/clar/.github/workflows/ci.yml | 20 +++- t/unit-tests/clar/.gitignore | 1 + t/unit-tests/clar/CMakeLists.txt | 28 +++++ t/unit-tests/clar/clar.c | 127 ++++++++++++--------- t/unit-tests/clar/clar/print.h | 11 +- t/unit-tests/clar/clar/sandbox.h | 17 ++- t/unit-tests/clar/clar/summary.h | 14 +-- t/unit-tests/clar/test/.gitignore | 4 - t/unit-tests/clar/test/CMakeLists.txt | 39 +++++++ t/unit-tests/clar/test/Makefile | 39 ------- 11 files changed, 189 insertions(+), 124 deletions(-) create mode 100644 t/unit-tests/clar/.editorconfig create mode 100644 t/unit-tests/clar/.gitignore create mode 100644 t/unit-tests/clar/CMakeLists.txt delete mode 100644 t/unit-tests/clar/test/.gitignore create mode 100644 t/unit-tests/clar/test/CMakeLists.txt delete mode 100644 t/unit-tests/clar/test/Makefile diff --git a/t/unit-tests/clar/.editorconfig b/t/unit-tests/clar/.editorconfig new file mode 100644 index 00000000000..aa343a42885 --- /dev/null +++ b/t/unit-tests/clar/.editorconfig @@ -0,0 +1,13 @@ +root = true + +[*] +charset = utf-8 +insert_final_newline = true + +[*.{c,h}] +indent_style = tab +tab_width = 8 + +[CMakeLists.txt] +indent_style = tab +tab_width = 8 diff --git a/t/unit-tests/clar/.github/workflows/ci.yml b/t/unit-tests/clar/.github/workflows/ci.yml index b1ac2de460a..0065843d17a 100644 --- a/t/unit-tests/clar/.github/workflows/ci.yml +++ b/t/unit-tests/clar/.github/workflows/ci.yml @@ -10,14 +10,26 @@ jobs: build: strategy: matrix: - os: [ ubuntu-latest, macos-latest ] + platform: + - os: ubuntu-latest + generator: Unix Makefiles + - os: macos-latest + generator: Unix Makefiles + - os: windows-latest + generator: Visual Studio 17 2022 + - os: windows-latest + generator: MSYS Makefiles + - os: windows-latest + generator: MinGW Makefiles - runs-on: ${{ matrix.os }} + runs-on: ${{ matrix.platform.os }} steps: - name: Check out uses: actions/checkout@v2 - name: Build run: | - cd test - make + mkdir build + cd build + cmake .. -G "${{matrix.platform.generator}}" + cmake --build . diff --git a/t/unit-tests/clar/.gitignore b/t/unit-tests/clar/.gitignore new file mode 100644 index 00000000000..84c048a73cc --- /dev/null +++ b/t/unit-tests/clar/.gitignore @@ -0,0 +1 @@ +/build/ diff --git a/t/unit-tests/clar/CMakeLists.txt b/t/unit-tests/clar/CMakeLists.txt new file mode 100644 index 00000000000..12d4af114fe --- /dev/null +++ b/t/unit-tests/clar/CMakeLists.txt @@ -0,0 +1,28 @@ +cmake_minimum_required(VERSION 3.16..3.29) + +project(clar LANGUAGES C) + +option(BUILD_TESTS "Build test executable" ON) + +add_library(clar INTERFACE) +target_sources(clar INTERFACE + clar.c + clar.h + clar/fixtures.h + clar/fs.h + clar/print.h + clar/sandbox.h + clar/summary.h +) +set_target_properties(clar PROPERTIES + C_STANDARD 90 + C_STANDARD_REQUIRED ON + C_EXTENSIONS OFF +) + +if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME) + include(CTest) + if(BUILD_TESTING) + add_subdirectory(test) + endif() +endif() diff --git a/t/unit-tests/clar/clar.c b/t/unit-tests/clar/clar.c index cef0f023c24..d54e4553674 100644 --- a/t/unit-tests/clar/clar.c +++ b/t/unit-tests/clar/clar.c @@ -4,7 +4,12 @@ * This file is part of clar, distributed under the ISC license. * For full terms see the included COPYING file. */ -#include + +#define _BSD_SOURCE +#define _DARWIN_C_SOURCE +#define _DEFAULT_SOURCE + +#include #include #include #include @@ -13,11 +18,22 @@ #include #include #include +#include /* required for sandboxing */ #include #include +#if defined(__UCLIBC__) && ! defined(__UCLIBC_HAS_WCHAR__) + /* + * uClibc can optionally be built without wchar support, in which case + * the installed is a stub that only defines the `whar_t` + * type but none of the functions typically declared by it. + */ +#else +# define CLAR_HAVE_WCHAR +#endif + #ifdef _WIN32 # define WIN32_LEAN_AND_MEAN # include @@ -28,6 +44,9 @@ # ifndef stat # define stat(path, st) _stat(path, st) + typedef struct _stat STAT_T; +# else + typedef struct stat STAT_T; # endif # ifndef mkdir # define mkdir(path, mode) _mkdir(path) @@ -60,30 +79,11 @@ # else # define p_snprintf snprintf # endif - -# ifndef PRIuZ -# define PRIuZ "Iu" -# endif -# ifndef PRIxZ -# define PRIxZ "Ix" -# endif - -# if defined(_MSC_VER) || (defined(__MINGW32__) && !defined(__MINGW64_VERSION_MAJOR)) - typedef struct stat STAT_T; -# else - typedef struct _stat STAT_T; -# endif #else # include /* waitpid(2) */ # include # define _MAIN_CC # define p_snprintf snprintf -# ifndef PRIuZ -# define PRIuZ "zu" -# endif -# ifndef PRIxZ -# define PRIxZ "zx" -# endif typedef struct stat STAT_T; #endif @@ -102,7 +102,7 @@ fixture_path(const char *base, const char *fixture_name); struct clar_error { const char *file; const char *function; - size_t line_number; + uintmax_t line_number; const char *error_msg; char *description; @@ -195,11 +195,12 @@ static void clar_print_shutdown(int test_count, int suite_count, int error_count static void clar_print_error(int num, const struct clar_report *report, const struct clar_error *error); static void clar_print_ontest(const char *suite_name, const char *test_name, int test_number, enum cl_test_status failed); static void clar_print_onsuite(const char *suite_name, int suite_index); +static void clar_print_onabortv(const char *msg, va_list argp); static void clar_print_onabort(const char *msg, ...); /* From clar_sandbox.c */ static void clar_unsandbox(void); -static int clar_sandbox(void); +static void clar_sandbox(void); /* From summary.h */ static struct clar_summary *clar_summary_init(const char *filename); @@ -218,6 +219,15 @@ static int clar_summary_shutdown(struct clar_summary *fp); _clar.trace_payload); \ } while (0) +static void clar_abort(const char *msg, ...) +{ + va_list argp; + va_start(argp, msg); + clar_print_onabortv(msg, argp); + va_end(argp); + exit(-1); +} + void cl_trace_register(cl_trace_cb *cb, void *payload) { _clar.pfn_trace_cb = cb; @@ -271,9 +281,7 @@ static double clar_time_diff(clar_time *start, clar_time *end) static void clar_time_now(clar_time *out) { - struct timezone tz; - - gettimeofday(out, &tz); + gettimeofday(out, NULL); } static double clar_time_diff(clar_time *start, clar_time *end) @@ -386,7 +394,8 @@ clar_run_suite(const struct clar_suite *suite, const char *filter) _clar.active_test = test[i].name; - report = calloc(1, sizeof(struct clar_report)); + if ((report = calloc(1, sizeof(*report))) == NULL) + clar_abort("Failed to allocate report.\n"); report->suite = _clar.active_suite; report->test = _clar.active_test; report->test_number = _clar.tests_ran; @@ -479,9 +488,10 @@ clar_parse_args(int argc, char **argv) switch (action) { case 's': { - struct clar_explicit *explicit = - calloc(1, sizeof(struct clar_explicit)); - assert(explicit); + struct clar_explicit *explicit; + + if ((explicit = calloc(1, sizeof(*explicit))) == NULL) + clar_abort("Failed to allocate explicit test.\n"); explicit->suite_idx = j; explicit->filter = argument; @@ -505,10 +515,8 @@ clar_parse_args(int argc, char **argv) } } - if (!found) { - clar_print_onabort("No suite matching '%s' found.\n", argument); - exit(-1); - } + if (!found) + clar_abort("No suite matching '%s' found.\n", argument); break; } @@ -540,11 +548,17 @@ clar_parse_args(int argc, char **argv) case 'r': _clar.write_summary = 1; free(_clar.summary_filename); - _clar.summary_filename = *(argument + 2) ? strdup(argument + 2) : NULL; + if (*(argument + 2)) { + if ((_clar.summary_filename = strdup(argument + 2)) == NULL) + clar_abort("Failed to allocate summary filename.\n"); + } else { + _clar.summary_filename = NULL; + } break; default: - assert(!"Unexpected commandline argument!"); + clar_abort("Unexpected commandline argument '%s'.\n", + argument[1]); } } } @@ -566,22 +580,18 @@ clar_test_init(int argc, char **argv) if (!_clar.summary_filename && (summary_env = getenv("CLAR_SUMMARY")) != NULL) { _clar.write_summary = 1; - _clar.summary_filename = strdup(summary_env); + if ((_clar.summary_filename = strdup(summary_env)) == NULL) + clar_abort("Failed to allocate summary filename.\n"); } if (_clar.write_summary && !_clar.summary_filename) - _clar.summary_filename = strdup("summary.xml"); + if ((_clar.summary_filename = strdup("summary.xml")) == NULL) + clar_abort("Failed to allocate summary filename.\n"); - if (_clar.write_summary && - !(_clar.summary = clar_summary_init(_clar.summary_filename))) { - clar_print_onabort("Failed to open the summary file\n"); - exit(-1); - } + if (_clar.write_summary) + _clar.summary = clar_summary_init(_clar.summary_filename); - if (clar_sandbox() < 0) { - clar_print_onabort("Failed to sandbox the test runner.\n"); - exit(-1); - } + clar_sandbox(); } int @@ -615,10 +625,9 @@ clar_test_shutdown(void) clar_unsandbox(); - if (_clar.write_summary && clar_summary_shutdown(_clar.summary) < 0) { - clar_print_onabort("Failed to write the summary file\n"); - exit(-1); - } + if (_clar.write_summary && clar_summary_shutdown(_clar.summary) < 0) + clar_abort("Failed to write the summary file '%s: %s.\n", + _clar.summary_filename, strerror(errno)); for (explicit = _clar.explicit; explicit; explicit = explicit_next) { explicit_next = explicit->next; @@ -649,7 +658,7 @@ static void abort_test(void) { if (!_clar.trampoline_enabled) { clar_print_onabort( - "Fatal error: a cleanup method raised an exception."); + "Fatal error: a cleanup method raised an exception.\n"); clar_report_errors(_clar.last_report); exit(-1); } @@ -673,7 +682,10 @@ void clar__fail( const char *description, int should_abort) { - struct clar_error *error = calloc(1, sizeof(struct clar_error)); + struct clar_error *error; + + if ((error = calloc(1, sizeof(*error))) == NULL) + clar_abort("Failed to allocate error.\n"); if (_clar.last_report->errors == NULL) _clar.last_report->errors = error; @@ -688,8 +700,9 @@ void clar__fail( error->line_number = line; error->error_msg = error_msg; - if (description != NULL) - error->description = strdup(description); + if (description != NULL && + (error->description = strdup(description)) == NULL) + clar_abort("Failed to allocate description.\n"); _clar.total_errors++; _clar.last_report->status = CL_TEST_FAILURE; @@ -763,6 +776,7 @@ void clar__assert_equal( } } } +#ifdef CLAR_HAVE_WCHAR else if (!strcmp("%ls", fmt)) { const wchar_t *wcs1 = va_arg(args, const wchar_t *); const wchar_t *wcs2 = va_arg(args, const wchar_t *); @@ -798,8 +812,9 @@ void clar__assert_equal( } } } - else if (!strcmp("%"PRIuZ, fmt) || !strcmp("%"PRIxZ, fmt)) { - size_t sz1 = va_arg(args, size_t), sz2 = va_arg(args, size_t); +#endif /* CLAR_HAVE_WCHAR */ + else if (!strcmp("%"PRIuMAX, fmt) || !strcmp("%"PRIxMAX, fmt)) { + uintmax_t sz1 = va_arg(args, uintmax_t), sz2 = va_arg(args, uintmax_t); is_equal = (sz1 == sz2); if (!is_equal) { int offset = p_snprintf(buf, sizeof(buf), fmt, sz1); diff --git a/t/unit-tests/clar/clar/print.h b/t/unit-tests/clar/clar/print.h index c17e2f693bd..69d0ee967e7 100644 --- a/t/unit-tests/clar/clar/print.h +++ b/t/unit-tests/clar/clar/print.h @@ -21,7 +21,7 @@ static void clar_print_clap_error(int num, const struct clar_report *report, con { printf(" %d) Failure:\n", num); - printf("%s::%s [%s:%"PRIuZ"]\n", + printf("%s::%s [%s:%"PRIuMAX"]\n", report->suite, report->test, error->file, @@ -136,7 +136,7 @@ static void clar_print_tap_ontest(const char *suite_name, const char *test_name, printf(" at:\n"); printf(" file: '"); print_escaped(error->file); printf("'\n"); - printf(" line: %" PRIuZ "\n", error->line_number); + printf(" line: %" PRIuMAX "\n", error->line_number); printf(" function: '%s'\n", error->function); printf(" ---\n"); @@ -202,10 +202,15 @@ static void clar_print_onsuite(const char *suite_name, int suite_index) PRINT(onsuite, suite_name, suite_index); } +static void clar_print_onabortv(const char *msg, va_list argp) +{ + PRINT(onabort, msg, argp); +} + static void clar_print_onabort(const char *msg, ...) { va_list argp; va_start(argp, msg); - PRINT(onabort, msg, argp); + clar_print_onabortv(msg, argp); va_end(argp); } diff --git a/t/unit-tests/clar/clar/sandbox.h b/t/unit-tests/clar/clar/sandbox.h index e25057b7c49..bc960f50e0f 100644 --- a/t/unit-tests/clar/clar/sandbox.h +++ b/t/unit-tests/clar/clar/sandbox.h @@ -122,14 +122,14 @@ static int build_sandbox_path(void) if (mkdir(_clar_path, 0700) != 0) return -1; -#elif defined(__TANDEM) - if (mktemp(_clar_path) == NULL) +#elif defined(_WIN32) + if (_mktemp_s(_clar_path, sizeof(_clar_path)) != 0) return -1; if (mkdir(_clar_path, 0700) != 0) return -1; -#elif defined(_WIN32) - if (_mktemp_s(_clar_path, sizeof(_clar_path)) != 0) +#elif defined(__sun) || defined(__TANDEM) + if (mktemp(_clar_path) == NULL) return -1; if (mkdir(_clar_path, 0700) != 0) @@ -142,15 +142,14 @@ static int build_sandbox_path(void) return 0; } -static int clar_sandbox(void) +static void clar_sandbox(void) { if (_clar_path[0] == '\0' && build_sandbox_path() < 0) - return -1; + clar_abort("Failed to build sandbox path.\n"); if (chdir(_clar_path) != 0) - return -1; - - return 0; + clar_abort("Failed to change into sandbox directory '%s': %s.\n", + _clar_path, strerror(errno)); } const char *clar_sandbox_path(void) diff --git a/t/unit-tests/clar/clar/summary.h b/t/unit-tests/clar/clar/summary.h index 4dd352e28b8..0d0b646fe75 100644 --- a/t/unit-tests/clar/clar/summary.h +++ b/t/unit-tests/clar/clar/summary.h @@ -66,16 +66,12 @@ struct clar_summary *clar_summary_init(const char *filename) struct clar_summary *summary; FILE *fp; - if ((fp = fopen(filename, "w")) == NULL) { - perror("fopen"); - return NULL; - } + if ((fp = fopen(filename, "w")) == NULL) + clar_abort("Failed to open the summary file '%s': %s.\n", + filename, strerror(errno)); - if ((summary = malloc(sizeof(struct clar_summary))) == NULL) { - perror("malloc"); - fclose(fp); - return NULL; - } + if ((summary = malloc(sizeof(struct clar_summary))) == NULL) + clar_abort("Failed to allocate summary.\n"); summary->filename = filename; summary->fp = fp; diff --git a/t/unit-tests/clar/test/.gitignore b/t/unit-tests/clar/test/.gitignore deleted file mode 100644 index a477d0c40ca..00000000000 --- a/t/unit-tests/clar/test/.gitignore +++ /dev/null @@ -1,4 +0,0 @@ -clar.suite -.clarcache -clar_test -*.o diff --git a/t/unit-tests/clar/test/CMakeLists.txt b/t/unit-tests/clar/test/CMakeLists.txt new file mode 100644 index 00000000000..7f2c1dc17a9 --- /dev/null +++ b/t/unit-tests/clar/test/CMakeLists.txt @@ -0,0 +1,39 @@ +find_package(Python COMPONENTS Interpreter REQUIRED) + +add_custom_command(OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/clar.suite" + COMMAND "${Python_EXECUTABLE}" "${CMAKE_SOURCE_DIR}/generate.py" --output "${CMAKE_CURRENT_BINARY_DIR}" + DEPENDS main.c sample.c clar_test.h + WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" +) + +add_executable(clar_test) +set_target_properties(clar_test PROPERTIES + C_STANDARD 90 + C_STANDARD_REQUIRED ON + C_EXTENSIONS OFF +) + +# MSVC generates all kinds of warnings. We may want to fix these in the future +# and then unconditionally treat warnings as errors. +if(NOT MSVC) + set_target_properties(clar_test PROPERTIES + COMPILE_WARNING_AS_ERROR ON + ) +endif() + +target_sources(clar_test PRIVATE + main.c + sample.c + "${CMAKE_CURRENT_BINARY_DIR}/clar.suite" +) +target_compile_definitions(clar_test PRIVATE + CLAR_FIXTURE_PATH="${CMAKE_CURRENT_SOURCE_DIR}/resources/" +) +target_compile_options(clar_test PRIVATE + $,/W4,-Wall> +) +target_include_directories(clar_test PRIVATE + "${CMAKE_SOURCE_DIR}" + "${CMAKE_CURRENT_BINARY_DIR}" +) +target_link_libraries(clar_test clar) diff --git a/t/unit-tests/clar/test/Makefile b/t/unit-tests/clar/test/Makefile deleted file mode 100644 index 93c6b2ad32c..00000000000 --- a/t/unit-tests/clar/test/Makefile +++ /dev/null @@ -1,39 +0,0 @@ -# -# Copyright (c) Vicent Marti. All rights reserved. -# -# This file is part of clar, distributed under the ISC license. -# For full terms see the included COPYING file. -# - -# -# Set up the path to the clar sources and to the fixtures directory -# -# The fixture path needs to be an absolute path so it can be used -# even after we have chdir'ed into the test directory while testing. -# -CURRENT_MAKEFILE := $(word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST)) -TEST_DIRECTORY := $(abspath $(dir $(CURRENT_MAKEFILE))) -CLAR_PATH := $(dir $(TEST_DIRECTORY)) -CLAR_FIXTURE_PATH := $(TEST_DIRECTORY)/resources/ - -CFLAGS=-g -I.. -I. -Wall -DCLAR_FIXTURE_PATH=\"$(CLAR_FIXTURE_PATH)\" - -.PHONY: clean - -# list the objects that go into our test -objects = main.o sample.o - -# build the test executable itself -clar_test: $(objects) clar_test.h clar.suite $(CLAR_PATH)clar.c - $(CC) $(CFLAGS) -o $@ "$(CLAR_PATH)clar.c" $(objects) - -# test object files depend on clar macros -$(objects) : $(CLAR_PATH)clar.h - -# build the clar.suite file of test metadata -clar.suite: - python "$(CLAR_PATH)generate.py" . - -# remove all generated files -clean: - $(RM) -rf *.o clar.suite .clarcache clar_test clar_test.dSYM From patchwork Mon Oct 21 10:56:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13843910 Received: from fhigh-a7-smtp.messagingengine.com (fhigh-a7-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 000C41E765C for ; Mon, 21 Oct 2024 10:56:41 +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=1729508203; cv=none; b=qwBSdCOw0lrIJFaxfnQRebvdKLdp5+OKBUMIXJfmPL+2Dup/ywRYwdtVn7dRodLdn+Irni1AbpCh79DS5scycaCNwZVUQFEaQN0JNJrxxAXkGbbPb1v80RtA2ylPjsouxsxvcSLjc2WeaOWvrJ44yc2x2kWS81TydQVeaI5HCKE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729508203; c=relaxed/simple; bh=nSFVXuh/O36rY0TcWW5He+uo83eAKx9Mv/0yNSyFJvk=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Mh4cvRMchcBxN5c+tgqJQk5w3biFWEis7VUJoIRWT+Zcpe1A/R5LBwXVjQKlwQJ9c0x4CSXdtGTYWsv30905r5+sYmi/0yL1DbRpCmP6PI/wXKCkum/aYOKYEtb68tcKSSQKzlVhHACn58r2HBk4jkZMcBiZItRzElejhMriD3A= 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=K01bZ2Fj; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=WekeLuhD; 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="K01bZ2Fj"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="WekeLuhD" Received: from phl-compute-12.internal (phl-compute-12.phl.internal [10.202.2.52]) by mailfhigh.phl.internal (Postfix) with ESMTP id 122D11140235; Mon, 21 Oct 2024 06:56:41 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-12.internal (MEProxy); Mon, 21 Oct 2024 06:56:41 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc:cc :content-transfer-encoding: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=1729508201; x=1729594601; bh=aJttxmBkuKljI1wHM/DP2f0F/WljyOzokRa4QBQ236s=; b= K01bZ2FjNvRkXYYUYVBi99guMmrm8b4W57CM12FhC4nAIEtLoQpi7CdppDl0kV2g pbnb/X5sntuqFRCV5QysF+6Sln9ZsaPMSoig9j+ZeKWC9/C8f5zcotVjp3kXkTz6 CswDoc7dpD5IGCPAtEM5eIe2BsYVY7HqIGPnXZ7cHIyJB84gWCBW0pnY/fAceL2i CWOHcO552FhgT+n7ds4rkPnIGEWHq5kLbNWwzFAtV61/3w/ov/5JgNFlLIruome4 zfw6B3jo0pfNbBaf4iNrN1k0Bxa6kHrpKblpoV1p4cXz9GRK2xiW469F/vHkdDN4 ojEgmF2OBd/Sg3Mtl02SMA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :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=1729508201; x= 1729594601; bh=aJttxmBkuKljI1wHM/DP2f0F/WljyOzokRa4QBQ236s=; b=W ekeLuhDP/nhFMv/VXHfsQyDRmHLaPdWy5PQ5INZWUjF4hm+D5d40zZdmqAtw/vxn ysoCdjg0r6Lx3N0Z66saez1wx7sNODI+x3qs2DtEJmcFrHpFcqQtiIOlqyH/KLeK iWASSLTuFzOhvlxkeWQNDx2Mkw6yi6B4N3GobXytDtHaXzTZx0RsUScjlHIUWyA9 4mweNAfjVLthIV6HPotBkoZfpcQ+OKawfzh2Gb5qprqMy1+V5FZcPOCiug8nEx8e Ve1/j8kMl9VtwUcMmCb+qInQhY+Dj36oOLr9XOnTHXzT/kJUcI5htdaeo9IcnR7Q PKgdD6qslfjbKDyURZ4pg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrvdehledgfeehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvfevuffkfhggtggugfgjsehtkeertddttdej necuhfhrohhmpefrrghtrhhitghkucfuthgvihhnhhgrrhguthcuoehpshesphhkshdrih hmqeenucggtffrrghtthgvrhhnpedvfeejiedtteelheeiteekveeftdefvdehkedvveet ffdvveevjeejleegtedvgfenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmh grihhlfhhrohhmpehpshesphhkshdrihhmpdhnsggprhgtphhtthhopedutddpmhhouggv pehsmhhtphhouhhtpdhrtghpthhtohepsghonhgvthesghhrvghnohgslhgvrdgtnhhrsh drfhhrpdhrtghpthhtohepsggrghgrshguohhtmhgvsehgmhgrihhlrdgtohhmpdhrtghp thhtohepvggurhgvvghlsehgmhgrihhlrdgtohhmpdhrtghpthhtohepghhithesvhhgvg hrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehtohhonhesihhothgtlhdrtghomhdp rhgtphhtthhopehsrghnuggrlhhssegtrhhushhthihtohhothhhphgrshhtvgdrnhgvth dprhgtphhtthhopehmvgesthhtrgihlhhorhhrrdgtohhmpdhrtghpthhtohepphgvfhhf sehpvghffhdrnhgvthdprhgtphhtthhopehjohhhrghnnhgvshdrshgthhhinhguvghlih hnsehgmhigrdguvg X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 21 Oct 2024 06:56:38 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 35d4bc2a (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Mon, 21 Oct 2024 10:55:11 +0000 (UTC) Date: Mon, 21 Oct 2024 12:56:35 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Alejandro =?utf-8?q?R=2E_Sede=C3=B1o?= , Toon Claes , Taylor Blau , Ed Reel , Johannes Schindelin , Bagas Sanjaya , Edgar Bonet , Jeff King , "brian m. carlson" Subject: [PATCH v2 2/5] Makefile: adjust sed command for generating "clar-decls.h" Message-ID: <17d77f36d41fb2928565a4922eab3a67426d2da6.1729506329.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: From: Alejandro R. Sedeño This moves the end-of-line marker out of the captured group, matching the start-of-line marker and for some reason fixing generation of "clar-decls.h" on some older, more esoteric platforms. Signed-off-by: Alejandro R. Sedeño Signed-off-by: Patrick Steinhardt --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index feeed6f9321..0101d349f38 100644 --- a/Makefile +++ b/Makefile @@ -3905,7 +3905,7 @@ GIT-TEST-SUITES: FORCE $(UNIT_TEST_DIR)/clar-decls.h: $(patsubst %,$(UNIT_TEST_DIR)/%.c,$(CLAR_TEST_SUITES)) GIT-TEST-SUITES $(QUIET_GEN)for suite in $(CLAR_TEST_SUITES); do \ - sed -ne "s/^\(void test_$${suite}__[a-zA-Z_0-9][a-zA-Z_0-9]*(void)$$\)/extern \1;/p" $(UNIT_TEST_DIR)/$$suite.c; \ + sed -ne "s/^\(void test_$${suite}__[a-zA-Z_0-9][a-zA-Z_0-9]*(void)\)$$/extern \1;/p" $(UNIT_TEST_DIR)/$$suite.c; \ done >$@ $(UNIT_TEST_DIR)/clar.suite: $(UNIT_TEST_DIR)/clar-decls.h $(QUIET_GEN)awk -f $(UNIT_TEST_DIR)/clar-generate.awk $< >$(UNIT_TEST_DIR)/clar.suite From patchwork Mon Oct 21 10:56:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13843911 Received: from fout-a2-smtp.messagingengine.com (fout-a2-smtp.messagingengine.com [103.168.172.145]) (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 1C87F1EABAC for ; Mon, 21 Oct 2024 10:56:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.145 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729508205; cv=none; b=mhPBmDpthZlbcm5/yyCeTCFIDIe+KH5G5n09HJjJ/hucbUO4c4qWa4n/BCIyQE19kNh5fZ5EgOcu6Dw48MD+FExRW77zAh90bMBf1RrDi2dkSgn3LnaOG82IW92ilx75pIt5n5rsBeIjKrMGc/+ZxNznzEh+G6DXK8yYhbE3q9U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729508205; c=relaxed/simple; bh=heQD6RiBc84s/U9Cl+vV3Q4jHGUiksGseHFe+1ueKLQ=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Y5HMETYf9NaiWlWMFVXU3R2yJkPVunUkP0iLK26dttRCa5posCSXvh2rxPhbiOGZbRVqG8jYpKZ84IucTxIQvdHLs3QB89M7GUTNP6rW/iTgE91ClGL+QEubsd9G2KUM/XNyGs9v6tY4ZglGHUdqE15iF9ZqQ9sJCo+yoiswSfw= 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=h1D+cz/Z; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=kg+VlBiQ; arc=none smtp.client-ip=103.168.172.145 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="h1D+cz/Z"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="kg+VlBiQ" Received: from phl-compute-09.internal (phl-compute-09.phl.internal [10.202.2.49]) by mailfout.phl.internal (Postfix) with ESMTP id 498FF13805C9; Mon, 21 Oct 2024 06:56:43 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-09.internal (MEProxy); Mon, 21 Oct 2024 06:56:43 -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=1729508203; x=1729594603; bh=pUxOpdGLnx uHasWNxzpE758H4lxrYuAvkx7y0fIAgBU=; b=h1D+cz/ZP4ZB5FAgqSWf5uqmJE O9O4hszv6ODi0SVfrsqcFoE7Cp5XKdLWGdrvS4UbCpdAkMRJCV+fWgHyGE9QGPOS pTgQqftgbpwVYpRxZwzUaC4wlLukyCcrpp3/ZgiP/vErECVyYeQ/3xVasyH3qoSC BV+KxYObwmQgAVW06drcIVQpCKdcm0twXtEviD8jaNEiUq98nFW38i8/hSFbYeqA JUqwyy1c4SqqTud34c1uh/ata0mBIH/ollaxY4fx2s35c35MC1AqrOD0APF7Eclf IasLO3D3dNpKkF7pXGtHbruBdVKSOVPayzuyCc+VABz7+549vfPRLj9RHrZw== 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=1729508203; x=1729594603; bh=pUxOpdGLnxuHasWNxzpE758H4lxr YuAvkx7y0fIAgBU=; b=kg+VlBiQXWHo/Zfw8JPM9+soDiBt6zKGDa/R5CXCRRUA YG+4BQDikbeSG1pHJJfgBd19YK2DekCUmTvuxG4zWyku7j3C+7g1Z3HL1Exqo+F3 9vwAL7lIj/rAJZ8jP2Vdk0onQMyjs+A55o0KvwrAEw42vMIOh+x3evMxfo1oSsC/ wEtp66UuJQ7dN6sFTfJopCmTupFOMk8KWjxOBnz3p1cStLjUyzmo4/rnjKJ8pzsq 0DbRs6rHGrIsOZT8k/kIvS5+hEB6omDzlfMSbXnzPQeThVm6ilb2K84jiUJ7L7Es 2Rz1t7UdEMsxxchuy7+7oCqPpcbJDURMzRSVXprDVw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrvdehledgfeehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvden ucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimh eqnecuggftrfgrthhtvghrnhepveekkeffhfeitdeludeigfejtdetvdelvdduhefgueeg udfghfeukefhjedvkedtnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrg hilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohepuddtpdhmohguvgep shhmthhpohhuthdprhgtphhtthhopegrshgvuggvnhhosehmihhtrdgvughupdhrtghpth htohepvggurhgvvghlsehgmhgrihhlrdgtohhmpdhrtghpthhtohepghhithesvhhgvghr rdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehjohhhrghnnhgvshdrshgthhhinhguvg hlihhnsehgmhigrdguvgdprhgtphhtthhopehtohhonhesihhothgtlhdrtghomhdprhgt phhtthhopegsohhnvghtsehgrhgvnhhosghlvgdrtghnrhhsrdhfrhdprhgtphhtthhope hpvghffhesphgvfhhfrdhnvghtpdhrtghpthhtohepshgrnhgurghlshestghruhhsthih thhoohhthhhprghsthgvrdhnvghtpdhrtghpthhtohepsggrghgrshguohhtmhgvsehgmh grihhlrdgtohhm X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 21 Oct 2024 06:56:41 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 3ceb8d40 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Mon, 21 Oct 2024 10:55:13 +0000 (UTC) Date: Mon, 21 Oct 2024 12:56:38 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Alejandro =?utf-8?q?R=2E_Sede=C3=B1o?= , Toon Claes , Taylor Blau , Ed Reel , Johannes Schindelin , Bagas Sanjaya , Edgar Bonet , Jeff King , "brian m. carlson" Subject: [PATCH v2 3/5] Makefile: extract script to generate clar declarations Message-ID: 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: Extract the script to generate function declarations for the clar unit testing framework into a standalone script. This is done such that we can reuse it in other build systems. Signed-off-by: Patrick Steinhardt --- Makefile | 4 +--- t/unit-tests/generate-clar-decls.sh | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 3 deletions(-) create mode 100755 t/unit-tests/generate-clar-decls.sh diff --git a/Makefile b/Makefile index 0101d349f38..6318ec0271b 100644 --- a/Makefile +++ b/Makefile @@ -3904,9 +3904,7 @@ GIT-TEST-SUITES: FORCE fi $(UNIT_TEST_DIR)/clar-decls.h: $(patsubst %,$(UNIT_TEST_DIR)/%.c,$(CLAR_TEST_SUITES)) GIT-TEST-SUITES - $(QUIET_GEN)for suite in $(CLAR_TEST_SUITES); do \ - sed -ne "s/^\(void test_$${suite}__[a-zA-Z_0-9][a-zA-Z_0-9]*(void)\)$$/extern \1;/p" $(UNIT_TEST_DIR)/$$suite.c; \ - done >$@ + $(QUIET_GEN)$(SHELL_PATH) $(UNIT_TEST_DIR)/generate-clar-decls.sh "$@" $(filter %.c,$^) $(UNIT_TEST_DIR)/clar.suite: $(UNIT_TEST_DIR)/clar-decls.h $(QUIET_GEN)awk -f $(UNIT_TEST_DIR)/clar-generate.awk $< >$(UNIT_TEST_DIR)/clar.suite $(CLAR_TEST_OBJS): $(UNIT_TEST_DIR)/clar-decls.h diff --git a/t/unit-tests/generate-clar-decls.sh b/t/unit-tests/generate-clar-decls.sh new file mode 100755 index 00000000000..688e0885f4f --- /dev/null +++ b/t/unit-tests/generate-clar-decls.sh @@ -0,0 +1,16 @@ +#!/bin/sh + +if test $# -lt 2 +then + echo "USAGE: $0 ..." 2>&1 + exit 1 +fi + +OUTPUT="$1" +shift + +for suite in "$@" +do + sed -ne "s/^\(void test_$(basename "${suite%.c}")__[a-zA-Z_0-9][a-zA-Z_0-9]*(void)\)$/extern \1;/p" "$suite" || + exit 1 +done >"$OUTPUT" From patchwork Mon Oct 21 10:56:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13843912 Received: from fout-a2-smtp.messagingengine.com (fout-a2-smtp.messagingengine.com [103.168.172.145]) (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 38F241EABC2 for ; Mon, 21 Oct 2024 10:56:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.145 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729508208; cv=none; b=OFZ0QicpSEASqkfWW53RnI/HFrcuvESdTpniPRASxeqFXoQBPGhHobIoDKoe4fEt6vSDrq71Y7b85fSLPGQb9hvV3QQ/fUPbEhKRdkteU2RNTXsPI0xWbsq8mGgXlVYmWM2Ri97aV9c92qSQTa6A70ozjInyGRTj5YJuSGKo+AA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729508208; c=relaxed/simple; bh=Kl0AJ4n9zhg/y++ngEQ4g9zCh71eOBfwRGehyqJxUVc=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=OLJaxy6ckRtvsamTSnC1zcN0ONy9OLb1b03lnAj6nDDxFJrDBe2ij8TdtRBu1t5c3azBk/0zqgP/cgfk4mqRVFIbVX/45hV6ld8j7I2PBiJAqHc+CfoNKbT7cLRHcK9Hd/IHDzw8V43NWgMFLul/4HuJH9j8lEjKQwL05lLEL5M= 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=NXikoP3p; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=Bt09MRJR; arc=none smtp.client-ip=103.168.172.145 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="NXikoP3p"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="Bt09MRJR" Received: from phl-compute-12.internal (phl-compute-12.phl.internal [10.202.2.52]) by mailfout.phl.internal (Postfix) with ESMTP id 734D713805CA; Mon, 21 Oct 2024 06:56:45 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-12.internal (MEProxy); Mon, 21 Oct 2024 06:56:45 -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=1729508205; x=1729594605; bh=zYLO5UFxdR kmyC0RNarrzCBBDTJNtE+GRF9vYzMzkMA=; b=NXikoP3p6bZcNkFB7tpBt6BbiQ BMLrzC5YhlMXyhIkzV3LddRJ3M4KFSmKJW5MnVKcgEiClSOksQO2B3YzhIb9AHh+ UvFWNVQacfVuNZWNxFLRfkRbA4sFVOgSST80oKLQ0PC4KglHH7r53OzMwHaj335Y gEua2g32wHfkg0w/2mL/POtnq+B1vVzP/8SCwNXxVjjuWwIvKDsHPxJcC5ngKX5o 460kdXqLVM2ncxkk5EiBPGjqtYc4rvYQ2R2l7rPY/ZBvw7zubCztQoR+k1HlEEvE s+1L3ZkcCRVlsWs9v8NKrLhoOl1lGMyWmBjjSpunsWwmhTNE5y9jCb8SopaQ== 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=1729508205; x=1729594605; bh=zYLO5UFxdRkmyC0RNarrzCBBDTJN tE+GRF9vYzMzkMA=; b=Bt09MRJRS+1C1lQMQkl0fO37c/lGsPcmkHZywDuIbPat 3yfhEXD4APvJ8GgWUWfkXIrAnhGg9XOfVCK9ul7dVAl8lu4mm7tgzuQgbpe7m54R M8K8yylyuTJPo0okWK6mvLo2Ic/5GXQQWgqjufkQi7pP+7SfV2NRjrCnYAc90p0b CVOgA3kgILfwKV2Oc+FA892U9AR/oSDPacWpo/91npe786KwD2Di7sxreXCF0IRW QOYROrp2r7XZ/szdsInpNrCnw3ZaefLHwTfN3RVHRKQn8lU6ezYoLl6SQ+3D0GPl AEVp8ip6ranLV2C17dx1x3tGRk3J11Wh/XN4+cKEWA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrvdehledgfeehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvden ucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimh eqnecuggftrfgrthhtvghrnhepveekkeffhfeitdeludeigfejtdetvdelvdduhefgueeg udfghfeukefhjedvkedtnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrg hilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohepuddtpdhmohguvgep shhmthhpohhuthdprhgtphhtthhopehsrghnuggrlhhssegtrhhushhthihtohhothhhph grshhtvgdrnhgvthdprhgtphhtthhopehgihhtsehvghgvrhdrkhgvrhhnvghlrdhorhhg pdhrtghpthhtohepvggurhgvvghlsehgmhgrihhlrdgtohhmpdhrtghpthhtohepsggrgh grshguohhtmhgvsehgmhgrihhlrdgtohhmpdhrtghpthhtoheprghsvgguvghnohesmhhi thdrvgguuhdprhgtphhtthhopehtohhonhesihhothgtlhdrtghomhdprhgtphhtthhope gsohhnvghtsehgrhgvnhhosghlvgdrtghnrhhsrdhfrhdprhgtphhtthhopehjohhhrghn nhgvshdrshgthhhinhguvghlihhnsehgmhigrdguvgdprhgtphhtthhopehmvgesthhtrg ihlhhorhhrrdgtohhm X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 21 Oct 2024 06:56:43 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id dd78467a (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Mon, 21 Oct 2024 10:55:16 +0000 (UTC) Date: Mon, 21 Oct 2024 12:56:41 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Alejandro =?utf-8?q?R=2E_Sede=C3=B1o?= , Toon Claes , Taylor Blau , Ed Reel , Johannes Schindelin , Bagas Sanjaya , Edgar Bonet , Jeff King , "brian m. carlson" Subject: [PATCH v2 4/5] cmake: fix compilation of clar-based unit tests Message-ID: 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 compilation of clar-based unit tests is broken because we do not add the binary directory into which we generate the "clar-decls.h" and "clar.suite" files as include directories. Instead, we accidentally set up the source directory as include directory. Fix this by including the binary directory instead of the source directory. Furthermore, set up the include directories as PUBLIC instead of PRIVATE such that they propagate from "unit-tests.lib" to the "unit-tests" executable, which needs to include the same directory. Reported-by: Ed Reel Signed-off-by: Patrick Steinhardt --- contrib/buildsystems/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/buildsystems/CMakeLists.txt b/contrib/buildsystems/CMakeLists.txt index 62af7b33d2f..093852ad9d6 100644 --- a/contrib/buildsystems/CMakeLists.txt +++ b/contrib/buildsystems/CMakeLists.txt @@ -1042,7 +1042,7 @@ file(WRITE "${CMAKE_BINARY_DIR}/t/unit-tests/clar.suite" "${clar_decls}" "${clar list(TRANSFORM clar_test_SUITES PREPEND "${CMAKE_SOURCE_DIR}/t/unit-tests/") list(TRANSFORM clar_test_SUITES APPEND ".c") add_library(unit-tests-lib ${clar_test_SUITES} "${CMAKE_SOURCE_DIR}/t/unit-tests/clar/clar.c") -target_include_directories(unit-tests-lib PRIVATE "${CMAKE_SOURCE_DIR}/t/unit-tests") +target_include_directories(unit-tests-lib PUBLIC "${CMAKE_BINARY_DIR}/t/unit-tests") add_executable(unit-tests "${CMAKE_SOURCE_DIR}/t/unit-tests/unit-test.c") target_link_libraries(unit-tests unit-tests-lib common-main) set_target_properties(unit-tests From patchwork Mon Oct 21 10:56:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13843913 Received: from fout-a2-smtp.messagingengine.com (fout-a2-smtp.messagingengine.com [103.168.172.145]) (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 725821EB9EF for ; Mon, 21 Oct 2024 10:56:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.145 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729508213; cv=none; b=seI0UikoNUl9OjhtFZFtOpGa8tWv/yxIo1LTBBKAoNOK4NQRUddOV8Go6O3BxTqIms9jfVvT6uq08lY7Kv9RyEDUwAZw/4t5k9UAuIdW9j3vcwclyl8cSqadt9dr4YOGVTvqczIKEEePgbcVb5ChSseEtO8lmu6D/5xNxp7nn4g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729508213; c=relaxed/simple; bh=GsLwj5/w33fv4cikxIvLwctBSP2ExHPAE6i4bKSo6PU=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=smDJ1VjMtSzMWdXD6B7pTSFWxYw/v5JwUBg2Yj8eJOtJvZLoP+atP+8UZ0K1mN28KpEKQ190LRfjZLzyuxPj2yy9/ULnZzBVDDD0NRzODyrsLWFvWNm6p7Ys2uqsRanKDBVVayGhAJflBKV50xXavQGgfVmT9mDPj9avcy8kM04= 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=TmFIuycp; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=iW+LHjl8; arc=none smtp.client-ip=103.168.172.145 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="TmFIuycp"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="iW+LHjl8" Received: from phl-compute-03.internal (phl-compute-03.phl.internal [10.202.2.43]) by mailfout.phl.internal (Postfix) with ESMTP id B2993138004F; Mon, 21 Oct 2024 06:56:50 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-03.internal (MEProxy); Mon, 21 Oct 2024 06:56:50 -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=1729508210; x=1729594610; bh=nXEBxyoUXU 2vNAnXcDZ4i2LAL0iOEDM9z+7UIryYypU=; b=TmFIuycpzo7zGk1WQXUhhTLYTH QldtbbUanv2koRS4MfQVpCiTa9aKvnp/VeqE3Fj6FaH5zelTy7G5O+FgzYk6Jyxt nLQXJ1NC6rU1FG2govJvZnfhXEyZ1jR3zC0b0qZFqkYbVuI88OnFpYFo662+GuL2 qUCSYRmfSwQs+oB0siJUJjjfntZdGRLSOpCeuKeAU9xJUsUWadcLzd95Iursol6N rRWemLfY0pp7qd41F41uR7PM4pp+pfcbizkC7OnFHxZ/cqUDFBONyCqfuA/On9TL 8cKsnrR5vhEYFR67/T5JXCGzebnPMHBGttQztCXQyPmEJGvJaqbf9WIZo8vQ== 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=1729508210; x=1729594610; bh=nXEBxyoUXU2vNAnXcDZ4i2LAL0iO EDM9z+7UIryYypU=; b=iW+LHjl8QDrSb8r9gz0tKQ+M+4UaLfslcZn6IzkxdG5T d1zeHMWZYydsoUjRCEcc7A9zPctAOjS366/ypvACI7buGLRI8eZcHKuqDmVunmJI BDTt/GLhOUIHXmm35JEqPlVM1D8jMXRba6E8KgTTJEJBi4Z2GPKAiNwrUGCvqcCM FSe8HJ9zbRfK3FWUfsi2T7sQtjbsxHicrLRnFymvxaKFwsL7cJrgWyBur8tZZnQT vTEse/8TpMwW7L1RFogE+B4It04h+6T9VgRqHuRIdJRen8nBa/XbZZRtjc4zly2V 3mpdQRrMwQ7gqlrQNAj2HlOb9kFVdrRfv+h29z/SNQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrvdehledgfeehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvden ucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimh eqnecuggftrfgrthhtvghrnhepveekkeffhfeitdeludeigfejtdetvdelvdduhefgueeg udfghfeukefhjedvkedtnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrg hilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohepuddtpdhmohguvgep shhmthhpohhuthdprhgtphhtthhopehgihhtsehvghgvrhdrkhgvrhhnvghlrdhorhhgpd hrtghpthhtohepshgrnhgurghlshestghruhhsthihthhoohhthhhprghsthgvrdhnvght pdhrtghpthhtohepvggurhgvvghlsehgmhgrihhlrdgtohhmpdhrtghpthhtohepsggrgh grshguohhtmhgvsehgmhgrihhlrdgtohhmpdhrtghpthhtohepphgvfhhfsehpvghffhdr nhgvthdprhgtphhtthhopegrshgvuggvnhhosehmihhtrdgvughupdhrtghpthhtohepmh gvsehtthgrhihlohhrrhdrtghomhdprhgtphhtthhopehjohhhrghnnhgvshdrshgthhhi nhguvghlihhnsehgmhigrdguvgdprhgtphhtthhopehtohhonhesihhothgtlhdrtghomh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 21 Oct 2024 06:56:48 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id b94673c0 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Mon, 21 Oct 2024 10:55:21 +0000 (UTC) Date: Mon, 21 Oct 2024 12:56:44 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Alejandro =?utf-8?q?R=2E_Sede=C3=B1o?= , Toon Claes , Taylor Blau , Ed Reel , Johannes Schindelin , Bagas Sanjaya , Edgar Bonet , Jeff King , "brian m. carlson" Subject: [PATCH v2 5/5] cmake: set up proper dependencies for generated clar headers Message-ID: 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 auto-generated headers used by clar are written at configure time and thus do not get regenerated automatically. Refactor the build recipes such that we use custom commands instead, which also has the benefit that we can reuse the same infrastructure as our Makefile. Signed-off-by: Patrick Steinhardt --- contrib/buildsystems/CMakeLists.txt | 50 +++++++---------------------- 1 file changed, 12 insertions(+), 38 deletions(-) diff --git a/contrib/buildsystems/CMakeLists.txt b/contrib/buildsystems/CMakeLists.txt index 093852ad9d6..9f80ab92656 100644 --- a/contrib/buildsystems/CMakeLists.txt +++ b/contrib/buildsystems/CMakeLists.txt @@ -1002,46 +1002,20 @@ foreach(unit_test ${unit_test_PROGRAMS}) endforeach() parse_makefile_for_scripts(clar_test_SUITES "CLAR_TEST_SUITES" "") - -set(clar_decls "") -set(clar_cbs "") -set(clar_cbs_count 0) -set(clar_suites "static struct clar_suite _clar_suites[] = {\n") -list(LENGTH clar_test_SUITES clar_suites_count) -foreach(suite ${clar_test_SUITES}) - file(STRINGS "${CMAKE_SOURCE_DIR}/t/unit-tests/${suite}.c" decls - REGEX "^void test_${suite}__[a-zA-Z_0-9][a-zA-Z_0-9]*\\(void\\)$") - - list(LENGTH decls decls_count) - string(REGEX REPLACE "void (test_${suite}__([a-zA-Z_0-9]*))\\(void\\)" " { \"\\2\", &\\1 },\n" cbs ${decls}) - string(JOIN "" cbs ${cbs}) - list(TRANSFORM decls PREPEND "extern ") - string(JOIN ";\n" decls ${decls}) - - string(APPEND clar_decls "${decls};\n") - string(APPEND clar_cbs - "static const struct clar_func _clar_cb_${suite}[] = {\n" - ${cbs} - "};\n") - string(APPEND clar_suites - " {\n" - " \"${suite}\",\n" - " { NULL, NULL },\n" - " { NULL, NULL },\n" - " _clar_cb_${suite}, ${decls_count}, 1\n" - " },\n") - math(EXPR clar_cbs_count "${clar_cbs_count}+${decls_count}") -endforeach() -string(APPEND clar_suites - "};\n" - "static const size_t _clar_suite_count = ${clar_suites_count};\n" - "static const size_t _clar_callback_count = ${clar_cbs_count};\n") -file(WRITE "${CMAKE_BINARY_DIR}/t/unit-tests/clar-decls.h" "${clar_decls}") -file(WRITE "${CMAKE_BINARY_DIR}/t/unit-tests/clar.suite" "${clar_decls}" "${clar_cbs}" "${clar_suites}") - list(TRANSFORM clar_test_SUITES PREPEND "${CMAKE_SOURCE_DIR}/t/unit-tests/") list(TRANSFORM clar_test_SUITES APPEND ".c") -add_library(unit-tests-lib ${clar_test_SUITES} "${CMAKE_SOURCE_DIR}/t/unit-tests/clar/clar.c") +add_custom_command(OUTPUT "${CMAKE_BINARY_DIR}/t/unit-tests/clar-decls.h" + COMMAND ${CMAKE_SOURCE_DIR}/t/unit-tests/generate-clar-decls.sh "${CMAKE_BINARY_DIR}/t/unit-tests/clar-decls.h" ${clar_test_SUITES} + DEPENDS ${CMAKE_SOURCE_DIR}/t/unit-tests/generate-clar-decls.sh ${clar_test_SUITES}) +add_custom_command(OUTPUT "${CMAKE_BINARY_DIR}/t/unit-tests/clar.suite" + COMMAND awk -f "${CMAKE_SOURCE_DIR}/t/unit-tests/clar-generate.awk" "${CMAKE_BINARY_DIR}/t/unit-tests/clar-decls.h" > "${CMAKE_BINARY_DIR}/t/unit-tests/clar.suite" + DEPENDS "${CMAKE_SOURCE_DIR}/t/unit-tests/clar-generate.awk" "${CMAKE_BINARY_DIR}/t/unit-tests/clar-decls.h") + +add_library(unit-tests-lib ${clar_test_SUITES} + "${CMAKE_SOURCE_DIR}/t/unit-tests/clar/clar.c" + "${CMAKE_BINARY_DIR}/t/unit-tests/clar-decls.h" + "${CMAKE_BINARY_DIR}/t/unit-tests/clar.suite" +) target_include_directories(unit-tests-lib PUBLIC "${CMAKE_BINARY_DIR}/t/unit-tests") add_executable(unit-tests "${CMAKE_SOURCE_DIR}/t/unit-tests/unit-test.c") target_link_libraries(unit-tests unit-tests-lib common-main)