summaryrefslogtreecommitdiff
path: root/src/shared/tests.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/shared/tests.c')
-rw-r--r--src/shared/tests.c17
1 files changed, 12 insertions, 5 deletions
diff --git a/src/shared/tests.c b/src/shared/tests.c
index bae113bdc8..f11b93bee7 100644
--- a/src/shared/tests.c
+++ b/src/shared/tests.c
@@ -24,6 +24,7 @@
#include <util.h>
#include "tests.h"
+#include "path-util.h"
char* setup_fake_runtime_dir(void) {
char t[] = "/tmp/fake-xdg-runtime-XXXXXX", *p;
@@ -41,10 +42,16 @@ const char* get_exe_relative_testdata_dir(void) {
static char testdir[PATH_MAX];
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. */
+ if (path_startswith(exedir, ABS_BUILD_DIR))
+ return ABS_SRC_DIR "/test";
+
+ /* Try relative path, according to the install-test layout */
assert_se(snprintf(testdir, sizeof(testdir), "%s/testdata", dirname(exedir)) > 0);
- if (access(testdir, F_OK) < 0) {
- fprintf(stderr, "Test data directory '%s' does not exist, set $SYSTEMD_TEST_DATA\n", testdir);
- exit(1);
- }
- return testdir;
+ if (access(testdir, F_OK) >= 0)
+ return testdir;
+
+ fputs("ERROR: Cannot find testdata directory, set $SYSTEMD_TEST_DATA\n", stderr);
+ exit(1);
}