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 22:47:19 +0000 (23:47 +0100)
commit37e11f0c1c1549e15f898d62c1d6a120acd21f28
tree89f40aa128b1fab49dd7169e2a409067cf3eb85d
parent4bbb913f3f405a5ade0f367b1426dc533df22f00
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