WordPress.org

Make WordPress Core

Opened 5 years ago

Last modified 3 months ago

#31432 new defect (bug)

Unit tests are sensitive to line endings

Reported by: SergeyBiryukov Owned by:
Milestone: Future Release Priority: normal
Severity: normal Version:
Component: Build/Test Tools Keywords: has-patch
Focuses: Cc:
PR Number:

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 (13)

#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 @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.


2 years ago

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

#10 @azaozz
5 months ago

#46798 was marked as a duplicate.

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

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


3 months ago

Note: See TracTickets for help on using tickets.