Make WordPress Core

Opened 10 years ago

Closed 5 years ago

Last modified 4 years ago

#31432 closed defect (bug) (fixed)

Unit tests are sensitive to line endings

Reported by: sergeybiryukov's profile SergeyBiryukov Owned by: sergeybiryukov's profile SergeyBiryukov
Milestone: 5.4 Priority: normal
Severity: normal Version:
Component: Build/Test Tools Keywords: has-patch
Focuses: Cc:

Description (last modified by SergeyBiryukov)

Currently, patching unit test files with grunt patch on Windows changes line endings.

This results in unexpected failures in some tests using the heredoc syntax (<<<), see #31430.

We should probably set svn:eol-style to native for test files, like we did for core, and do something like str_replace( "\r\n", "\n", ... ) in the tests with heredoc.

Attachments (1)

31432.patch (14.1 KB) - added by SergeyBiryukov 10 years ago.

Download all attachments as: .zip

Change History (18)

#1 @SergeyBiryukov
10 years ago

  • Keywords has-patch added; needs-patch removed
  • Milestone changed from Awaiting Review to 4.2

31432.patch fixes the affected tests.

#2 @wonderboymusic
10 years ago

Hmmmm, maybe switch to output buffers? I can easily imagine myself forgetting about this being a thing...

#3 follow-up: @dd32
10 years ago

The alternative is that we introduce a AssertEqualsIgnoreEOL() style function, or even extend assertEquals to assertEquals($one, $two, $message = '', $allow_mismatched_EOL = true) in our unit test class (which I don't really like).

#4 @SergeyBiryukov
10 years ago

  • Description modified (diff)

This ticket was mentioned in Slack in #core by helen. View the logs.


10 years ago

#6 @boonebgorges
10 years ago

  • Milestone changed from 4.2 to Future Release

This is not linked to a specific release, so I'm moving out of the milestone. Please feel free to move back when a decision has been made.

This ticket was mentioned in Slack in #core by sergey. View the logs.


7 years ago

#8 @bobbingwide
7 years ago

Having detected this line ending problem with Tests_Dependencies_Styles::test_conditional_inline_styles_are_also_conditional, running under Windows on a clone of git://develop.git.wordpress.org/ I ran

git config --global core.autocrlf input

checked the file out and the test worked.

...but Tests_Formatting_Autop::test_that_wpautop_skips_line_breaks_after_br then failed.

Last edited 7 years ago by bobbingwide (previous) (diff)

#10 @azaozz
5 years ago

#46798 was marked as a duplicate.

#11 @azaozz
5 years ago

Seems the "time proven" solution was to use assertContains() when testing HTML output, and avoid the line endings.

Still seeing line endings errors in phpunit/tests/dependencies/scripts.php that are caused by comparing with wp_scripts_print_translations_output that holds some inline JS. It tests translation scripts outputted with printf() in script-loader. Seems we can test it with assertContains() too, perhaps only one line, not the whole script.

Last edited 5 years ago by azaozz (previous) (diff)

This ticket was mentioned in Slack in #core by sergey. View the logs.


5 years ago

#13 @SergeyBiryukov
5 years ago

  • Milestone changed from Future Release to 5.4

This became much more prominent with [46586], seeing 47 failures on trunk.

#14 in reply to: ↑ 3 @SergeyBiryukov
5 years ago

Replying to dd32:

The alternative is that we introduce a AssertEqualsIgnoreEOL() style function, or even extend assertEquals to assertEquals($one, $two, $message = '', $allow_mismatched_EOL = true) in our unit test class (which I don't really like).

Introducing something like assertEqualsIgnoreEOL() makes sense to me.

We already have assertDiscardWhitespace(), which is not really used anywhere though.

#15 @SergeyBiryukov
5 years ago

  • Owner set to SergeyBiryukov
  • Resolution set to fixed
  • Status changed from new to closed

In 46612:

Build/Test Tools: Ignore EOL differences in tests using multiline string assertions.

Unix vs. Windows EOL style mismatches can cause misleading failures in tests using the heredoc syntax (<<<) or multiline strings as the expected result.

Fixes #31432. See #42594, #47411.

#16 @SergeyBiryukov
4 years ago

In 48443:

Tests: Ignore EOL differences in email tests using multiline string assertions.

Unix vs. Windows EOL style mismatches can cause misleading failures in tests using the heredoc syntax (<<<) or multiline strings as the expected result.

Follow-up to [46612], [48033].

Props davidbaumwald.
See #31432, #41750.

#17 @SergeyBiryukov
4 years ago

In 48466:

Tests: Ignore EOL differences in some tests using multiline string assertions.

Unix vs. Windows EOL style mismatches can cause misleading failures in tests using the heredoc syntax (<<<) or multiline strings as the expected result.

Follow-up to [46612], [48443].

See #31432.

Note: See TracTickets for help on using tickets.