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