Skip to content

Commit a92c573

Browse files
authored
Fix test_edit to work with BSD sed (#3129)
2 parents 0b5c6b7 + bd131e1 commit a92c573

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

tests/test_termui.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -386,15 +386,22 @@ def test_fast_edit(runner):
386386
@pytest.mark.skipif(platform.system() == "Windows", reason="No sed on Windows.")
387387
def test_edit(runner):
388388
with tempfile.NamedTemporaryFile(mode="w") as named_tempfile:
389-
named_tempfile.write("a\nb")
389+
named_tempfile.write("a\nb\n")
390390
named_tempfile.flush()
391391

392392
result = click.edit(filename=named_tempfile.name, editor="sed -i~ 's/$/Test/'")
393393
assert result is None
394394

395395
# We need ot reopen the file as it becomes unreadable after the edit.
396396
with open(named_tempfile.name) as reopened_file:
397-
assert reopened_file.read() == "aTest\nbTest"
397+
# POSIX says that when sed writes a pattern space to output then it
398+
# is immediately followed by a newline and so the expected result
399+
# should contain the newline. However, some sed implementations
400+
# (e.g. GNU sed) does not terminate the last line in the output
401+
# with the newline in a case the input data missed newline at the
402+
# end of last line. Hence the input data (see above) should be
403+
# terminated by newline too.
404+
assert reopened_file.read() == "aTest\nbTest\n"
398405

399406

400407
@pytest.mark.parametrize(

0 commit comments

Comments
 (0)