test: make unit tests relocatable

It is useful to package test-* binaries and run them as root under
autopkgtest or manually on particular machines. They currently have a
built-in hardcoded absolute path to their test data, which does not work
when running the test programs from any other path than the original
build directory.

By default, make the tests look for their data in
<test_exe_directory>/testdata/ so that they can be called from any
directory (provided that the corresponding test data is installed
correctly). As we don't have a fixed static path in the build tree (as
build and source tree are independent), set $TEST_DIR with "make check"
to point to <srcdir>/test/, as we previously did with an automake
variable.
This commit is contained in:
Martin Pitt
2017-02-13 22:31:13 +01:00
parent ee3c7ff7c3
commit f853c6efb5
10 changed files with 30 additions and 8 deletions
+1 -1
View File
@@ -40,7 +40,7 @@ int main(int argc, char *argv[]) {
assert_se(runtime_dir = setup_fake_runtime_dir());
/* prepare the test */
assert_se(set_unit_path(TEST_DIR) >= 0);
assert_se(set_unit_path(TEST_DATA_DIR("")) >= 0);
r = manager_new(UNIT_FILE_USER, true, &m);
if (MANAGER_SKIP_TEST(r)) {
log_notice_errno(r, "Skipping test: manager_new: %m");