test: use ${builddir}/systemd-runtest.env to set $SYSTEMD_TEST_DATA
authorFilipe Brandenburger <filbranden@google.com>
Wed, 12 Sep 2018 06:55:02 +0000 (23:55 -0700)
committerPeter Michael Green <plugwash@raspbian.org>
Thu, 20 Sep 2018 20:22:45 +0000 (21:22 +0100)
commitf82e700c85f08d8cf781e6536104872da0166d0a
treedabc9edaa71316d7fe8e621030913e9b8d263e72
parenta8ebec8169b1ee2f7e6e3fffbb246cef0c92edc1
test: use ${builddir}/systemd-runtest.env to set $SYSTEMD_TEST_DATA

This simplifies get_testdata_dir() to simply checking for an environment
variable, with an additional function to locate a systemd-runtest.env file in
the same directory as the test binary and reading environment variable
assignments from that file if it exists.

This makes it possible to:
- Run `ninja test` from the build dir and have it use ${srcdir}/test for
  test unit definitions.
- Run a test directly, such as `build/test-execute` and have it locate
  them correctly.
- Run installed tests (from systemd-tests package) and locate the test
  units in the installed location (/usr/lib/systemd/tests/testdata), in
  which case the absence of the systemd-runtest.env file will have
  get_testdata_dir() use the installed location hardcoded into the
  binaries.

Explicit setting of $SYSTEMD_TEST_DATA still overrides the contents of
systemd-runtest.env.

(cherry picked from commit e2d413707fc68ed033a83e10a055ca638a1e1e18)

Gbp-Pq: Name test-use-builddir-systemd-runtest.env-to-set-SYSTEMD_TEST.patch
meson.build
src/shared/tests.c