aboutsummaryrefslogtreecommitdiff
path: root/unittests/helpers.py
diff options
context:
space:
mode:
authorNirbheek Chauhan <nirbheek@centricular.com>2022-01-16 16:01:33 +0530
committerNirbheek Chauhan <nirbheek.chauhan@gmail.com>2022-01-16 23:42:19 +0530
commitfaf79f4539841cbf89fe8d53cf35aa91fd8273c9 (patch)
treed6d4eaf7caae6681714cc97c56dd2ff1b73e5329 /unittests/helpers.py
parent1cda222a1a5faf98bf5c72bc103307bf76f76f7f (diff)
downloadmeson-faf79f4539841cbf89fe8d53cf35aa91fd8273c9.zip
meson-faf79f4539841cbf89fe8d53cf35aa91fd8273c9.tar.gz
meson-faf79f4539841cbf89fe8d53cf35aa91fd8273c9.tar.bz2
Add a test for the --vsenv meson setup option
The tests and the unittests both unconditionally call setup_vsenv() because all tests are run using the backend commands directly: ninja, msbuild, etc. There's no way to undo this vs env setup, so the only way to test that --vsenv works is by: 1. Removing all paths in PATH that provide ninja 2. Changing setup_vsenv(force=True) to forcibly set-up a new vsenv when MESON_FORCE_VSENV_FOR_UNITTEST is set 3. Mock-patching build_command, test_command, install_command to use `meson` instead of `ninja` 4. Asserting that 'Activating VS' is in the output for all commands 5. Ensure that compilation works because ninja is picked up from the vs env. I manually checked that this test actually does fail when the previous commit is reverted.
Diffstat (limited to 'unittests/helpers.py')
-rw-r--r--unittests/helpers.py16
1 files changed, 15 insertions, 1 deletions
diff --git a/unittests/helpers.py b/unittests/helpers.py
index b759dba..bf06bdc 100644
--- a/unittests/helpers.py
+++ b/unittests/helpers.py
@@ -5,11 +5,13 @@ import unittest
import functools
import re
import typing as T
+from pathlib import Path
from contextlib import contextmanager
from mesonbuild.compilers import detect_c_compiler, compiler_from_language
from mesonbuild.mesonlib import (
- MachineChoice, is_osx, is_cygwin, EnvironmentException, OptionKey, MachineChoice
+ MachineChoice, is_osx, is_cygwin, EnvironmentException, OptionKey, MachineChoice,
+ OrderedSet
)
from run_tests import get_fake_env
@@ -170,3 +172,15 @@ def get_rpath(fname: str) -> T.Optional[str]:
# don't check for, so clear those
final = ':'.join([e for e in raw.split(':') if not e.startswith('/nix')])
return final
+
+def get_path_without_cmd(cmd: str, path: str) -> str:
+ pathsep = os.pathsep
+ paths = OrderedSet([Path(p).resolve() for p in path.split(pathsep)])
+ while True:
+ full_path = shutil.which(cmd, path=path)
+ if full_path is None:
+ break
+ dirname = Path(full_path).resolve().parent
+ paths.discard(dirname)
+ path = pathsep.join([str(p) for p in paths])
+ return path