From f408407620b04e09fbb5d2df2ba6dc51e4abe6e9 Mon Sep 17 00:00:00 2001 From: Boone Gorges Date: Fri, 2 Oct 2015 13:50:12 +0000 Subject: [PATCH] Improvements to PCRE benchmarking tests. * Add test file accidentally omitted from [34761]. * Bail properly from benchmarker when a `preg_last_error()` is found. Props miqrogroove. See #34121. git-svn-id: https://develop.svn.wordpress.org/trunk@34773 602fd350-edb4-49c9-b593-d223f7449a82 --- tests/phpunit/includes/utils.php | 9 ++-- .../phpunit/tests/formatting/WpHtmlSplit.php | 53 +++++++++++++++++++ 2 files changed, 58 insertions(+), 4 deletions(-) create mode 100644 tests/phpunit/tests/formatting/WpHtmlSplit.php diff --git a/tests/phpunit/includes/utils.php b/tests/phpunit/includes/utils.php index e95323a2e0..5f1d6c4b25 100644 --- a/tests/phpunit/includes/utils.php +++ b/tests/phpunit/includes/utils.php @@ -433,15 +433,16 @@ function benchmark_pcre_backtracking( $pattern, $subject, $strategy ) { continue; case PREG_RECURSION_LIMIT_ERROR: trigger_error('PCRE recursion limit encountered before backtrack limit.'); - break; + return; case PREG_BAD_UTF8_ERROR: trigger_error('UTF-8 error during PCRE benchmark.'); - break; + return; case PREG_INTERNAL_ERROR: trigger_error('Internal error during PCRE benchmark.'); - break; + return; default: - trigger_error('Unexpected error during PCRE benchmark.'); + trigger_error('Unexpected error during PCRE benchmark.'); + return; } } diff --git a/tests/phpunit/tests/formatting/WpHtmlSplit.php b/tests/phpunit/tests/formatting/WpHtmlSplit.php new file mode 100644 index 0000000000..363177f723 --- /dev/null +++ b/tests/phpunit/tests/formatting/WpHtmlSplit.php @@ -0,0 +1,53 @@ +assertEquals( $output, wp_html_split( $input ) ); + } + + function data_basic_features() { + return array( + array( + 'abcd efgh', + array( 'abcd efgh' ), + ), + array( + 'abcd efgh', + array( 'abcd ', '', ' efgh' ), + ), + array( + 'abcd efgh', + array( 'abcd ', '', ' efgh' ), + ), + array( + 'abcd ]]> efgh', + array( 'abcd ', ' ]]>', ' efgh' ), + ), + ); + } + + /** + * Automated performance testing of the main regex. + * + * @dataProvider data_whole_posts + */ + function test_pcre_performance( $input ) { + $regex = get_html_split_regex(); + $result = benchmark_pcre_backtracking( $regex, $input, 'split' ); + return $this->assertLessThan( 200, $result ); + } + + function data_whole_posts() { + require_once( DIR_TESTDATA . '/formatting/whole-posts.php' ); + return data_whole_posts(); + } +}