From cedfa575f6144b9eb3ed9f777074c7b95ad52231 Mon Sep 17 00:00:00 2001 From: Nirbheek Chauhan Date: Thu, 10 Nov 2016 01:34:29 +0530 Subject: [PATCH] Add a unit test for Qt5 detection with qmake This can only be done as a unit test because it requires changes to the environment. This also means we need to pass the current environment to subprocess.check_output, which we should always do anyway since the environment is torn down and restored between each test. --- run_unittests.py | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/run_unittests.py b/run_unittests.py index 8df000160..44e190e9e 100755 --- a/run_unittests.py +++ b/run_unittests.py @@ -19,7 +19,7 @@ import re, json import tempfile import mesonbuild.environment from mesonbuild.environment import detect_ninja -from mesonbuild.dependencies import PkgConfigDependency +from mesonbuild.dependencies import PkgConfigDependency, Qt5Dependency def get_soname(fname): # HACK, fix to not use shell. @@ -59,6 +59,7 @@ class LinuxlikeTests(unittest.TestCase): self.ninja_command = [detect_ninja(), '-C', self.builddir] self.common_test_dir = os.path.join(src_root, 'test cases/common') self.vala_test_dir = os.path.join(src_root, 'test cases/vala') + self.framework_test_dir = os.path.join(src_root, 'test cases/frameworks') self.output = b'' self.orig_env = os.environ.copy() @@ -67,22 +68,29 @@ class LinuxlikeTests(unittest.TestCase): os.environ = self.orig_env super().tearDown() + def _run(self, command): + self.output += subprocess.check_output(command, env=os.environ.copy()) + def init(self, srcdir): - self.output += subprocess.check_output(self.meson_command + [srcdir, self.builddir]) + self._run(self.meson_command + [srcdir, self.builddir]) def build(self): - self.output += subprocess.check_output(self.ninja_command) + self._run(self.ninja_command) def run_target(self, target): self.output += subprocess.check_output(self.ninja_command + [target]) def setconf(self, arg): - self.output += subprocess.check_output(self.mconf_command + [arg, self.builddir]) + self._run(self.mconf_command + [arg, self.builddir]) def get_compdb(self): with open(os.path.join(self.builddir, 'compile_commands.json')) as ifile: return json.load(ifile) + def get_meson_log(self): + with open(os.path.join(self.builddir, 'meson-logs', 'meson-log.txt')) as f: + return f.readlines() + def introspect(self, arg): out = subprocess.check_output(self.mintro_command + [arg, self.builddir]) return json.loads(out.decode('utf-8')) @@ -181,5 +189,19 @@ class LinuxlikeTests(unittest.TestCase): self.init(testdir) self.run_target('check_exists') + def test_qt5dependency_qmake_detection(self): + # Can't be sure that `qmake` is Qt5, so just try qmake-qt5. + if not shutil.which('qmake-qt5'): + raise unittest.SkipTest('qt5 not found') + # Disable pkg-config codepath and force searching with qmake/qmake-qt5 + os.environ['PKG_CONFIG_LIBDIR'] = self.builddir + os.environ['PKG_CONFIG_PATH'] = self.builddir + testdir = os.path.join(self.framework_test_dir, '4 qt') + self.init(testdir) + # Confirm that the dependency was found with qmake + msg = 'Qt5 native `qmake-qt5` dependency found: YES\n' + mesonlog = self.get_meson_log() + self.assertTrue(msg in mesonlog) + if __name__ == '__main__': unittest.main()