Skip to content

Commit

Permalink
tests: Always enable the traceback in run_project_tests.py
Browse files Browse the repository at this point in the history
  • Loading branch information
mensinda committed Jun 18, 2021
1 parent 10afec5 commit b2112bc
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 6 deletions.
5 changes: 4 additions & 1 deletion run_project_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,9 @@ def __init__(self, path: Path, name: T.Optional[str], args: T.List[str], skip: b
self.do_not_set_opts = [] # type: T.List[str]
self.stdout = [] # type: T.List[T.Dict[str, str]]

# Always print a stack trace for Meson exceptions
self.env['MESON_FORCE_BACKTRACE'] = '1'

def __repr__(self) -> str:
return '<{}: {:<48} [{}: {}] -- {}>'.format(type(self).__name__, str(self.path), self.name, self.args, self.skip)

Expand Down Expand Up @@ -619,7 +622,7 @@ def _run_test(test: TestDef,
gen_args.extend(['--native-file', nativefile.as_posix()])
if crossfile.exists():
gen_args.extend(['--cross-file', crossfile.as_posix()])
(returncode, stdo, stde) = run_configure(gen_args, env=test.env)
(returncode, stdo, stde) = run_configure(gen_args, env=test.env, catch_exception=True)
try:
logfile = Path(test_build_dir, 'meson-logs', 'meson-log.txt')
mesonlog = logfile.open(errors='ignore', encoding='utf-8').read()
Expand Down
2 changes: 1 addition & 1 deletion run_single_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def main() -> None:
failed = True
else:
msg = mlog.green('PASS:')
mlog.log(msg, test.display_name())
mlog.log(msg, *test.display_name())
if result is not None and result.msg and 'MESON_SKIP_TEST' not in result.stdo:
mlog.log('reason:', result.msg)
if result.step is BuildStep.configure:
Expand Down
14 changes: 11 additions & 3 deletions run_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import tempfile
import platform
import argparse
import traceback
from io import StringIO
from enum import Enum
from glob import glob
Expand Down Expand Up @@ -268,12 +269,19 @@ def clear_meson_configure_class_caches() -> None:
dependencies.PkgConfigDependency.pkgbin_cache = {}
dependencies.PkgConfigDependency.class_pkgbin = mesonlib.PerMachine(None, None)

def run_configure_inprocess(commandlist: T.List[str], env: T.Optional[T.Dict[str, str]] = None) -> T.Tuple[int, str, str]:
def run_configure_inprocess(commandlist: T.List[str], env: T.Optional[T.Dict[str, str]] = None, catch_exception: bool = False) -> T.Tuple[int, str, str]:
stderr = StringIO()
stdout = StringIO()
returncode = 0
with mock.patch.dict(os.environ, env or {}), mock.patch.object(sys, 'stdout', stdout), mock.patch.object(sys, 'stderr', stderr):
try:
returncode = mesonmain.run(commandlist, get_meson_script())
except Exception:
if catch_exception:
returncode = 1
traceback.print_exc()
else:
raise
finally:
clear_meson_configure_class_caches()
return returncode, stdout.getvalue(), stderr.getvalue()
Expand All @@ -282,11 +290,11 @@ def run_configure_external(full_command: T.List[str], env: T.Optional[T.Dict[str
pc, o, e = mesonlib.Popen_safe(full_command, env=env)
return pc.returncode, o, e

def run_configure(commandlist: T.List[str], env: T.Optional[T.Dict[str, str]] = None) -> T.Tuple[int, str, str]:
def run_configure(commandlist: T.List[str], env: T.Optional[T.Dict[str, str]] = None, catch_exception: bool = False) -> T.Tuple[int, str, str]:
global meson_exe
if meson_exe:
return run_configure_external(meson_exe + commandlist, env=env)
return run_configure_inprocess(commandlist, env=env)
return run_configure_inprocess(commandlist, env=env, catch_exception=catch_exception)

def print_system_info():
print(mlog.bold('System information.'))
Expand Down
2 changes: 1 addition & 1 deletion run_unittests.py
Original file line number Diff line number Diff line change
Expand Up @@ -6165,7 +6165,7 @@ def test_exception_exit_status(self):
'''
tdir = os.path.join(self.unit_test_dir, '21 exit status')
with self.assertRaises(subprocess.CalledProcessError) as cm:
self.init(tdir, inprocess=False, override_envvars = {'MESON_UNIT_TEST': '1'})
self.init(tdir, inprocess=False, override_envvars = {'MESON_UNIT_TEST': '1', 'MESON_FORCE_BACKTRACE': ''})
self.assertEqual(cm.exception.returncode, 2)
self.wipe()

Expand Down

0 comments on commit b2112bc

Please sign in to comment.