[Bug]: [mutate] Windows: @pest-mutate-ignore comments land on line 1 in files with LF line endings
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.
Source: pestphp/pest