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)
committerMichael Biebl <biebl@debian.org>
Wed, 12 Sep 2018 17:07:38 +0000 (18:07 +0100)
commit2f2169a39dc104d261a206c4f70f0dfec77ae34a
treefceeb84fc9d6c1527bb3d4c64791ee0990491666
parent2e904236cf54d32c5ea191fd9f8618921c2239b7
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