]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
test: use ASSERT_OK_ERRNO() for setenv() and unsetenv()
authorYu Watanabe <watanabe.yu+github@gmail.com>
Thu, 1 Aug 2024 06:58:30 +0000 (15:58 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Thu, 1 Aug 2024 13:42:08 +0000 (22:42 +0900)
src/test/test-calendarspec.c
src/test/test-cgroup-setup.c
src/test/test-os-util.c
src/test/test-terminal-util.c

index 7cda114de6b1417b2f275af1419d33ce29258e4c..f13d982e10c8e8de0e9d998f4434aa67abb30282 100644 (file)
@@ -256,7 +256,7 @@ TEST(calendar_spec_from_string) {
 
 static int intro(void) {
         /* Tests have hard-coded results that do not expect a specific timezone to be set by the caller */
-        ASSERT_OK(unsetenv("TZ"));
+        ASSERT_OK_ERRNO(unsetenv("TZ"));
 
         return EXIT_SUCCESS;
 }
index 8b5d02d5b79089638f0c51eb615d08fe3bfbd0ae..af5712060bf58dea3dec3005dad5422f2cf68810 100644 (file)
@@ -31,33 +31,33 @@ TEST(is_wanted_print) {
 }
 
 TEST(is_wanted) {
-        ASSERT_OK(setenv("SYSTEMD_PROC_CMDLINE",
-                         "systemd.unified_cgroup_hierarchy", 1));
+        ASSERT_OK_ERRNO(setenv("SYSTEMD_PROC_CMDLINE",
+                               "systemd.unified_cgroup_hierarchy", 1));
         test_is_wanted_print_one(false);
 
-        ASSERT_OK(setenv("SYSTEMD_PROC_CMDLINE",
-                         "systemd.unified_cgroup_hierarchy=0", 1));
+        ASSERT_OK_ERRNO(setenv("SYSTEMD_PROC_CMDLINE",
+                               "systemd.unified_cgroup_hierarchy=0", 1));
         test_is_wanted_print_one(false);
 
-        ASSERT_OK(setenv("SYSTEMD_PROC_CMDLINE",
-                         "systemd.unified_cgroup_hierarchy=0 "
-                         "systemd.legacy_systemd_cgroup_controller", 1));
+        ASSERT_OK_ERRNO(setenv("SYSTEMD_PROC_CMDLINE",
+                               "systemd.unified_cgroup_hierarchy=0 "
+                               "systemd.legacy_systemd_cgroup_controller", 1));
         test_is_wanted_print_one(false);
 
-        ASSERT_OK(setenv("SYSTEMD_PROC_CMDLINE",
-                         "systemd.unified_cgroup_hierarchy=0 "
-                         "systemd.legacy_systemd_cgroup_controller=0", 1));
+        ASSERT_OK_ERRNO(setenv("SYSTEMD_PROC_CMDLINE",
+                               "systemd.unified_cgroup_hierarchy=0 "
+                               "systemd.legacy_systemd_cgroup_controller=0", 1));
         test_is_wanted_print_one(false);
 
         /* cgroup_no_v1=all implies unified cgroup hierarchy, unless otherwise
          * explicitly specified. */
-        ASSERT_OK(setenv("SYSTEMD_PROC_CMDLINE",
-                         "cgroup_no_v1=all", 1));
+        ASSERT_OK_ERRNO(setenv("SYSTEMD_PROC_CMDLINE",
+                               "cgroup_no_v1=all", 1));
         test_is_wanted_print_one(false);
 
-        ASSERT_OK(setenv("SYSTEMD_PROC_CMDLINE",
-                         "cgroup_no_v1=all "
-                         "systemd.unified_cgroup_hierarchy=0", 1));
+        ASSERT_OK_ERRNO(setenv("SYSTEMD_PROC_CMDLINE",
+                               "cgroup_no_v1=all "
+                               "systemd.unified_cgroup_hierarchy=0", 1));
         test_is_wanted_print_one(false);
 }
 
index 55475a56ae96d734315864ce7c97db4829d31bf5..74802a23b38106ac1b33f89f04dd006733881fc0 100644 (file)
@@ -27,7 +27,7 @@ TEST(parse_os_release) {
                 log_info("ID: %s", id);
         }
 
-        ASSERT_EQ(setenv("SYSTEMD_OS_RELEASE", "/dev/null", 1), 0);
+        ASSERT_OK_ERRNO(setenv("SYSTEMD_OS_RELEASE", "/dev/null", 1));
         ASSERT_EQ(parse_os_release(NULL, "ID", &id2), 0);
         log_info("ID: %s", strnull(id2));
 
@@ -36,7 +36,7 @@ TEST(parse_os_release) {
                                 "ID=the-id  \n"
                                 "NAME=the-name"), 0);
 
-        ASSERT_EQ(setenv("SYSTEMD_OS_RELEASE", tmpfile, 1), 0);
+        ASSERT_OK_ERRNO(setenv("SYSTEMD_OS_RELEASE", tmpfile, 1));
         ASSERT_EQ(parse_os_release(NULL, "ID", &id, "NAME", &name), 0);
         log_info("ID: %s NAME: %s", id, name);
         ASSERT_STREQ(id, "the-id");
@@ -48,7 +48,7 @@ TEST(parse_os_release) {
                                 "ID=\"the-id\"  \n"
                                 "NAME='the-name'"), 0);
 
