| 395 | |
| 396 | @pytest.mark.skipif(platform.system() == "Windows", reason="No sed on Windows.") |
| 397 | def test_edit(runner): |
| 398 | with tempfile.NamedTemporaryFile(mode="w") as named_tempfile: |
| 399 | named_tempfile.write("a\nb\n") |
| 400 | named_tempfile.flush() |
| 401 | |
| 402 | result = click.edit(filename=named_tempfile.name, editor="sed -i~ 's/$/Test/'") |
| 403 | assert result is None |
| 404 | |
| 405 | # We need to reopen the file as it becomes unreadable after the edit. |
| 406 | with open(named_tempfile.name) as reopened_file: |
| 407 | # POSIX says that when sed writes a pattern space to output then it |
| 408 | # is immediately followed by a newline and so the expected result |
| 409 | # should contain the newline. However, some sed implementations |
| 410 | # (e.g. GNU sed) does not terminate the last line in the output |
| 411 | # with the newline in a case the input data missed newline at the |
| 412 | # end of last line. Hence the input data (see above) should be |
| 413 | # terminated by newline too. |
| 414 | assert reopened_file.read() == "aTest\nbTest\n" |
| 415 | |
| 416 | |
| 417 | @pytest.mark.parametrize( |