mirror of
https://github.com/morgan9e/systemd
synced 2026-04-14 08:25:20 +09:00
test: use ASSERT_OK_ERRNO() for setenv() and unsetenv()
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user