WordPress.org

Make WordPress Core

Changeset 525 in tests


Ignore:
Timestamp:
02/10/12 14:28:14 (2 years ago)
Author:
westi
Message:

Introduce a simple way to run a group of tests with similar names e.g. all the xmlrpc tests.
I tried implementing something based on the PHPUnit @group auto-grouping but couldn't get it working with our custom runner so went with a simple approach instead.

Files:
2 edited

Legend:

Unmodified
Added
Removed
  • wp-test.php

    r507 r525  
    2424 *   - -t  Specific test class names to be run (separated by spaces or commas) 
    2525 *   - -v  Sets WP_DIR to "DIR_TESTROOT/wordpress-<value>".  Overridden by -r. 
     26 *   - -g  Runs a group of test cases by matching part of the test class name 
    2627 */ 
    2728 
    2829// parse options 
    29 $options = 'r:t:v:dfhlmnpqs'; 
     30$options = 'g:r:t:v:dfhlmnpqs'; 
    3031if (is_callable('getopt')) { 
    3132    $opts = getopt($options); 
     
    5960  -t  Specific test class names to be run (separated by spaces or commas) 
    6061  -v  Sets WP_DIR to "DIR_TESTROOT/wordpress-<value>".  Overridden by -r. 
     62  -g  Runs a group of test cases by matching part of the test class name 
    6163 
    6264EOH; 
     
    205207    } 
    206208    // run the tests and print the results 
    207     list ($result, $printer) = wptest_run_tests($classes, isset($opts['t']) ? $opts['t'] : array()); 
     209    list ($result, $printer) = wptest_run_tests($classes, isset($opts['t']) ? $opts['t'] : array(), isset($opts['g']) ? $opts['g'] : null ); 
    208210    wptest_print_result($printer,$result); 
    209211} 
  • wp-testlib/base.php

    r504 r525  
    498498    } 
    499499    closedir($dh); 
    500  
    501500    return $tests; 
    502501} 
     
    541540} 
    542541 
    543 function wptest_run_tests($classes, $classnames = array()) { 
     542function wptest_run_tests($classes, $classnames = array(), $filter = null ) { 
    544543    $suite = new PHPUnit_Framework_TestSuite(); 
    545544 
     
    551550 
    552551    foreach ( $classes as $testcase ) { 
    553         if ( empty($classnames) || in_array( strtolower($testcase), $classnames ) ) { 
     552        if ( ( empty($classnames) || in_array( strtolower( $testcase ), $classnames ) ) && 
     553             ( is_null( $filter ) || strstr( $testcase, $filter ) ) 
     554            ) { 
    554555            $suite->addTestSuite($testcase); 
    555556        } 
     
    561562    $printer = new PHPUnit_TextUI_ResultPrinter(NULL, WP_PHPUNIT_VERBOSE, !stristr(PHP_OS, 'WIN') ); 
    562563    $result->addListener($printer); 
    563     return array($suite->run($result), $printer); 
     564    return array($suite->run($result, FALSE ), $printer); 
    564565} 
    565566 
Note: See TracChangeset for help on using the changeset viewer.