Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Regex filtering #23

Closed
wants to merge 1 commit into from
Closed

Conversation

johncrenshaw
Copy link

The current mechanisms for filtering large numbers of files from coverage data are horribly inadequate, especially for projects that use large monolithic libraries like Zend Framework.

I've made a few changes to PHPUnit_Util_Filter to allow regex based filters. (Blacklist only, since whitelists would be difficult to properly support, and wouldn't be made any faster by this, although a regular expression parameter on the whitelist might make sense.)

I didn't rewrite addDirectoryToFilter, so it's still slow, but this gives a workaround for now, and it shouldn't be too hard to rewrite addDirectoryToFilter later. (realpath, explode, preg_quote all segments with $delimiter='', implode with $glue='(\|/)'), and wrap with ''.)

This patch also allows for other useful exclusions, such as:
PHPUnit_Util_Filter::addRegexToFilter('test(s?)', 'TESTS');

…acceptable alternative to outrageously slow directory filters (which can take several minutes to filter something like Zend Framework from the coverage information.)


TODO: Rewrite the directory filters to use the regular expressions, rather than walking the file tree
@ped7g
Copy link

ped7g commented Nov 12, 2010

I have been struggling with speed of addDirectoryToFilter / addFileToFilter too when running ordinary non code coverage tests.
(I can live with the penalty when running code coverage, as it takes 2 times longer then normally anyway, so additional 2 secs doesn't matter at all at that point)

For now I have a workaround by doing this in test bootstrap.php:
define('PHPUNIT_COVERAGE', '--coverage');
foreach( $GLOBALS['argv'] as $opt ) {
if ( strncasecmp( $opt, PHPUNIT_COVERAGE, strlen(PHPUNIT_COVERAGE) ) == 0 ) {
//calls to addDirectoryToBlacklist(...) are here
}
}

But when I tried to profile the ordinary test, I figured out the PHPUnit does blacklist itself no matter if the code coverage is set on or off, which costs me additional ~1sec of tests execution.

Your solution would solve both cases by simply making the blacklisting cheap enough to be used all the time.
+1 for your patch

@johncrenshaw
Copy link
Author

lol, if the delay had only been 2 seconds that would have been fine. I was excluding the entire Zend Framework, which is more like a 30 second delay. The patch is also useful for excluding things like '.test.' which otherwise cannot be excluded.

@sebastianbergmann
Copy link
Owner

Closing, as the code this pull request is for is not part of PHPUnit anymore.

localheinz pushed a commit to localheinz/phpunit that referenced this pull request Sep 11, 2020
localheinz pushed a commit to localheinz/phpunit that referenced this pull request Oct 30, 2020
localheinz pushed a commit to localheinz/phpunit that referenced this pull request Oct 30, 2020
localheinz pushed a commit to localheinz/phpunit that referenced this pull request Nov 6, 2020
localheinz added a commit to localheinz/phpunit that referenced this pull request Nov 6, 2020
Co-authored-by: Andreas Möller <am@localheinz.com>
localheinz added a commit to localheinz/phpunit that referenced this pull request Nov 6, 2020
Co-authored-by: Andreas Möller <am@localheinz.com>
localheinz added a commit to localheinz/phpunit that referenced this pull request Nov 6, 2020
Co-authored-by: Andreas Möller <am@localheinz.com>
localheinz added a commit to localheinz/phpunit that referenced this pull request Nov 7, 2020
Co-authored-by: Andreas Möller <am@localheinz.com>
localheinz added a commit to localheinz/phpunit that referenced this pull request Nov 13, 2020
Co-authored-by: Andreas Möller <am@localheinz.com>
Co-authored-by: Arne Blankerts <Arne@Blankerts.de>
localheinz added a commit to localheinz/phpunit that referenced this pull request Nov 13, 2020
Co-authored-by: Andreas Möller <am@localheinz.com>
Co-authored-by: Arne Blankerts <Arne@Blankerts.de>
sebastianbergmann pushed a commit that referenced this pull request Nov 28, 2020
Co-authored-by: Andreas Möller <am@localheinz.com>
Co-authored-by: Arne Blankerts <Arne@Blankerts.de>
localheinz added a commit to localheinz/phpunit that referenced this pull request Dec 19, 2020
Co-authored-by: Andreas Möller <am@localheinz.com>
Co-authored-by: Arne Blankerts <Arne@Blankerts.de>
localheinz added a commit to localheinz/phpunit that referenced this pull request Dec 21, 2020
Co-authored-by: Andreas Möller <am@localheinz.com>
Co-authored-by: Arne Blankerts <Arne@Blankerts.de>
localheinz added a commit to localheinz/phpunit that referenced this pull request Dec 23, 2020
Co-authored-by: Andreas Möller <am@localheinz.com>
Co-authored-by: Arne Blankerts <Arne@Blankerts.de>
localheinz added a commit to localheinz/phpunit that referenced this pull request Dec 24, 2020
Co-authored-by: Andreas Möller <am@localheinz.com>
Co-authored-by: Arne Blankerts <Arne@Blankerts.de>
localheinz added a commit to localheinz/phpunit that referenced this pull request Dec 26, 2020
Co-authored-by: Andreas Möller <am@localheinz.com>
Co-authored-by: Arne Blankerts <Arne@Blankerts.de>
localheinz added a commit to localheinz/phpunit that referenced this pull request Dec 26, 2020
Co-authored-by: Andreas Möller <am@localheinz.com>
Co-authored-by: Arne Blankerts <Arne@Blankerts.de>
localheinz added a commit to localheinz/phpunit that referenced this pull request Dec 27, 2020
Co-authored-by: Andreas Möller <am@localheinz.com>
Co-authored-by: Arne Blankerts <Arne@Blankerts.de>
localheinz added a commit to localheinz/phpunit that referenced this pull request Dec 28, 2020
Co-authored-by: Andreas Möller <am@localheinz.com>
Co-authored-by: Arne Blankerts <Arne@Blankerts.de>
localheinz added a commit to localheinz/phpunit that referenced this pull request Dec 28, 2020
Co-authored-by: Andreas Möller <am@localheinz.com>
Co-authored-by: Arne Blankerts <Arne@Blankerts.de>
localheinz added a commit to localheinz/phpunit that referenced this pull request Dec 29, 2020
Co-authored-by: Andreas Möller <am@localheinz.com>
Co-authored-by: Arne Blankerts <Arne@Blankerts.de>
localheinz added a commit to localheinz/phpunit that referenced this pull request Dec 30, 2020
Co-authored-by: Andreas Möller <am@localheinz.com>
Co-authored-by: Arne Blankerts <Arne@Blankerts.de>
localheinz added a commit to localheinz/phpunit that referenced this pull request Jan 2, 2021
Co-authored-by: Andreas Möller <am@localheinz.com>
Co-authored-by: Arne Blankerts <Arne@Blankerts.de>
localheinz added a commit to localheinz/phpunit that referenced this pull request Jan 6, 2021
Co-authored-by: Andreas Möller <am@localheinz.com>
Co-authored-by: Arne Blankerts <Arne@Blankerts.de>
localheinz added a commit to localheinz/phpunit that referenced this pull request Jan 11, 2021
Co-authored-by: Andreas Möller <am@localheinz.com>
Co-authored-by: Arne Blankerts <Arne@Blankerts.de>
localheinz added a commit to localheinz/phpunit that referenced this pull request Jan 15, 2021
Co-authored-by: Andreas Möller <am@localheinz.com>
Co-authored-by: Arne Blankerts <Arne@Blankerts.de>
localheinz added a commit to localheinz/phpunit that referenced this pull request Jan 20, 2021
Co-authored-by: Andreas Möller <am@localheinz.com>
Co-authored-by: Arne Blankerts <Arne@Blankerts.de>
localheinz added a commit to localheinz/phpunit that referenced this pull request Jan 26, 2021
Co-authored-by: Andreas Möller <am@localheinz.com>
Co-authored-by: Arne Blankerts <Arne@Blankerts.de>
sebastianbergmann pushed a commit that referenced this pull request Jan 31, 2021
Co-authored-by: Andreas Möller <am@localheinz.com>
Co-authored-by: Arne Blankerts <Arne@Blankerts.de>
localheinz added a commit to localheinz/phpunit that referenced this pull request Feb 1, 2021
Co-authored-by: Andreas Möller <am@localheinz.com>
Co-authored-by: Arne Blankerts <Arne@Blankerts.de>
localheinz added a commit to localheinz/phpunit that referenced this pull request Feb 12, 2021
Co-authored-by: Andreas Möller <am@localheinz.com>
Co-authored-by: Arne Blankerts <Arne@Blankerts.de>
localheinz added a commit to localheinz/phpunit that referenced this pull request Feb 16, 2021
Co-authored-by: Andreas Möller <am@localheinz.com>
Co-authored-by: Arne Blankerts <Arne@Blankerts.de>
localheinz added a commit to localheinz/phpunit that referenced this pull request Feb 24, 2021
Co-authored-by: Andreas Möller <am@localheinz.com>
Co-authored-by: Arne Blankerts <Arne@Blankerts.de>
sebastianbergmann pushed a commit that referenced this pull request Mar 12, 2021
Co-authored-by: Andreas Möller <am@localheinz.com>
Co-authored-by: Arne Blankerts <Arne@Blankerts.de>
localheinz added a commit to localheinz/phpunit that referenced this pull request Mar 14, 2021
Co-authored-by: Andreas Möller <am@localheinz.com>
Co-authored-by: Arne Blankerts <Arne@Blankerts.de>
sebastianbergmann pushed a commit that referenced this pull request May 21, 2021
Co-authored-by: Andreas Möller <am@localheinz.com>
Co-authored-by: Arne Blankerts <Arne@Blankerts.de>
partikus pushed a commit to zf1s/phpunit that referenced this pull request Oct 4, 2022
…support

support for wildcards (glob) in exclude
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants