[Bug]: [mutate] Windows: @pest-mutate-ignore comments land on line 1 in files with LF line endings
Nobody has claimed this yet.
- Dominant language
- PHP
- Stars
- 11.7k
- Forks
- 538
- Avg merge
- 4d 11h
- Merged PRs (30d)
- 8
Description
What Happened
On Windows, // @pest-mutate-ignore comments don't apply in files with LF line endings, which is what a .gitattributes with eol=lf produces. The mutants they should suppress are still generated and reported.
MutationGenerator::generate() locates the comments by splitting the source on PHP_EOL:
foreach (explode(PHP_EOL, $contents) as $lineNumber => $line) {
On Windows PHP_EOL is "\r\n", so an LF file isn't split at all. The whole file becomes line 1, and every ignore comment is recorded for line 1 instead of its own line.
Expected: ignore comments apply to their own line, whatever the file's line endings or the OS.
How to Reproduce
On Windows, take any LF file with a // @pest-mutate-ignore comment on a line that has a surviving mutant, and run pest --mutate.
This is currently hidden by #1927, which makes every mutant count as killed on Windows anyway. With that one patched locally (quotes removed from --filter), the sample repository's composer test:mutate on Windows reports the 2 mutants on the two lines of src/Tty.php marked // @pest-mutate-ignore: RemoveArrayItem as untested (94.87%). Replacing PHP_EOL with "\n" in that explode() as well gives 100%, the same as on Linux.
Suggested fix: preg_split('/\R/', $contents), which handles LF and CRLF files on any OS.
Sample Repository
https://github.com/Shoxcie/composer-tty
Pest Version
5.2.1 (pestphp/pest-plugin-mutate v5.0.2)
PHP Version
8.5.10
Operation System
Windows
Notes
Filed here because issues are disabled on pestphp/pest-plugin-mutate. Related Windows issues: #1927, #1916, #1313.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at MutationGenerator::generate(), where ignore comments are split from the source using PHP_EOL. Reproduce the issue with an LF-ended file on Windows, then run the sample repository's composer test:mutate command; done means ignore comments apply to their own lines for both LF and CRLF files.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php
- Domain
- testing-qa
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 78/100