summaryrefslogtreecommitdiff
path: root/t/unit-tests/unit-test.h
AgeCommit message (Collapse)Author
8 daysmeson: ensure correct "clar-decls.h" header is usedPatrick Steinhardt
The "clar-decls.h" header gets generated by us to extract prototypes of unit test functions from our clar-based tests. This generated file is then written into "t/unit-tests/" and included via "unit-test.h". The intent of all this is that we can keep "-Wmissing-prototype" warnings enabled. If we had that warning disabled, it would be easy to miss in case any of the non-static functions had a typo in its name and thus wasn't picked up by our test case extractor. Including the file directly has a big downside though: if a source tree was built both with our Makefile and with Meson, then the Meson build would include the "clar-decls.h" file from our Makefile. And if those are out of sync we get compiler errors. We already fixed a similar issue in 4771501c0a (meson: ensure correct version-def.h is used, 2025-01-14). Let's do the same and pass the absolute path to "clar-decls.h" via a preprocessor define. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2024-09-04t/unit-tests: convert ctype tests to use clarPatrick Steinhardt
Convert the ctype tests to use the new clar unit testing framework. Introduce a new function `cl_failf()` that allows us to print a formatted error message, which we can use to point out which of the characters was classified incorrectly. This results in output like this on failure: # start of suite 1: ctype not ok 1 - ctype::isspace --- reason: | Test failed. 0x0d is classified incorrectly: expected 0, got 1 at: file: 't/unit-tests/ctype.c' line: 36 function: 'test_ctype__isspace' --- ok 2 - ctype::isdigit ok 3 - ctype::isalpha ok 4 - ctype::isalnum ok 5 - ctype::is_glob_special ok 6 - ctype::is_regex_special ok 7 - ctype::is_pathspec_magic ok 8 - ctype::isascii ok 9 - ctype::islower ok 10 - ctype::isupper ok 11 - ctype::iscntrl ok 12 - ctype::ispunct ok 13 - ctype::isxdigit ok 14 - ctype::isprint Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2024-09-04Makefile: wire up the clar unit testing frameworkPatrick Steinhardt
Wire up the clar unit testing framework by introducing a new "unit-tests" executable. In contrast to the existing framework, this will result in a single executable for all test suites. The ability to pick specific tests to execute is retained via functionality built into the clar itself. Note that we need to be a bit careful about how we need to invalidate our Makefile rules. While we obviously have to regenerate the clar suite when our test suites change, we also have to invalidate it in case any of the test suites gets removed. We do so by using our typical pattern of creating a `GIT-TEST-SUITES` file that gets updated whenever the set of test suites changes, so that we can easily depend on that file. Another specialty is that we generate a "clar-decls.h" file. The test functions are neither static, nor do they have external declarations. This is because they are getting parsed via "generate.py", which then creates the external generations that get populated into an array. These declarations are only seen by the main function though. The consequence is that we will get a bunch of "missing prototypes" errors from our compiler for each of these test functions. To fix those errors, we extract the `extern` declarations from "clar.suite" and put them into a standalone header that then gets included by each of our unit tests. This gets rid of compiler warnings for every function which has been extracted by "generate.py". More importantly though, it does _not_ get rid of warnings in case a function really isn't being used by anything. Thus, it would cause a compiler error if a function name was mistyped and thus not picked up by "generate.py". The test driver "unit-test.c" is an empty stub for now. It will get implemented in the next commit. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>