t: import the clar unit testing framework
commit9b7caa2809cba618f2af702d35b12bc99535f2b9
authorPatrick Steinhardt <ps@pks.im>
Wed, 4 Sep 2024 14:16:48 +0000 (4 16:16 +0200)
committerJunio C Hamano <gitster@pobox.com>
Wed, 4 Sep 2024 15:41:36 +0000 (4 08:41 -0700)
tree0f1591bf2586d56363aa51f0767df4f5fe69e706
parent71360809ec218ebb58a092f61efbd215fe1d364b
t: import the clar unit testing framework

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>
20 files changed:
Documentation/technical/unit-tests.txt
Makefile
t/unit-tests/clar/.github/workflows/ci.yml [new file with mode: 0644]
t/unit-tests/clar/COPYING [new file with mode: 0644]
t/unit-tests/clar/README.md [new file with mode: 0644]
t/unit-tests/clar/clar.c [new file with mode: 0644]
t/unit-tests/clar/clar.h [new file with mode: 0644]
t/unit-tests/clar/clar/fixtures.h [new file with mode: 0644]
t/unit-tests/clar/clar/fs.h [new file with mode: 0644]
t/unit-tests/clar/clar/print.h [new file with mode: 0644]
t/unit-tests/clar/clar/sandbox.h [new file with mode: 0644]
t/unit-tests/clar/clar/summary.h [new file with mode: 0644]
t/unit-tests/clar/generate.py [new file with mode: 0755]
t/unit-tests/clar/test/.gitignore [new file with mode: 0644]
t/unit-tests/clar/test/Makefile [new file with mode: 0644]
t/unit-tests/clar/test/clar_test.h [new file with mode: 0644]
t/unit-tests/clar/test/main.c [new file with mode: 0644]
t/unit-tests/clar/test/main.c.sample [new file with mode: 0644]
t/unit-tests/clar/test/resources/test/file [new file with mode: 0644]
t/unit-tests/clar/test/sample.c [new file with mode: 0644]