-        ASSERT_EQ(setenv("SYSTEMD_OS_RELEASE", tmpfile2, 1), 0);
+        ASSERT_OK_ERRNO(setenv("SYSTEMD_OS_RELEASE", tmpfile2, 1));
         ASSERT_EQ(parse_os_release(NULL, "ID", &id, "NAME", &name), 0);
         log_info("ID: %s NAME: %s", id, name);
         ASSERT_STREQ(id, "the-id");
@@ -58,7 +58,7 @@ TEST(parse_os_release) {
         log_info("FOOBAR: %s", strnull(foobar));
         ASSERT_NULL(foobar);
 
-        assert_se(unsetenv("SYSTEMD_OS_RELEASE") == 0);
+        ASSERT_OK_ERRNO(unsetenv("SYSTEMD_OS_RELEASE"));
 }
 
 TEST(parse_extension_release) {
@@ -111,14 +111,14 @@ TEST(load_os_release_pairs) {
                                 "ID=\"the-id\"  \n"
                                 "NAME='the-name'"), 0);
 
-        ASSERT_EQ(setenv("SYSTEMD_OS_RELEASE", tmpfile, 1), 0);
+        ASSERT_OK_ERRNO(setenv("SYSTEMD_OS_RELEASE", tmpfile, 1));
 
         _cleanup_strv_free_ char **pairs = NULL;
         ASSERT_EQ(load_os_release_pairs(NULL, &pairs), 0);
         assert_se(strv_equal(pairs, STRV_MAKE("ID", "the-id",
                                               "NAME", "the-name")));
 
-        ASSERT_EQ(unsetenv("SYSTEMD_OS_RELEASE"), 0);
+        ASSERT_OK_ERRNO(unsetenv("SYSTEMD_OS_RELEASE"));
 }
 
 TEST(os_release_support_ended) {
index f1e04ae632098dad27e2204b979f2307979680c4..9e87c4d195f1f057857960c6774d9a4a04f225b4 100644 (file)
@@ -251,7 +251,7 @@ TEST(terminal_is_pty_fd) {
 }
 
 static void test_get_color_mode_with_env(const char *key, const char *val, ColorMode expected) {
-        ASSERT_OK(setenv(key, val, true));
+        ASSERT_OK_ERRNO(setenv(key, val, true));
         reset_terminal_feature_caches();
         log_info("get_color_mode($%s=%s): %s", key, val, color_mode_to_string(get_color_mode()));
         ASSERT_EQ(get_color_mode(), expected);
@@ -269,11 +269,11 @@ TEST(get_color_mode) {
         test_get_color_mode_with_env("SYSTEMD_COLORS", "yes",   COLOR_24BIT);
         test_get_color_mode_with_env("SYSTEMD_COLORS", "24bit", COLOR_24BIT);
 
-        ASSERT_OK(setenv("NO_COLOR", "1", true));
+        ASSERT_OK_ERRNO(setenv("NO_COLOR", "1", true));
         test_get_color_mode_with_env("SYSTEMD_COLORS", "42",      COLOR_OFF);
         test_get_color_mode_with_env("SYSTEMD_COLORS", "invalid", COLOR_OFF);
-        ASSERT_OK(unsetenv("NO_COLOR"));
-        ASSERT_OK(unsetenv("SYSTEMD_COLORS"));
+        ASSERT_OK_ERRNO(unsetenv("NO_COLOR"));
+        ASSERT_OK_ERRNO(unsetenv("SYSTEMD_COLORS"));
 
         test_get_color_mode_with_env("COLORTERM", "truecolor", terminal_is_dumb() ? COLOR_OFF : COLOR_24BIT);
         test_get_color_mode_with_env("COLORTERM", "24bit",     terminal_is_dumb() ? COLOR_OFF : COLOR_24BIT);