WordPress.org

Make WordPress Core

Opened 5 years ago

Closed 7 months ago

#31432 closed defect (bug) (fixed)

Unit tests are sensitive to line endings

Reported by: SergeyBiryukov Owned by: 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 5 years ago.

Download all attachments as: .zip

Change History (16)

#1 @SergeyBiryukov
5 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
5 years ago

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

#3 follow-up: @dd32
5 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
5 years ago

  • Description modified (diff)

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


5 years ago

#6 @boonebgorges
5 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.


3 years ago

#8 @bobbingwide
3 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 3 years ago by bobbingwide (previous) (diff)

#10 @azaozz
12 months ago

#46798 was marked as a duplicate.

#11 @azaozz
12 months 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 12 months ago by azaozz (previous) (diff)

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


11 months ago

#13 @SergeyBiryukov
7 months 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
7 months 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
7 months 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.

Note: See TracTickets for help on using tickets.