summaryrefslogtreecommitdiff
path: root/src/test/test-load-fragment.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 11:00:16 +0900
commit99839c7ebd4b83a5b0d5982d669cfe10d1252e1f (patch)
tree233ee8eda2a42e35af272157afddbc5c15fa3a4d /src/test/test-load-fragment.c
parentfaa1b3c6c415abb201d03ab1c46f9e89100ab9b2 (diff)
downloadsystemd-99839c7ebd4b83a5b0d5982d669cfe10d1252e1f.tar.gz
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-load-fragment.c')
-rw-r--r--src/test/test-load-fragment.c21
1 files changed, 11 insertions, 10 deletions
diff --git a/src/test/test-load-fragment.c b/src/test/test-load-fragment.c
index 9e5ae85597..554bb206dc 100644
--- a/src/test/test-load-fragment.c
+++ b/src/test/test-load-fragment.c
@@ -30,6 +30,10 @@
/* Nontrivial value serves as a placeholder to check that parsing function (didn't) change it */
#define CGROUP_LIMIT_DUMMY 3
+static char *runtime_dir = NULL;
+
+STATIC_DESTRUCTOR_REGISTER(runtime_dir, rm_rf_physical_and_freep);
+
TEST_RET(unit_file_get_set) {
int r;
Hashmap *h;
@@ -958,15 +962,12 @@ TEST(unit_is_recursive_template_dependency) {
assert_se(unit_is_likely_recursive_template_dependency(u, "foobar@foobar@123.mount", "foobar@%n.mount") == 0);
}
-DEFINE_CUSTOM_TEST_MAIN(
- LOG_INFO,
+static int intro(void) {
+ if (enter_cgroup_subroot(NULL) == -ENOMEDIUM)
+ return log_tests_skipped("cgroupfs not available");
- _cleanup_(rm_rf_physical_and_freep) char *runtime_dir = NULL;
- ({
- if (enter_cgroup_subroot(NULL) == -ENOMEDIUM)
- return log_tests_skipped("cgroupfs not available");
-
- assert_se(runtime_dir = setup_fake_runtime_dir());
- }),
+ assert_se(runtime_dir = setup_fake_runtime_dir());
+ return EXIT_SUCCESS;
+}
- /* no outro */);
+DEFINE_CUSTOM_TEST_MAIN(LOG_INFO, intro, test_nop);