Commit d5e3695ea29dc822d990121ebbf06bffb8a3247d

Peter Hutterer 2021-01-22T08:05:09

test: fill in srcdir/builddir when not set in the environment Makes this test easier to run from the commandline. Where either of top_srcdir or top_builddir isn't set, fill them in from the CWD or fail otherwise. Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>

diff --git a/test/tool-option-parsing.py b/test/tool-option-parsing.py
index a2072b3..9b7d008 100755
--- a/test/tool-option-parsing.py
+++ b/test/tool-option-parsing.py
@@ -31,8 +31,19 @@ import tempfile
 import unittest
 
 
-top_builddir = os.environ['top_builddir']
-top_srcdir = os.environ['top_srcdir']
+try:
+    top_builddir = os.environ['top_builddir']
+    top_srcdir = os.environ['top_srcdir']
+except KeyError:
+    print('Required environment variables not found: top_srcdir/top_builddir', file=sys.stderr)
+    from pathlib import Path
+    top_srcdir = '.'
+    try:
+        top_builddir = next(Path('.').glob('**/meson-logs/')).parent
+    except StopIteration:
+        sys.exit(1)
+    print('Using srcdir "{}", builddir "{}"'.format(top_srcdir, top_builddir), file=sys.stderr)
+
 
 logging.basicConfig(level=logging.DEBUG)
 logger = logging.getLogger('test')