aboutsummaryrefslogtreecommitdiff
path: root/mesonbuild/mtest.py
diff options
context:
space:
mode:
authorDaan De Meyer <daan.j.demeyer@gmail.com>2024-04-21 16:07:53 +0200
committerDaan De Meyer <daan.j.demeyer@gmail.com>2024-04-23 21:36:35 +0200
commitd68306c9c8641bfd200d77cd1afa0d032648c365 (patch)
tree32162b2b310e91caf365d0dd2786555757c3ee65 /mesonbuild/mtest.py
parent344a97e08a695af40ec77e439582ffdc06154f21 (diff)
downloadmeson-d68306c9c8641bfd200d77cd1afa0d032648c365.zip
meson-d68306c9c8641bfd200d77cd1afa0d032648c365.tar.gz
meson-d68306c9c8641bfd200d77cd1afa0d032648c365.tar.bz2
mtest: Connect /dev/null to stdin when not running in interactive mode
This allows tests to check whether stdin is a tty to figure out if they're running in interactive mode or not. It also makes sure that tests that are not running in interactive mode don't inadvertendly try to read from stdin.
Diffstat (limited to 'mesonbuild/mtest.py')
-rw-r--r--mesonbuild/mtest.py6
1 files changed, 5 insertions, 1 deletions
diff --git a/mesonbuild/mtest.py b/mesonbuild/mtest.py
index 311274f..460a44c 100644
--- a/mesonbuild/mtest.py
+++ b/mesonbuild/mtest.py
@@ -1497,7 +1497,7 @@ class SingleTestRunner:
await self._run_cmd(harness, cmd)
return self.runobj
- async def _run_subprocess(self, args: T.List[str], *,
+ async def _run_subprocess(self, args: T.List[str], *, stdin: T.Optional[int],
stdout: T.Optional[int], stderr: T.Optional[int],
env: T.Dict[str, str], cwd: T.Optional[str]) -> TestSubprocess:
# Let gdb handle ^C instead of us
@@ -1523,6 +1523,7 @@ class SingleTestRunner:
signal.signal(signal.SIGINT, previous_sigint_handler)
p = await asyncio.create_subprocess_exec(*args,
+ stdin=stdin,
stdout=stdout,
stderr=stderr,
env=env,
@@ -1533,9 +1534,11 @@ class SingleTestRunner:
async def _run_cmd(self, harness: 'TestHarness', cmd: T.List[str]) -> None:
if self.console_mode is ConsoleUser.INTERACTIVE:
+ stdin = None
stdout = None
stderr = None
else:
+ stdin = asyncio.subprocess.DEVNULL
stdout = asyncio.subprocess.PIPE
stderr = asyncio.subprocess.STDOUT \
if not self.options.split and not self.runobj.needs_parsing \
@@ -1549,6 +1552,7 @@ class SingleTestRunner:
extra_cmd.append(f'--gtest_output=xml:{gtestname}.xml')
p = await self._run_subprocess(cmd + extra_cmd,
+ stdin=stdin,
stdout=stdout,
stderr=stderr,
env=self.runobj.env,