summaryrefslogtreecommitdiff
path: root/t/unit-tests/clar
AgeCommit message (Collapse)Author
5 dayst/unit-tests/clar: fix -Wmaybe-uninitialized with -OgDenton Liu
When building with -Og on gcc 15.1.1, the build produces a warning. In practice, though, this cannot be hit because `exact` acts as a guard and that variable can only be set after `matchlen` is already initialized Assign a default value to `matchlen` so that the warning is silenced. Signed-off-by: Denton Liu <liu.denton@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2025-03-28clar: avoid using the comma operator unnecessarilyJohannes Schindelin
The comma operator is a somewhat obscure C feature that is often used by mistake and can even cause unintentional code flow. In this instance, it makes the code harder to read than necessary, too. Better use a semicolon instead. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Acked-by: Phillip Wood <phillip.wood@dunelm.org.uk> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2024-10-21t/unit-tests: update clar to 206accbPatrick Steinhardt
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 <wchar.h>. The most important bits here are the improved platform compatibility with Windows, OpenSUSE, SunOS and uClibc. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Taylor Blau <me@ttaylorr.com>
2024-09-04clar: stop including `shellapi.h` unnecessarilyJohannes Schindelin
The `shellapi.h` header was included as of https://github.com/clar-test/clar/commit/136e763211aa, to have `SHFileOperation()` declared so that it could be called. However, https://github.com/clar-test/clar/commit/5ce31b69b525 removed that call, and therefore that `#include <shellapi.h>` is unnecessary. It is also unwanted in Git because this project uses a subset of Git for Windows' SDK in its CI builds that (for bandwidth reasons) excludes tons of header files, including `shellapi.h`. So let's remove it. Note: Since the `windows.h` header would include `shellapi.h` anyway, we also define `WIN32_LEAN_AND_MEAN` to avoid this and similar other unnecessary includes before including `windows.h`. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2024-09-04clar(win32): avoid compile error due to unused `fs_copy()`Johannes Schindelin
When CLAR_FIXTURE_PATH is unset, the `fs_copy()` function seems not to be used. But it is declared as `static`, and GCC does not like that, complaining that it should not be declared/defined to begin with. We could mark this function as (potentially) unused by following the `MAYBE_UNUSED` pattern from Git's `git-compat-util.h`. However, this is a GCC-only construct that is not understood by Visual C. Besides, `clar` does not use that pattern at all. Instead, let's use the `((void)SYMBOL);` pattern that `clar` already uses elsewhere; This avoids the compile error by sorta kinda make the function used after a fashion. Note: GCC 14.x (which Git for Windows' SDK already uses) is able to figure out that this function is unused even though there are recursive calls between `fs_copy()` and `fs_copydir_helper()`; Earlier GCC versions do not detect that, and therefore the issue has been hidden from the regular Linux CI builds (where GCC 14.x is not yet used). That is the reason why this change is only made in the Windows-specific portion of `t/unit-tests/clar/clar/fs.h`. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2024-09-04clar: avoid compile error with mingw-w64Johannes Schindelin
When using mingw-w64 to compile the code, and using `_stat()`, it is necessary to use `struct _stat`, too, and not `struct stat` (as the latter is incompatible with the "dashed" version because it is limited to 32-bit time types for backwards compatibility). Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2024-09-04t/clar: fix compatibility with NonStopPatrick Steinhardt
The NonStop platform does not have `mkdtemp()` available, which we rely on in `build_sandbox_path()`. Fix this issue by using `mktemp()` and `mkdir()` instead on this platform. This has been cherry-picked from the upstream pull request at [1]. [1]: https://github.com/clar-test/clar/pull/96 Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2024-09-04t: import the clar unit testing frameworkPatrick Steinhardt
Our unit testing framework is a homegrown solution. While it supports most of our needs, it is likely that the volume of unit tests will grow quite a bit in the future such that we can exercise low-level subsystems directly. This surfaces several shortcomings that the current solution has: - There is no way to run only one specific tests. While some of our unit tests wire this up manually, others don't. In general, it requires quite a bit of boilerplate to get this set up correctly. - Failures do not cause a test to stop execution directly. Instead, the test author needs to return manually whenever an assertion fails. This is rather verbose and is not done correctly in most of our unit tests. - Wiring up a new testcase requires both implementing the test function and calling it in the respective test suite's main function, which is creating code duplication. We can of course fix all of these issues ourselves, but that feels rather pointless when there are already so many unit testing frameworks out there that have those features. We line out some requirements for any unit testing framework in "Documentation/technical/unit-tests.txt". The "clar" unit testing framework, which isn't listed in that table yet, ticks many of the boxes: - It is licensed under ISC, which is compatible. - It is easily vendorable because it is rather tiny at around 1200 lines of code. - It is easily hackable due to the same reason. - It has TAP support. - It has skippable tests. - It preprocesses test files in order to extract test functions, which then get wired up automatically. While it's not perfect, the fact that clar originates from the libgit2 project means that it should be rather easy for us to collaborate with upstream to plug any gaps. Import the clar unit testing framework at commit 1516124 (Merge pull request #97 from pks-t/pks-whitespace-fixes, 2024-08-15). The framework will be wired up in subsequent commits. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>