summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Pitt <martin@piware.de>2017-02-15 08:52:17 +0100
committerMartin Pitt <martin@piware.de>2017-02-16 21:36:31 +0100
commitc60b6ddafbd462378073f85e4690455fc3908ad2 (patch)
tree2e60f70d2f78d352e1be0196b55706f90b6177be
parent1f35a3b2a4a6bdc97c0eacfee208e05b2f67f523 (diff)
test: show error message if $SYSTEMD_TEST_DATA does not exist
Rename get_exe_relative_testdata_dir() to get_testdata_dir() and move the env var check into that, so that everything interesting happens at the same place.
-rw-r--r--src/shared/tests.c13
-rw-r--r--src/shared/tests.h2
-rw-r--r--src/test/test-helper.h4
3 files changed, 15 insertions, 4 deletions
diff --git a/src/shared/tests.c b/src/shared/tests.c
index f11b93bee7..be098b304c 100644
--- a/src/shared/tests.c
+++ b/src/shared/tests.c
@@ -36,11 +36,22 @@ char* setup_fake_runtime_dir(void) {
return p;
}
-const char* get_exe_relative_testdata_dir(void) {
+const char* get_testdata_dir(void) {
+ const char *env;
_cleanup_free_ char *exedir = NULL;
/* convenience: caller does not need to free result */
static char testdir[PATH_MAX];
+ /* if the env var is set, use that */
+ env = getenv("SYSTEMD_TEST_DATA");
+ if (env) {
+ if (access(env, F_OK) >= 0)
+ return env;
+
+ fputs("ERROR: $SYSTEMD_TEST_DATA directory does not exist\n", stderr);
+ exit(1);
+ }
+
assert_se(readlink_and_make_absolute("/proc/self/exe", &exedir) >= 0);
/* Check if we're running from the builddir. If so, use the compiled in path. */
diff --git a/src/shared/tests.h b/src/shared/tests.h
index 0100b48937..927b9fc2bb 100644
--- a/src/shared/tests.h
+++ b/src/shared/tests.h
@@ -20,4 +20,4 @@
***/
char* setup_fake_runtime_dir(void);
-const char* get_exe_relative_testdata_dir(void);
+const char* get_testdata_dir(void);
diff --git a/src/test/test-helper.h b/src/test/test-helper.h
index 02608434be..7c9eff2483 100644
--- a/src/test/test-helper.h
+++ b/src/test/test-helper.h
@@ -42,5 +42,5 @@
-ENOMEDIUM /* cannot determine cgroup */ \
)
-#define TEST_DATA_DIR(subdir) \
- strjoina(getenv("SYSTEMD_TEST_DATA") ?: get_exe_relative_testdata_dir(), subdir)
+#define TEST_DATA_DIR(subdir) \
+ strjoina(get_testdata_dir(), subdir)