From d68306c9c8641bfd200d77cd1afa0d032648c365 Mon Sep 17 00:00:00 2001 From: Daan De Meyer Date: Sun, 21 Apr 2024 16:07:53 +0200 Subject: [PATCH] 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. --- mesonbuild/mtest.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/mesonbuild/mtest.py b/mesonbuild/mtest.py index 311274f37..460a44c49 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,