diff --git a/CHANGES.rst b/CHANGES.rst index d2d25705d2..dcd93e4b48 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -24,6 +24,7 @@ Unreleased - Lazily import ``shutil``. :pr:`3023` - Properly forward exception information to resources registered with ``click.core.Context.with_resource()``. :issue:`2447` :pr:`3058` +- Fix regression related to EOF handling in CliRunner. :issue:`2939`:pr:`2940` Version 8.2.2 ------------- diff --git a/src/click/testing.py b/src/click/testing.py index 3d3cb1701c..f6f60b809a 100644 --- a/src/click/testing.py +++ b/src/click/testing.py @@ -127,13 +127,6 @@ def name(self) -> str: def mode(self) -> str: return self._mode - def __next__(self) -> str: # type: ignore - try: - line = super().__next__() - except StopIteration as e: - raise EOFError() from e - return line - def make_input_stream( input: str | bytes | t.IO[t.Any] | None, charset: str @@ -359,7 +352,10 @@ def isolation( @_pause_echo(echo_input) # type: ignore def visible_input(prompt: str | None = None) -> str: sys.stdout.write(prompt or "") - val = next(text_input).rstrip("\r\n") + try: + val = next(text_input).rstrip("\r\n") + except StopIteration as e: + raise EOFError() from e sys.stdout.write(f"{val}\n") sys.stdout.flush() return val @@ -368,7 +364,10 @@ def visible_input(prompt: str | None = None) -> str: def hidden_input(prompt: str | None = None) -> str: sys.stdout.write(f"{prompt or ''}\n") sys.stdout.flush() - return next(text_input).rstrip("\r\n") + try: + return next(text_input).rstrip("\r\n") + except StopIteration as e: + raise EOFError() from e @_pause_echo(echo_input) # type: ignore def _getchar(echo: bool) -> str: diff --git a/tests/test_chain.py b/tests/test_chain.py index ba11b7e2ae..702eaaa3e1 100644 --- a/tests/test_chain.py +++ b/tests/test_chain.py @@ -163,8 +163,8 @@ def processor(iterator): return processor result = runner.invoke(cli, args, input=input) - # last two lines are '' and 'Aborted!' - assert result.output.splitlines()[:-2] == expect + assert not result.exception + assert result.output.splitlines() == expect def test_args_and_chain(runner):