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)
committerFelipe Sateler <fsateler@debian.org>
Thu, 6 Dec 2018 00:03:34 +0000 (00:03 +0000)
commitf47e9afb0e08e716500c9574a6d59d9cab82a819
treee8beb244f4b214fdc66988e07da1bdebb3ef6617
parent11ad51e3f03c3a39ace66318a556b696a8dccbaf
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