Skip to content

Commit

Permalink
mtest: Connect /dev/null to stdin when not running in interactive mode
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
DaanDeMeyer committed Apr 23, 2024
1 parent 161be5a commit 40e0ef9
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion mesonbuild/mtest.py
Original file line number Diff line number Diff line change
Expand Up @@ -1497,7 +1497,7 @@ async def run(self, harness: 'TestHarness') -> TestRun:
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
Expand All @@ -1523,6 +1523,7 @@ def postwait_fn() -> None:
signal.signal(signal.SIGINT, previous_sigint_handler)

p = await asyncio.create_subprocess_exec(*args,
stdin=stdin,
stdout=stdout,
stderr=stderr,
env=env,
Expand All @@ -1533,9 +1534,11 @@ def postwait_fn() -> None:

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 \
Expand All @@ -1549,6 +1552,7 @@ async def _run_cmd(self, harness: 'TestHarness', cmd: T.List[str]) -> None:
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,
Expand Down

0 comments on commit 40e0ef9

Please sign in to comment.