4a90ac9ee1b3ac5d3861a890a1f0384a9ed42ff4
[tinc] / test / integration / testlib / path.py
1 """Paths to compiled binaries, and a few other important environment variables."""
2
3 import os
4 import pathlib
5 import sys
6
7 env = {
8     "TEST_NAME": os.getenv("TEST_NAME"),
9     "TINC_PATH": os.getenv("TINC_PATH"),
10     "TINCD_PATH": os.getenv("TINCD_PATH"),
11     "SPLICE_PATH": os.getenv("SPLICE_PATH"),
12     "PYTHON_PATH": os.getenv("PYTHON_PATH"),
13     "SPTPS_TEST_PATH": os.getenv("SPTPS_TEST_PATH"),
14     "SPTPS_KEYPAIR_PATH": os.getenv("SPTPS_KEYPAIR_PATH"),
15 }
16
17 # Not strictly necessary, used for better autocompletion and search by reference.
18 TEST_NAME = str(env["TEST_NAME"])
19 TINC_PATH = str(env["TINC_PATH"])
20 TINCD_PATH = str(env["TINCD_PATH"])
21 SPLICE_PATH = str(env["SPLICE_PATH"])
22 PYTHON_PATH = str(env["PYTHON_PATH"])
23 SPTPS_TEST_PATH = str(env["SPTPS_TEST_PATH"])
24 SPTPS_KEYPAIR_PATH = str(env["SPTPS_KEYPAIR_PATH"])
25
26 PYTHON_CMD = "runpython" if "meson.exe" in PYTHON_PATH.lower() else ""
27
28
29 def _check() -> bool:
30     """Basic sanity checks on passed environment variables."""
31     for key, val in env.items():
32         if not val or (key != "TEST_NAME" and not os.path.isfile(val)):
33             return False
34     return True
35
36
37 if not _check():
38     MSG = """
39 Please run tests using
40     $ meson test -C build
41 or
42     $ ninja -C build test
43 """
44     print(MSG, file=sys.stderr)
45     sys.exit(1)
46
47 # Current working directory
48 CWD = os.getcwd()
49
50 # Path to the testing library
51 TESTLIB_ROOT = pathlib.Path(__file__).parent
52
53 # Source root for the integration test suite
54 TEST_SRC_ROOT = TESTLIB_ROOT.parent.resolve()
55
56 _wd = os.path.join(CWD, "wd")
57 os.makedirs(_wd, exist_ok=True)
58
59 # Useful when running tests manually
60 _gitignore = os.path.join(_wd, ".gitignore")
61 if not os.path.exists(_gitignore):
62     with open(_gitignore, "w", encoding="utf-8") as f:
63         f.write("*")
64
65 # Working directory for this test
66 TEST_WD = os.path.join(_wd, TEST_NAME)