test: fill in srcdir/builddir when not set in the environment
authorPeter Hutterer <peter.hutterer@who-t.net>
Thu, 21 Jan 2021 22:05:09 +0000 (08:05 +1000)
committerRan Benita <ran@unusedvar.com>
Sat, 23 Jan 2021 16:57:23 +0000 (18:57 +0200)
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>
test/tool-option-parsing.py

index a2072b3..9b7d008 100755 (executable)
@@ -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')