From 50b2ef7354b503ae62abd504cdce938c390b358f Mon Sep 17 00:00:00 2001 From: Michael Forney Date: Mon, 8 Oct 2018 10:05:36 -0700 Subject: [PATCH] Consider 'samu' when looking for ninja command samu prints a different message when the build is a no-op, so make assertBuildIsNoop consider that as well. Also, if compile_commands.json cannot be found, just skip the test. This seems reasonable since meson just produces a warning if `ninja -t compdb` fails. Finally, only capture stdout in run_meson_command_tests.py, since the backend may print messages the tests don't recognize to stderr. Fixes #3405. --- mesonbuild/environment.py | 2 +- run_meson_command_tests.py | 7 +++---- run_unittests.py | 13 ++++++++----- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/mesonbuild/environment.py b/mesonbuild/environment.py index 2a6f750b4..80917ed0b 100644 --- a/mesonbuild/environment.py +++ b/mesonbuild/environment.py @@ -120,7 +120,7 @@ def find_coverage_tools(): return gcovr_exe, gcovr_new_rootdir, lcov_exe, genhtml_exe def detect_ninja(version='1.5', log=False): - for n in ['ninja', 'ninja-build']: + for n in ['ninja', 'ninja-build', 'samu']: try: p, found = Popen_safe([n, '--version'])[0:2] except (FileNotFoundError, PermissionError): diff --git a/run_meson_command_tests.py b/run_meson_command_tests.py index 390868a91..17fe969ce 100755 --- a/run_meson_command_tests.py +++ b/run_meson_command_tests.py @@ -63,15 +63,14 @@ class CommandTests(unittest.TestCase): def _run(self, command, workdir=None): ''' - Run a command while printing the stdout and stderr to stdout, - and also return a copy of it + Run a command while printing the stdout, and also return a copy of it ''' # If this call hangs CI will just abort. It is very hard to distinguish # between CI issue and test bug in that case. Set timeout and fail loud # instead. p = subprocess.run(command, stdout=subprocess.PIPE, - stderr=subprocess.STDOUT, env=os.environ.copy(), - universal_newlines=True, cwd=workdir, timeout=60 * 5) + env=os.environ.copy(), universal_newlines=True, + cwd=workdir, timeout=60 * 5) print(p.stdout) if p.returncode != 0: raise subprocess.CalledProcessError(p.returncode, command) diff --git a/run_unittests.py b/run_unittests.py index d63a96172..298e249c0 100755 --- a/run_unittests.py +++ b/run_unittests.py @@ -921,11 +921,11 @@ class BasePlatformTests(unittest.TestCase): # Misc stuff self.orig_env = os.environ.copy() if self.backend is Backend.ninja: - self.no_rebuild_stdout = 'ninja: no work to do.' + self.no_rebuild_stdout = ['ninja: no work to do.', 'samu: nothing to do'] else: # VS doesn't have a stable output when no changes are done # XCode backend is untested with unit tests, help welcome! - self.no_rebuild_stdout = 'UNKNOWN BACKEND {!r}'.format(self.backend.name) + self.no_rebuild_stdout = ['UNKNOWN BACKEND {!r}'.format(self.backend.name)] self.builddirs = [] self.new_builddir() @@ -1076,8 +1076,11 @@ class BasePlatformTests(unittest.TestCase): def get_compdb(self): if self.backend is not Backend.ninja: raise unittest.SkipTest('Compiler db not available with {} backend'.format(self.backend.name)) - with open(os.path.join(self.builddir, 'compile_commands.json')) as ifile: - contents = json.load(ifile) + try: + with open(os.path.join(self.builddir, 'compile_commands.json')) as ifile: + contents = json.load(ifile) + except FileNotFoundError: + raise unittest.SkipTest('Compiler db not found') # If Ninja is using .rsp files, generate them, read their contents, and # replace it as the command for all compile commands in the parsed json. if len(contents) > 0 and contents[0]['command'].endswith('.rsp'): @@ -1131,7 +1134,7 @@ class BasePlatformTests(unittest.TestCase): def assertBuildIsNoop(self): ret = self.build() if self.backend is Backend.ninja: - self.assertEqual(ret.split('\n')[-2], self.no_rebuild_stdout) + self.assertIn(ret.split('\n')[-2], self.no_rebuild_stdout) elif self.backend is Backend.vs: # Ensure that some target said that no rebuild was done self.assertIn('CustomBuild:\n All outputs are up-to-date.', ret)