mtest: fix logic bug that broke tests where the cmd is a Windows found program

In this case, the test fname might have an implicit extension and cannot
be found by `os.path.isfile()`.

We cannot use `shutil.which()` to handle platform differences, because
not all test fnames are executable -- for example Java jars.

The test representation does have an "is built" attribute which in
theory should work here, because all built targets definitely have their
full filename known to Meson, but it turns out to be misnamed. Rename it
correctly and add an actual "is built" attribute to check.

Tests which aren't built by Meson can be assumed to exist without
consulting their existence on the filesystem.

Fixes #10027
pull/10119/head
Eli Schwartz 3 years ago committed by Jussi Pakkanen
parent e54e9f58e5
commit 4680c09aac
  1. 2
      mesonbuild/backend/backends.py
  2. 6
      mesonbuild/mtest.py

@ -224,6 +224,7 @@ class TestSerialisation:
protocol: TestProtocol protocol: TestProtocol
priority: int priority: int
cmd_is_built: bool cmd_is_built: bool
cmd_is_exe: bool
depends: T.List[str] depends: T.List[str]
version: str version: str
verbose: bool verbose: bool
@ -1147,6 +1148,7 @@ class Backend:
t.is_parallel, cmd_args, t.env, t.is_parallel, cmd_args, t.env,
t.should_fail, t.timeout, t.workdir, t.should_fail, t.timeout, t.workdir,
extra_paths, t.protocol, t.priority, extra_paths, t.protocol, t.priority,
isinstance(exe, build.Target),
isinstance(exe, build.Executable), isinstance(exe, build.Executable),
[x.get_id() for x in depends], [x.get_id() for x in depends],
self.environment.coredata.version, self.environment.coredata.version,

@ -1349,18 +1349,18 @@ class SingleTestRunner:
def _get_test_cmd(self) -> T.Optional[T.List[str]]: def _get_test_cmd(self) -> T.Optional[T.List[str]]:
testentry = self.test.fname[0] testentry = self.test.fname[0]
if self.options.no_rebuild and not os.path.isfile(testentry): if self.options.no_rebuild and self.test.cmd_is_built and not os.path.isfile(testentry):
raise TestException(f'The test program {testentry!r} does not exist. Cannot run tests before building them.') raise TestException(f'The test program {testentry!r} does not exist. Cannot run tests before building them.')
if testentry.endswith('.jar'): if testentry.endswith('.jar'):
return ['java', '-jar'] + self.test.fname return ['java', '-jar'] + self.test.fname
elif not self.test.is_cross_built and run_with_mono(testentry): elif not self.test.is_cross_built and run_with_mono(testentry):
return ['mono'] + self.test.fname return ['mono'] + self.test.fname
elif self.test.cmd_is_built and self.test.is_cross_built and self.test.needs_exe_wrapper: elif self.test.cmd_is_exe and self.test.is_cross_built and self.test.needs_exe_wrapper:
if self.test.exe_wrapper is None: if self.test.exe_wrapper is None:
# Can not run test on cross compiled executable # Can not run test on cross compiled executable
# because there is no execute wrapper. # because there is no execute wrapper.
return None return None
elif self.test.cmd_is_built: elif self.test.cmd_is_exe:
# If the command is not built (ie, its a python script), # If the command is not built (ie, its a python script),
# then we don't check for the exe-wrapper # then we don't check for the exe-wrapper
if not self.test.exe_wrapper.found(): if not self.test.exe_wrapper.found():

Loading…
Cancel
Save