1
1
mirror of https://github.com/systemd/systemd-stable.git synced 2025-02-09 09:57:26 +03:00

tests: modernize load_testdata_env() a bit

Let's add assert() around everyhing we don't expect to fail.

Port to path_extract_directory().

Log errrors from load_env_file_pairs() which we ignore.
This commit is contained in:
Lennart Poettering 2022-04-01 10:52:47 +02:00
parent 5b89bff55f
commit 8419213d99

View File

@ -48,23 +48,26 @@ char* setup_fake_runtime_dir(void) {
static void load_testdata_env(void) {
static bool called = false;
_cleanup_free_ char *s = NULL;
_cleanup_free_ char *envpath = NULL;
_cleanup_free_ char *s = NULL, *d = NULL, *envpath = NULL;
_cleanup_strv_free_ char **pairs = NULL;
int r;
if (called)
return;
called = true;
assert_se(readlink_and_make_absolute("/proc/self/exe", &s) >= 0);
dirname(s);
assert_se(path_extract_directory(s, &d) >= 0);
assert_se(envpath = path_join(d, "systemd-runtest.env"));
envpath = path_join(s, "systemd-runtest.env");
if (load_env_file_pairs(NULL, envpath, &pairs) < 0)
r = load_env_file_pairs(NULL, envpath, &pairs);
if (r < 0) {
log_debug_errno(r, "Reading %s failed: %m", envpath);
return;
}
STRV_FOREACH_PAIR(k, v, pairs)
setenv(*k, *v, 0);
assert_se(setenv(*k, *v, 0) >= 0);
}
int get_testdata_dir(const char *suffix, char **ret) {