Skip to content

Commit

Permalink
mtest: fix rebuilding all before running tests
Browse files Browse the repository at this point in the history
If an explicit list of targets is passed on the CLI, then that is passed
to rebuild_deps. If not, we pass every loaded test to rebuild_deps
instead. This means we cannot distinguish between "trying to run all
tests" and "trying to run specific tests". We then load all the deps for
all tests, and try to build them all as explicit arguments to the
underlying ninja.

This is usually papered over by people running `ninja test`, which
depends on "all" anyway as a prerequisite for invoking the underlying
`meson test --no-rebuild --print-errorlogs`, however, instead running
`meson setup builddir && meson test -C builddir` with under-specified
test deps would actually build a handful of deps and not anything else,
then fail.

Instead, pass no tests to rebuild_deps, so that we iterate over nothing
and add no explicit targets. Hence, meson rebuilds the default "all"
rule.
  • Loading branch information
eli-schwartz committed May 20, 2022
1 parent 5d0538d commit ed6b33e
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 1 deletion.
3 changes: 2 additions & 1 deletion mesonbuild/mtest.py
Original file line number Diff line number Diff line change
Expand Up @@ -1666,9 +1666,10 @@ def doit(self) -> int:
raise RuntimeError('Test harness object can only be used once.')
self.is_run = True
tests = self.get_tests()
rebuild_only_tests = tests if self.options.args else []
if not tests:
return 0
if not self.options.no_rebuild and not rebuild_deps(self.options.wd, tests):
if not self.options.no_rebuild and not rebuild_deps(self.options.wd, rebuild_only_tests):
# We return 125 here in case the build failed.
# The reason is that exit code 125 tells `git bisect run` that the current
# commit should be skipped. Thus users can directly use `meson test` to
Expand Down
1 change: 1 addition & 0 deletions test cases/unit/106 underspecified mtest/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
int main(void) { return 0 ; }
8 changes: 8 additions & 0 deletions test cases/unit/106 underspecified mtest/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
project('underspecified deps', 'c')

runner = find_program('runner.py')
exe1 = executable('main1', 'main.c')
exe2 = executable('main2', 'main.c')

test('runner-with-exedep', runner, args: exe1)
test('runner-without-dep', runner, args: exe2.full_path())
5 changes: 5 additions & 0 deletions test cases/unit/106 underspecified mtest/runner.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env python3

import sys, subprocess

subprocess.run(sys.argv[1:], check=True)
10 changes: 10 additions & 0 deletions unittests/platformagnostictests.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# limitations under the License.

import os
import subprocess
import tempfile
from unittest import skipIf

Expand Down Expand Up @@ -83,3 +84,12 @@ def test_debug_function_outputs_to_meson_log(self):
mesonlog = os.path.join(self.builddir, 'meson-logs/meson-log.txt')
with open(mesonlog, mode='r', encoding='utf-8') as file:
self.assertIn(log_msg, file.read())

def test_mtest_rebuild_deps(self):
testdir = os.path.join(self.unit_test_dir, '106 underspecified mtest')
self.init(testdir)

self._run(self.mtest_command)
self.clean()

self._run(self.mtest_command + ['runner-with-exedep'])

0 comments on commit ed6b33e

Please sign in to comment.