summaryrefslogtreecommitdiffstats
path: root/src/test/test-sleep.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2022-02-01 12:06:59 +0100
committerYu Watanabe <watanabe.yu+github@gmail.com>2022-02-02 03:00:16 +0100
commit99839c7ebd4b83a5b0d5982d669cfe10d1252e1f (patch)
tree233ee8eda2a42e35af272157afddbc5c15fa3a4d /src/test/test-sleep.c
parentnetwork: dhcp-server: make empty string to DNS= or friends clear previously s... (diff)
downloadsystemd-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.c15
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);