diff options
author | Lennart Poettering <lennart@poettering.net> | 2022-02-01 12:06:59 +0100 |
---|---|---|
committer | Yu Watanabe <watanabe.yu+github@gmail.com> | 2022-02-02 03:00:16 +0100 |
commit | 99839c7ebd4b83a5b0d5982d669cfe10d1252e1f (patch) | |
tree | 233ee8eda2a42e35af272157afddbc5c15fa3a4d /src/test/test-sleep.c | |
parent | network: dhcp-server: make empty string to DNS= or friends clear previously s... (diff) | |
download | systemd-99839c7ebd4b83a5b0d5982d669cfe10d1252e1f.tar.xz systemd-99839c7ebd4b83a5b0d5982d669cfe10d1252e1f.zip |
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.)
Diffstat (limited to 'src/test/test-sleep.c')
-rw-r--r-- | src/test/test-sleep.c | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/src/test/test-sleep.c b/src/test/test-sleep.c index 183ad4f7b7..f56e7e0167 100644 --- a/src/test/test-sleep.c +++ b/src/test/test-sleep.c @@ -118,10 +118,11 @@ TEST(sleep) { log_info("Suspend-then-Hibernate configured and possible: %s", r >= 0 ? yes_no(r) : strerror_safe(r)); } -DEFINE_CUSTOM_TEST_MAIN( - LOG_DEBUG, - ({ - if (getuid() != 0) - log_warning("This program is unlikely to work for unprivileged users"); - }), - /* no outro */); +static int intro(void) { + if (getuid() != 0) + log_warning("This program is unlikely to work for unprivileged users"); + + return EXIT_SUCCESS; +} + +DEFINE_CUSTOM_TEST_MAIN(LOG_DEBUG, intro, test_nop); |