diff --git a/src/darker/tests/test_main.py b/src/darker/tests/test_main.py index 9b5b62e82..d438d92c4 100644 --- a/src/darker/tests/test_main.py +++ b/src/darker/tests/test_main.py @@ -942,6 +942,27 @@ def test_stdout_path_resolution(git_repo, capsys): assert capsys.readouterr().out == 'print("foo")\n' +@pytest.mark.parametrize("newline", ["\n", "\r\n"], ids=["unix", "windows"]) +def test_stdout_newlines(tmp_path, monkeypatch, capsysbinary, newline): + """When using ``--stdout``, newlines are not duplicated. + + See: https://github.com/akaihola/darker/issues/604 + + """ + monkeypatch.chdir(tmp_path) + code = f"import collections{newline}import sys{newline}".encode() + Path("new-file.py").write_bytes(code) + with patch("sys.stdin.buffer.read", return_value=code): + + result = darker.__main__.main( + ["--stdout", "--isort", "--stdin-filename=new-file.py", "-"], + ) + + assert result == 0 + expect = f"import collections{newline}import sys{newline}".encode() + assert capsysbinary.readouterr().out == expect + + def test_long_command_length(git_repo): """Large amount of changed files does not break Git invocation even on Windows""" # For PR #542 - large character count for changed files