diff options
author | Yu Watanabe <watanabe.yu+github@gmail.com> | 2024-08-01 08:58:30 +0200 |
---|---|---|
committer | Yu Watanabe <watanabe.yu+github@gmail.com> | 2024-08-01 15:42:08 +0200 |
commit | fea2f92d8d8eb367547314f7dba9476d4cfe3899 (patch) | |
tree | bfdfa34942a991a6e080bd85dfdaebfe9150ce74 | |
parent | test: resolve "Unchecked return value" coverity warning (diff) | |
download | systemd-fea2f92d8d8eb367547314f7dba9476d4cfe3899.tar.xz systemd-fea2f92d8d8eb367547314f7dba9476d4cfe3899.zip |
test: use ASSERT_OK_ERRNO() for setenv() and unsetenv()
-rw-r--r-- | src/test/test-calendarspec.c | 2 | ||||
-rw-r--r-- | src/test/test-cgroup-setup.c | 30 | ||||
-rw-r--r-- | src/test/test-os-util.c | 12 | ||||
-rw-r--r-- | src/test/test-terminal-util.c | 8 |
4 files changed, 26 insertions, 26 deletions
diff --git a/src/test/test-calendarspec.c b/src/test/test-calendarspec.c index 7cda114de6..f13d982e10 100644 --- a/src/test/test-calendarspec.c +++ b/src/test/test-calendarspec.c @@ -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; } diff --git a/src/test/test-cgroup-setup.c b/src/test/test-cgroup-setup.c index 8b5d02d5b7..af5712060b 100644 --- a/src/test/test-cgroup-setup.c +++ b/src/test/test-cgroup-setup.c @@ -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); } diff --git a/src/test/test-os-util.c b/src/test/test-os-util.c index 55475a56ae..74802a23b3 100644 --- a/src/test/test-os-util.c +++ b/src/test/test-os-util.c @@ -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) { diff --git a/src/test/test-terminal-util.c b/src/test/test-terminal-util.c index f1e04ae632..9e87c4d195 100644 --- a/src/test/test-terminal-util.c +++ b/src/test/test-terminal-util.c @@ -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); |