diff options
| author | Eli Schwartz <eschwartz93@gmail.com> | 2025-01-27 16:40:19 -0500 |
|---|---|---|
| committer | Eli Schwartz <eschwartz93@gmail.com> | 2025-01-28 11:26:47 -0500 |
| commit | d51e20288853f376e9244671604176913f2e4e79 (patch) | |
| tree | bce5d750ce115e507f8d2c1dc614458b7ef375e8 | |
| parent | c31963ca80997006347619fb07ee28ee9dd1de49 (diff) | |
| download | meson-d51e20288853f376e9244671604176913f2e4e79.tar.gz | |
fix edge case in testcase expect_error() if error is printed using mlog
It catches the exception message itself, but for multi-line exceptions
it may be worth print an error() as well as raising, to communicate
multiple bits of information.
When using the VS backend, this means that we get an actual `ERROR: ...`
printed during a successful run, which then breaks msbuild as msbuild
parses stdout of successful commands, regexes them for the word "error:"
and interprets that as... an error. So a meson project tests example
that uses testcase expect_error() and then successfully configures and
builds, fails to successfully `meson --internal regenerate`.
Sneak around this by doing our own pattern replace to evade msbuild.
There is probably a way to tell msbuild to stop doing this, but that
would require me understanding the vs backend well enough to patch the
xml it generates. No thanks...
| -rw-r--r-- | mesonbuild/interpreter/interpreter.py | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/mesonbuild/interpreter/interpreter.py b/mesonbuild/interpreter/interpreter.py index 806a737ea..c7aef9329 100644 --- a/mesonbuild/interpreter/interpreter.py +++ b/mesonbuild/interpreter/interpreter.py @@ -4,8 +4,7 @@ from __future__ import annotations -import hashlib -import traceback +import hashlib, io, sys, traceback from .. import mparser from .. import environment @@ -1474,10 +1473,18 @@ class Interpreter(InterpreterBase, HoldableObject): class ExpectErrorObject(ContextManagerObject): def __init__(self, msg: str, how: str, subproject: str) -> None: super().__init__(subproject) + self.old_stdout = sys.stdout + sys.stdout = self.new_stdout = io.StringIO() self.msg = msg self.how = how def __exit__(self, exc_type, exc_val, exc_tb): + sys.stdout = self.old_stdout + for l in self.new_stdout.getvalue().splitlines(): + if 'ERROR:' in l: + print(l.replace('ERROR', 'ERROR (msbuild proof)')) + else: + print(l) if exc_val is None: raise InterpreterException('Expecting an error but code block succeeded') if isinstance(exc_val, mesonlib.MesonException): |
