]> git.ipfire.org Git - thirdparty/systemd.git/commit
tests: rework test macros to not take code as parameters
authorLennart Poettering <lennart@poettering.net>
Tue, 1 Feb 2022 11:06:59 +0000 (12:06 +0100)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 2 Feb 2022 02:00:16 +0000 (11:00 +0900)
commit99839c7ebd4b83a5b0d5982d669cfe10d1252e1f
tree233ee8eda2a42e35af272157afddbc5c15fa3a4d
parentfaa1b3c6c415abb201d03ab1c46f9e89100ab9b2
tests: rework test macros to not take code as parameters

C macros are nasty. We use them, but we try to be conservative with
them. In particular passing literal, complex code blocks as argument is
icky, because of "," handling of C, and also because it's quite a
challange for most code highlighters and similar. Hence, let's avoid
that. Using macros for genreating functions is OK but if so, the
parameters should be simple words, not full code blocks.

hence, rework DEFINE_CUSTOM_TEST_MAIN() to take a function name instead
of code block as argument.

As side-effect this also fixes a bunch of cases where we might end up
returning a negative value from main().

Some uses of DEFINE_CUSTOM_TEST_MAIN() inserted local variables into the
main() functions, these are replaced by static variables, and their
destructors by the static destructor logic.

This doesn't fix any bugs or so, it's just supposed to make the code
easier to work with and improve it easthetically.

Or in other words: let's use macros where it really makes sense, but
let's not go overboard with it.

(And yes, FOREACH_DIRENT() is another one of those macros that take
code, and I dislike that too and regret I ever added that.)
22 files changed:
src/shared/tests.h
src/test/test-barrier.c
src/test/test-cgroup-setup.c
src/test/test-chown-rec.c
src/test/test-format-table.c
src/test/test-fs-util.c
src/test/test-hashmap.c
src/test/test-install-root.c
src/test/test-load-fragment.c
src/test/test-mountpoint-util.c
src/test/test-namespace.c
src/test/test-proc-cmdline.c
src/test/test-process-util.c
src/test/test-sd-hwdb.c
src/test/test-serialize.c
src/test/test-sleep.c
src/test/test-stat-util.c
src/test/test-time-util.c
src/test/test-unit-file.c
src/test/test-unit-name.c
src/test/test-unit-serialize.c
src/test/test-utf8.c