Problem/Motivation
It looks like #2928249: Introduce a PHPUnit 6+ compatibility layer for Drupal\Tests\Listeners classes broke testing on Windows.
php ../vendor/phpunit/phpunit/phpunit --group Imagemagick --verbose
PHP Fatal error: Uncaught preg_match(): Compilation failed: unknown property name after \P or \p at offset 5
C:\projects\drupal8\vendor\symfony\phpunit-bridge\DeprecationErrorHandler.php:105
C:\projects\drupal8\core\tests\TestSuites\TestSuiteBase.php:47
C:\projects\drupal8\core\tests\TestSuites\TestSuiteBase.php:48
C:\projects\drupal8\core\tests\TestSuites\UnitTestSuite.php:22
thrown in C:\projects\drupal8\core\tests\TestSuites\TestSuiteBase.php on line 47
That's only the beginning of the the problem because the rest of the regex on line 47 has the directory separator hard coded as well and it will fail to match without complex logic..
return !preg_match("@^$root/core/tests/Drupal/Tests/Listeners(/|$)@", dirname($test));
Probably in Windows we should have backslashes.
Proposed resolution
Use namespace as data for filtering, because it is OS independent data.
Remaining tasks
User interface changes
API changes
Data model changes
| Comment | File | Size | Author |
|---|---|---|---|
| #18 | 2932715-18.patch | 1.08 KB | alexpott |
| #18 | 6-18-interdiff.txt | 969 bytes | alexpott |
| #6 | 2932715-6.patch | 1.08 KB | alexpott |
| #2 | 2932715-2.patch | 924 bytes | mondrake |
Comments
Comment #2
mondrakeMaybe this is sufficient.
Comment #3
borisson_Is there a way we can get a testbot on windows to make sure we don't regress here, or is this really sufficient? In any case, this needs manual verification from windows users that this works.
Back to needs work for manual tests (I think this is the right status change).
Comment #4
mondrakeWorks for me in an Appveyor build of the Imagemagick module.
Without the patch: https://ci.appveyor.com/project/mondrake/imagemagick/build/1.0.201
With the patch:
https://ci.appveyor.com/project/mondrake/imagemagick/build/1.0.204
Comment #5
Anonymous (not verified) commented#3:
We already have a series of tests that fail on Windows due to difference with '/' and '\' in path-assertions. Usually we ignore these fails, because without testbot on windows (or CS rules) it will be difficult to control them.
But in this case any tests fail, regardless of their code. Therefore, +1 for a more loyal filter pattern.
Manual testing done:
Command:
php ../vendor/phpunit/phpunit/phpunit --group action --verboseWithout patch:
With #2 patch:
OK (7 tests, 169 assertions)Thank you, @mondrake!
Comment #6
alexpottThis is quite a bit of loosening of the regular expression. Not sure that that is a great idea. We can do better. I don't have windows but the patch attached should be OS independent because we don't use filepath matching anymore. Also 4 backslashes - https://www.developwebsites.net/match-backslash-preg_match-php/ :)
Comment #7
Anonymous (not verified) commented#6: Works on Windows perfect too. Nice idea!
Comment #8
mondrakeMuch better indeed. RTBC +1
Comment #10
mondrakebot fluke
Comment #12
catchCommitted/pushed to 8.6.x and cherry-picked to 8.5.x. Thanks!
Comment #15
tacituseu commentedFails on PHP 5.5
https://www.drupal.org/pift-ci-job/874218
https://www.drupal.org/pift-ci-job/874226
Comment #18
alexpottYeah array_filter() is a better approach but unfortunately ARRAY_FILTER_USE_KEY is not part of PHP5.5. Soon we'll be able to use it but for now we need to flip the array a couple fo times.
Comment #19
neclimdulAlternative approach developed for different reasons.
#2934670: Escape site root in TestSuite resolution
Comment #20
alexpott@neclimdul I must be missing something but I can't see how #2934670: Escape site root in TestSuite resolution is going to solve the windows problem whereas I can see how the solution here solves that problem.
Comment #21
neclimdulEscaping the path should fix the regex compilation fixing the original code. The problem 2934670 solves is essentially the same as this only the character triggering it was '@' and not on windows. I'm not tied to it as a solution I just wanted to bring it into the discussion since this was reverted.
Comment #22
alexpott@neclimdul from the other patch:
return !preg_match("@^$quoted_root/core/tests/Drupal/Tests/Listeners(/|$)@", dirname($test));That is still not going to work for the Window's directory separator.
Comment #23
neclimdulIt should preg_quote will escape the backslashes. https://3v4l.org/Z0ggj
Comment #24
alexpott@neclimdul I must be missing something. I can't see how the preg_quote is going to help Window's backslashes match the forward slashes in the preg_match's pattern.
Comment #25
Anonymous (not verified) commented#18 excellent correction for php 5.5. Back to RTBC.
IS updated for better clarification this issue. Also a little more here:
preg_quote, when in regular expression there are unknown components, like$root. And #19 related issue has nice demonstration tests!'/'(Unix),'\'(Windows). And we want to check them with one regular expression.\\|/- but this is more complicated and we can not say that there is no third OS where another directory separator is used :)$root.Comment #26
catchCommitted/pushed to 8.6.x and cherry-picked to 8.5.x. Thanks!
Comment #29
neclimdulI'm really lost on what you guys are saying because the IS is specifically about special characters in the path.
.
I must be missing something.
Comment #30
neclimdulAlex got me straight, I was so focused on the root and not catching that everyone was talking about the other half of the regex.