test: use ${builddir}/systemd-runtest.env for $SYSTEMD_CATALOG_DIR
This makes it so that tests no longer need to know the absolute paths to the source and build dirs, instead using the systemd-runtest.env file to get these paths when running from the build tree. Confirmed that test-catalog works on `ninja test`, when called standalone and also when the environment file is not present, in which case it will use the installed location under /usr/lib/systemd/catalog. The location can now also be overridden for this test by setting the $SYSTEMD_CATALOG_DIR environment variable.
This commit is contained in:
+16
-6
@@ -44,12 +44,6 @@ static void load_testdata_env(void) {
|
||||
setenv(*k, *v, 0);
|
||||
}
|
||||
|
||||
bool test_is_running_from_builddir(char **exedir) {
|
||||
load_testdata_env();
|
||||
|
||||
return !!getenv("SYSTEMD_TEST_DATA");
|
||||
}
|
||||
|
||||
const char* get_testdata_dir(void) {
|
||||
const char *env;
|
||||
|
||||
@@ -66,3 +60,19 @@ const char* get_testdata_dir(void) {
|
||||
|
||||
return env;
|
||||
}
|
||||
|
||||
const char* get_catalog_dir(void) {
|
||||
const char *env;
|
||||
|
||||
load_testdata_env();
|
||||
|
||||
/* if the env var is set, use that */
|
||||
env = getenv("SYSTEMD_CATALOG_DIR");
|
||||
if (!env)
|
||||
env = SYSTEMD_CATALOG_DIR;
|
||||
if (access(env, F_OK) < 0) {
|
||||
fprintf(stderr, "ERROR: $SYSTEMD_CATALOG_DIR directory [%s] does not exist\n", env);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
return env;
|
||||
}
|
||||
|
||||
+1
-1
@@ -2,5 +2,5 @@
|
||||
#pragma once
|
||||
|
||||
char* setup_fake_runtime_dir(void);
|
||||
bool test_is_running_from_builddir(char **exedir);
|
||||
const char* get_testdata_dir(void);
|
||||
const char* get_catalog_dir(void);
|
||||
|
||||
Reference in New Issue
Block a user