Skip to content

fix: support LF line endings for @pest-mutate-ignore on Windows - #44

Open
webdevsamran wants to merge 1 commit into
pestphp:5.xfrom
webdevsamran:fix/windows-lf-mutate-ignore
Open

webdevsamran wants to merge 1 commit into
pestphp:5.xfrom
webdevsamran:fix/windows-lf-mutate-ignore

Conversation

@webdevsamran

Copy link
Copy Markdown

Fixes pestphp/pest#1928

Problem

On Windows, MutationGenerator::generate() parses @pest-mutate-ignore annotations by splitting file contents on PHP_EOL:

foreach (explode(PHP_EOL, $contents) as $lineNumber => $line) {

On Windows, PHP_EOL evaluates to "\r\n". When inspecting source files that use Unix LF (\n) line endings (such as repositories with eol=lf in .gitattributes), explode() does not split the file. The entire file is treated as a single line, causing any ignore comment anywhere in the file to be attributed to line 1 ($lineNumber + 1 = 1). Consequently, mutants on their actual lines are not suppressed and fail mutation testing runs.

Solution

Replace explode(PHP_EOL, $contents) with preg_split('/\R/', $contents) to handle all OS newline formats (\n, \r\n, \r) consistently across platforms.

Verification

  • Added a regression test in tests/Unit/MutationGeneratorTest.php asserting that @pest-mutate-ignore correctly ignores mutators on lines beyond line 1 when files use LF line endings.

…indows

Signed-off-by: Samran Asif <samranwebdev2000@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: [mutate] Windows: @pest-mutate-ignore comments land on line 1 in files with LF line endings

1 participant