aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNirbheek Chauhan <nirbheek@centricular.com>2019-01-29 23:25:17 +0530
committerNirbheek Chauhan <nirbheek.chauhan@gmail.com>2019-01-31 20:12:21 +0530
commit3997e8762ef057d1cb89c0d68d068a3aaf5e0450 (patch)
tree335fc0d267440c8f413540144bdb3f4f63c284f1
parent58852e62905684343e1219ecef1b632c54816507 (diff)
downloadmeson-3997e8762ef057d1cb89c0d68d068a3aaf5e0450.zip
meson-3997e8762ef057d1cb89c0d68d068a3aaf5e0450.tar.gz
meson-3997e8762ef057d1cb89c0d68d068a3aaf5e0450.tar.bz2
unit tests: Fix sdl2 failure test on macOS
Also ensure that the test's no-pkg-config codepath will always be run, even on the CI where we always have pkg-config available. This counts as a test case for #4728
-rwxr-xr-xrun_tests.py8
-rwxr-xr-xrun_unittests.py35
2 files changed, 38 insertions, 5 deletions
diff --git a/run_tests.py b/run_tests.py
index 7f85be6..2805375 100755
--- a/run_tests.py
+++ b/run_tests.py
@@ -213,6 +213,13 @@ def run_mtest_inprocess(commandlist):
sys.stderr = old_stderr
return returncode, mystdout.getvalue(), mystderr.getvalue()
+def clear_meson_configure_class_caches():
+ mesonbuild.compilers.CCompiler.library_dirs_cache = {}
+ mesonbuild.compilers.CCompiler.program_dirs_cache = {}
+ mesonbuild.compilers.CCompiler.find_library_cache = {}
+ mesonbuild.dependencies.PkgConfigDependency.pkgbin_cache = {}
+ mesonbuild.dependencies.PkgConfigDependency.class_pkgbin = mesonlib.PerMachine(None, None, None)
+
def run_configure_inprocess(commandlist):
old_stdout = sys.stdout
sys.stdout = mystdout = StringIO()
@@ -223,6 +230,7 @@ def run_configure_inprocess(commandlist):
finally:
sys.stdout = old_stdout
sys.stderr = old_stderr
+ clear_meson_configure_class_caches()
return returncode, mystdout.getvalue(), mystderr.getvalue()
def run_configure_external(full_command):
diff --git a/run_unittests.py b/run_unittests.py
index d6c3ffb..87d9fc3 100755
--- a/run_unittests.py
+++ b/run_unittests.py
@@ -230,6 +230,32 @@ def temp_filename():
except OSError:
pass
+@contextmanager
+def no_pkgconfig():
+ '''
+ A context manager that overrides shutil.which and ExternalProgram to force
+ them to return None for pkg-config to simulate it not existing.
+ '''
+ old_which = shutil.which
+ old_search = ExternalProgram._search
+
+ def new_search(self, name, search_dir):
+ if name == 'pkg-config':
+ return [None]
+ return old_search(self, name, search_dir)
+
+ def new_which(cmd, *kwargs):
+ if cmd == 'pkg-config':
+ return None
+ return old_which(cmd, *kwargs)
+
+ shutil.which = new_which
+ ExternalProgram._search = new_search
+ try:
+ yield
+ finally:
+ shutil.which = old_which
+ ExternalProgram._search = old_search
class PatchModule:
'''
@@ -3412,7 +3438,7 @@ class FailureTests(BasePlatformTests):
and slows down testing.
'''
dnf = "[Dd]ependency.*not found(:.*)?"
- nopkg = '[Pp]kg-config not found'
+ nopkg = '[Pp]kg-config.*not found'
def setUp(self):
super().setUp()
@@ -3499,10 +3525,9 @@ class FailureTests(BasePlatformTests):
raise unittest.SkipTest('sdl2-config found')
self.assertMesonRaises("dependency('sdl2', method : 'sdlconfig')", self.dnf)
if shutil.which('pkg-config'):
- errmsg = self.dnf
- else:
- errmsg = self.nopkg
- self.assertMesonRaises("dependency('sdl2', method : 'pkg-config')", errmsg)
+ self.assertMesonRaises("dependency('sdl2', method : 'pkg-config')", self.dnf)
+ with no_pkgconfig():
+ self.assertMesonRaises("dependency('sdl2', method : 'pkg-config')", self.nopkg)
def test_gnustep_notfound_dependency(self):
# Want to test failure, so skip if available