#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 )
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)
Change History (18)
#1
@
10 years ago
- Keywords has-patch added; needs-patch removed
- Milestone changed from Awaiting Review to 4.2
#2
@
10 years ago
Hmmmm, maybe switch to output buffers? I can easily imagine myself forgetting about this being a thing...
#3
follow-up:
↓ 14
@
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).
This ticket was mentioned in Slack in #core by helen. View the logs.
10 years ago
#6
@
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
@
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.
#11
@
6 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.
This ticket was mentioned in Slack in #core by sergey. View the logs.
5 years ago
#13
@
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
@
5 years ago
Replying to dd32:
The alternative is that we introduce a
AssertEqualsIgnoreEOL()
style function, or even extendassertEquals
toassertEquals($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.
31432.patch fixes the affected tests.