qa:whattotest
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionNext revisionBoth sides next revision | ||
qa:whattotest [2008/05/06 15:01] – add note about imap and gd already being focused on outside of the testfest lsmith | qa:whattotest [2008/05/07 12:52] – more minor format changes zoe | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ==== More information on what to test ==== | + | ====== More information on what to test ====== |
There are currently independent efforts underway to improve the testing for the IMAP and GD extension. Therefore these two extensions should not be focused on during a testfest in May 08. | There are currently independent efforts underway to improve the testing for the IMAP and GD extension. Therefore these two extensions should not be focused on during a testfest in May 08. | ||
Line 7: | Line 7: | ||
You can tell a certain amount from line coverage - but it doesn' | You can tell a certain amount from line coverage - but it doesn' | ||
- | I've put the source code for two scripts below - both are a little unfinished, I will go on tidying them up. | + | I've put the source code for two scripts below - both are a little unfinished, I will go on tidying them up. |
+ | **Note** Both scripts look at **functions** and are not any help if you are looking at a PHP 5 OO extension. | ||
- | 1) This script runs through all of the phpt tests in the source tree and then compares the function calls in the tests with a complete list of PHP's internal functions. At the end it will tell you if there is a function in PHP that is not mentioned in any test case (I get 415). Thanks to Damien Seguy for this. | ||
- | [[http:// | + | ==== Script 1 ==== |
+ | This script runs through all of the phpt tests in the source tree and then compares the function calls in the tests with a complete list of PHP's internal functions. At the end it will tell you if there is a function in PHP that is not mentioned in any test case (I get 415). Thanks to Damien Seguy for this. | ||
+ | <code php> | ||
+ | <?php | ||
- | 2) A slight modification to Damien's script. In this case the script will print out what test cases each function is mentioned in. This doesn't mean that the function is properly tested in each one, just that it's used. For example, if you look at the output for 'cos' you will see three tests which are clearly meant to be testing ' | + | // define here your PHP source directory |
+ | define('PHP_SRC',' | ||
- | [[http://pastebin.com/ | + | //Get a list of all of the test (phpt) files in the source tree. |
+ | $files = array(); | ||
+ | get_phpt_files(PHP_SRC, | ||
+ | //Find all the functions that are called in the test case code | ||
+ | $tested = array(); | ||
+ | foreach($files as $file) { | ||
+ | $tested = array_merge(extract_tests($file), | ||
+ | } | ||
+ | $tested = array_unique($tested); | ||
+ | // | ||
+ | //Get a list of all of the internal PHP functions | ||
+ | $internal = get_defined_functions(); | ||
+ | $internal = $internal[' | ||
+ | |||
+ | //Compare the list of all function with those that are called from a phpt test case. | ||
+ | $non_tested = array_diff($internal, | ||
+ | print_r($non_tested); | ||
+ | print count($non_tested). " untested functions\n"; | ||
+ | |||
+ | |||
+ | function | ||
+ | $code = file_get_contents($file); | ||
+ | |||
+ | if (!preg_match('/ | ||
+ | // print " | ||
+ | return array(); | ||
+ | } | ||
+ | |||
+ | $tokens = token_get_all($r[1]); | ||
+ | $functions = array_filter($tokens, | ||
+ | $functions = array_map( ' | ||
+ | $functions = array_unique($functions); | ||
+ | |||
+ | return $functions; | ||
+ | } | ||
+ | |||
+ | function filter_functions($x) { | ||
+ | return $x[0] == 307; | ||
+ | } | ||
+ | |||
+ | function map_token_value($x) { | ||
+ | return $x[1]; | ||
+ | } | ||
+ | function get_phpt_files($dir, | ||
+ | { | ||
+ | $thisdir = dir($dir.'/' | ||
+ | while(($file = $thisdir-> | ||
+ | if ($file != ' | ||
+ | $path = $thisdir-> | ||
+ | if(is_dir($path) == true) { | ||
+ | get_phpt_files($path , $phpt_file_count , $all_phpt); | ||
+ | } else { | ||
+ | if (preg_match("/ | ||
+ | $all_phpt[$phpt_file_count] = $path; | ||
+ | $phpt_file_count++; | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | return; | ||
+ | } | ||
+ | |||
+ | |||
+ | ?> | ||
+ | </ | ||
+ | |||
+ | |||
+ | ==== Script 2 ==== | ||
+ | A slight modification to Damien' | ||
+ | <code php> | ||
+ | <?php | ||
+ | // define here your PHP source directory | ||
+ | define(' | ||
+ | |||
+ | //Get a list of all of the test (phpt) files in the source tree. | ||
+ | $files = array(); | ||
+ | get_phpt_files(PHP_SRC, | ||
+ | |||
+ | |||
+ | $tests_by_function=array(); | ||
+ | |||
+ | //Get a list of all of the internal PHP functions | ||
+ | $internal = get_defined_functions(); | ||
+ | $internal = $internal[' | ||
+ | foreach($internal as $function) { | ||
+ | $tests_by_function[$function] = array(); | ||
+ | } | ||
+ | |||
+ | //Find all the functions that are called in the test case code | ||
+ | $tested = array(); | ||
+ | $temp_array = array(); | ||
+ | |||
+ | foreach($files as $file) { | ||
+ | $temp_array = extract_tests($file); | ||
+ | $tested = array_merge($temp_array, | ||
+ | foreach($temp_array as $function) { | ||
+ | if(array_key_exists($function, | ||
+ | array_push($tests_by_function[$function], | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | $tested = array_unique($tested); | ||
+ | print_r($tests_by_function); | ||
+ | |||
+ | |||
+ | function | ||
+ | $code = file_get_contents($file); | ||
+ | |||
+ | if (!preg_match('/ | ||
+ | // print " | ||
+ | return array(); | ||
+ | } | ||
+ | |||
+ | $tokens = token_get_all($r[1]); | ||
+ | $functions = array_filter($tokens, | ||
+ | $functions = array_map( ' | ||
+ | $functions = array_unique($functions); | ||
+ | |||
+ | return $functions; | ||
+ | } | ||
+ | |||
+ | function filter_functions($x) { | ||
+ | return $x[0] == 307; | ||
+ | } | ||
+ | |||
+ | function map_token_value($x) { | ||
+ | return $x[1]; | ||
+ | } | ||
+ | function get_phpt_files($dir, | ||
+ | { | ||
+ | $thisdir = dir($dir.'/' | ||
+ | while(($file = $thisdir-> | ||
+ | if ($file != ' | ||
+ | $path = $thisdir-> | ||
+ | if(is_dir($path) == true) { | ||
+ | get_phpt_files($path , $phpt_file_count , $all_phpt); | ||
+ | } else { | ||
+ | if (preg_match("/ | ||
+ | $all_phpt[$phpt_file_count] = $path; | ||
+ | $phpt_file_count++; | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | return; | ||
+ | } | ||
+ | |||
+ | |||
+ | ?> | ||
+ | </ | ||
+ | |||
+ | ==== Script 3 ==== | ||
+ | |||
+ | <code php> | ||
+ | <?php | ||
+ | // define here your PHP source directory | ||
+ | define(' | ||
+ | |||
+ | //Get a list of all of the test (phpt) files in the source tree. | ||
+ | $files = array(); | ||
+ | get_phpt_files(PHP_SRC, | ||
+ | |||
+ | |||
+ | $tests_by_method=array(); | ||
+ | $class_by_method=array(); | ||
+ | |||
+ | //Get a list of all of the PHP classes | ||
+ | $classes = get_declared_classes(); | ||
+ | |||
+ | $methodArray = array(); | ||
+ | $methodNameArray = array(); | ||
+ | $method_names = array(); | ||
+ | |||
+ | //Get the method names from each class | ||
+ | foreach($classes as $class) { | ||
+ | $classInfo = new ReflectionClass($class); | ||
+ | $methodArray = $classInfo-> | ||
+ | $method_names = get_method_names($methodArray); | ||
+ | $class_by_method[$class] = array(); | ||
+ | array_push($class_by_method[$class], | ||
+ | $methodNameArray = array_merge($method_names, | ||
+ | foreach($method_names as $method) { | ||
+ | $tests_by_method[$method] = array(); | ||
+ | } | ||
+ | } | ||
+ | |||
+ | //Find all the functions that are called in the test case code | ||
+ | $tested = array(); | ||
+ | $temp_array = array(); | ||
+ | |||
+ | foreach($files as $file) { | ||
+ | $temp_array = extract_tests($file); | ||
+ | $tested = array_merge($temp_array, | ||
+ | foreach($temp_array as $function) { | ||
+ | if(array_key_exists($function, | ||
+ | array_push($tests_by_method[$function], | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | //Print out the tests in which methods are used | ||
+ | //print_r ($class_by_method); | ||
+ | foreach($classes as $class) { | ||
+ | echo " | ||
+ | foreach($class_by_method[$class] as $methods) { | ||
+ | foreach($methods as $method) { | ||
+ | if(!preg_match('/ | ||
+ | echo " | ||
+ | foreach($tests_by_method[$method] as $test) { | ||
+ | echo "Test: " | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | |||
+ | |||
+ | function | ||
+ | $code = file_get_contents($file); | ||
+ | |||
+ | if (!preg_match('/ | ||
+ | // print " | ||
+ | return array(); | ||
+ | } | ||
+ | |||
+ | $tokens = token_get_all($r[1]); | ||
+ | $functions = array_filter($tokens, | ||
+ | $functions = array_map( ' | ||
+ | $functions = array_unique($functions); | ||
+ | return $functions; | ||
+ | } | ||
+ | |||
+ | function filter_functions($x) { | ||
+ | return $x[0] == 307; | ||
+ | } | ||
+ | |||
+ | function map_token_value($x) { | ||
+ | return $x[1]; | ||
+ | } | ||
+ | function get_phpt_files($dir, | ||
+ | { | ||
+ | $thisdir = dir($dir.'/' | ||
+ | while(($file = $thisdir-> | ||
+ | if ($file != ' | ||
+ | $path = $thisdir-> | ||
+ | if(is_dir($path) == true) { | ||
+ | get_phpt_files($path , $phpt_file_count , $all_phpt); | ||
+ | } else { | ||
+ | if (preg_match("/ | ||
+ | $all_phpt[$phpt_file_count] = $path; | ||
+ | $phpt_file_count++; | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | return; | ||
+ | } | ||
+ | function get_method_names($methodArray) { | ||
+ | $names = array(); | ||
+ | foreach ($methodArray as $method) { | ||
+ | array_push($names, | ||
+ | } | ||
+ | return $names; | ||
+ | } | ||
+ | |||
+ | ?> | ||
+ | </ |
qa/whattotest.txt · Last modified: 2017/09/22 13:28 by 127.0.0.1