cvs: php4 / run-tests.php
| From: | Marcus B�rger | Date: | Mon, 26 Aug 2002 23:26:47 +0000 |
| Subject: | cvs: php4 / run-tests.php | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-13687@lists.php.net to get a copy of this message | ||
helly Mon Aug 26 19:26:47 2002 EDT
Modified files:
/php4 run-tests.php
Log:
-reimplemented old style output (.exp, .out)
-implemented diff format output
-delete error logs on success
@Changed regression tests produce selectable error reports. The tests now
@recognize environment variable TEST_PHP_LOG_FORMAT which can
@contain O and E for old style .out and .exp files, L for new .log format and
@D for an internal diff format that does not require systems diff. (Marcus)
#diff output makes it easier to detect the failure on huge or combined tests.
#It was discussed that the php function's diff output has the advantage that
#it is available on every system. Everyone insisting on systems diff may
#use diff on .exp and .out files.
Index: php4/run-tests.php
diff -u php4/run-tests.php:1.53 php4/run-tests.php:1.54
--- php4/run-tests.php:1.53 Wed Aug 21 19:06:38 2002
+++ php4/run-tests.php Mon Aug 26 19:26:46 2002
@@ -67,6 +67,12 @@
error("environment variable TEST_PHP_EXECUTABLE must be set to specify PHP
executable!");
}
+if(isset($_ENV['TEST_PHP_LOG_FORMAT'])) {
+ $log_format = strtoupper($_ENV['TEST_PHP_LOG_FORMAT']);
+} else {
+ $log_format = 'LEOD';
+}
+
if(!@is_executable($php)) {
error("invalid PHP executable specified by TEST_PHP_EXECUTABLE = " . $php);
}
@@ -262,6 +268,8 @@
function run_test($php,$file)
{
+ global $log_format;
+
if (DETAILED) echo "
=================
TEST $file
@@ -389,6 +397,12 @@
@unlink($tmp_post);
@unlink($tmp_file);
+ // unlink old test results
+ @unlink(ereg_replace('\.phpt$','.diff',$file));
+ @unlink(ereg_replace('\.phpt$','.log',$file));
+ @unlink(ereg_replace('\.phpt$','.exp',$file));
+ @unlink(ereg_replace('\.phpt$','.out',$file));
+
// Does the output match what is expected?
$output = trim($out);
@@ -396,7 +410,8 @@
$output = preg_replace('/\r\n/',"\n",$output);
$wanted = preg_replace('/\r\n/',"\n",$wanted);
-
+
+ // compare and leave on success
$ok = (0 == strcmp($output,$wanted));
if ($ok) {
echo "PASS $tested\n";
@@ -404,25 +419,62 @@
}
// Test failed so we need to report details.
-
echo "FAIL $tested\n";
- $logname = ereg_replace('\.phpt$','.log',$file);
- $log = fopen($logname,'w')
- or error("Cannot create test log - $logname");
-
- fwrite($log,"
+ // write .exp
+ if (strpos($log_format,'E')!==false) {
+ $logname = ereg_replace('\.phpt$','.exp',$file);
+ $log = fopen($logname,'w') or error("Cannot create test log - $logname");
+ fwrite($log,$wanted);
+ fclose($log);
+ }
+
+ // write .out
+ if (strpos($log_format,'O')!==false) {
+ $logname = ereg_replace('\.phpt$','.out',$file);
+ $log = fopen($logname,'w') or error("Cannot create test log - $logname");
+ fwrite($log,$output);
+ fclose($log);
+ }
+
+ // write .diff
+ if (strpos($log_format,'D')!==false) {
+ $logname = ereg_replace('\.phpt$','.diff',$file);
+ $log = fopen($logname,'w') or error("Cannot create test log - $logname");
+ fwrite($log,generate_diff($wanted,$output));
+ fclose($log);
+ }
+
+ // write .log
+ if (strpos($log_format,'L')!==false) {
+ $logname = ereg_replace('\.phpt$','.log',$file);
+ $log = fopen($logname,'w') or error("Cannot create test log - $logname");
+ fwrite($log,"
---- EXPECTED OUTPUT
$wanted
---- ACTUAL OUTPUT
$output
---- FAILED
");
- fclose($log);
+ fclose($log);
+ error_report($file,$logname,$tested);
+ }
- error_report($file,$logname,$tested);
-
return 'FAILED';
+}
+
+function generate_diff($wanted,$output) {
+ $w = explode("\n", $wanted);
+ $o = explode("\n", $output);
+ $w1 = array_diff($w,$o);
+ $o1 = array_diff($o,$w);
+ $w2 = array();
+ $o2 = array();
+ foreach($w1 as $idx => $val) $w2[sprintf("%03d<",$idx)] = sprintf("%03d-
$val", $idx+1);
+ foreach($o1 as $idx => $val) $o2[sprintf("%03d>",$idx)] = sprintf("%03d+
$val", $idx+1);
+ $diff = array_merge($w2, $o2);
+ ksort($diff);
+ return implode("\r\n", $diff);
}
function error($message) {