cvs: pear-core /PEAR RunTest.php
| From: | Greg Beaver | Date: | Sat, 17 Feb 2007 05:41:32 +0000 |
| Subject: | cvs: pear-core /PEAR RunTest.php | ||
| Groups: | php.pear.cvs php.pear.core | ||
| Request: | Send a blank email to pear-core+get-5435@lists.php.net to get a copy of this message | ||
cellog Sat Feb 17 05:41:32 2007 UTC
Modified files:
/pear-core/PEAR RunTest.php
Log:
- .exp expected output was not being overwritten by .log
- basic environment not passed to child php test process
- implement --FAIL-- for tests that should fail
http://cvs.php.net/viewvc.cgi/pear-core/PEAR/RunTest.php?r1=1.30&r2=1.31&diff_format=u
Index: pear-core/PEAR/RunTest.php
diff -u pear-core/PEAR/RunTest.php:1.30 pear-core/PEAR/RunTest.php:1.31
--- pear-core/PEAR/RunTest.php:1.30 Sat Feb 17 04:38:27 2007
+++ pear-core/PEAR/RunTest.php Sat Feb 17 05:41:32 2007
@@ -16,7 +16,7 @@
* @author Greg Beaver <cellog@php.net>
* @copyright 1997-2006 The PHP Group
* @license http://www.php.net/license/3_0.txt
PHP License 3.0
- * @version CVS: $Id: RunTest.php,v 1.30 2007/02/17 04:38:27 cellog Exp $
+ * @version CVS: $Id: RunTest.php,v 1.31 2007/02/17 05:41:32 cellog Exp $
* @link http://pear.php.net/package/PEAR
* @since File available since Release 1.3.3
*/
@@ -354,6 +354,7 @@
$savedir = getcwd(); // in case the test moves us around
// Reset environment from any previous test.
+ $env = $_ENV;
$env['REDIRECT_STATUS']='';
$env['QUERY_STRING']='';
$env['PATH_TRANSLATED']='';
@@ -469,54 +470,87 @@
}
}
- if (isset($section_text['EXPECTF']) ||
isset($section_text['EXPECTREGEX'])) {
- if (isset($section_text['EXPECTF'])) {
- $wanted = trim($section_text['EXPECTF']);
- } else {
- $wanted = trim($section_text['EXPECTREGEX']);
- }
- $wanted_re = preg_replace('/\r\n/',"\n",$wanted);
- if (isset($section_text['EXPECTF'])) {
- $wanted_re = preg_quote($wanted_re, '/');
- // Stick to basics
- $wanted_re = str_replace("%s", ".+?", $wanted_re); //not greedy
- $wanted_re = str_replace("%i", "[+\-]?[0-9]+", $wanted_re);
- $wanted_re = str_replace("%d", "[0-9]+", $wanted_re);
- $wanted_re = str_replace("%x", "[0-9a-fA-F]+", $wanted_re);
- $wanted_re = str_replace("%f",
"[+\-]?\.?[0-9]+\.?[0-9]*(E-?[0-9]+)?", $wanted_re);
- $wanted_re = str_replace("%c", ".", $wanted_re);
- // %f allows two points "-.0.0" but that is the best *simple* expression
- }
+ do {
+ if (isset($section_text['EXPECTF']) ||
isset($section_text['EXPECTREGEX'])) {
+ if (isset($section_text['EXPECTF'])) {
+ $wanted = trim($section_text['EXPECTF']);
+ } else {
+ $wanted = trim($section_text['EXPECTREGEX']);
+ }
+ $wanted_re = preg_replace('/\r\n/',"\n",$wanted);
+ if (isset($section_text['EXPECTF'])) {
+ $wanted_re = preg_quote($wanted_re, '/');
+ // Stick to basics
+ $wanted_re = str_replace("%s", ".+?", $wanted_re); //not
greedy
+ $wanted_re = str_replace("%i", "[+\-]?[0-9]+", $wanted_re);
+ $wanted_re = str_replace("%d", "[0-9]+", $wanted_re);
+ $wanted_re = str_replace("%x", "[0-9a-fA-F]+", $wanted_re);
+ $wanted_re = str_replace("%f",
"[+\-]?\.?[0-9]+\.?[0-9]*(E-?[0-9]+)?", $wanted_re);
+ $wanted_re = str_replace("%c", ".", $wanted_re);
+ // %f allows two points "-.0.0" but that is the best *simple*
expression
+ }
/* DEBUG YOUR REGEX HERE
var_dump($wanted_re);
print(str_repeat('=', 80) . "\n");
var_dump($output);
*/
- if (!$returnfail && preg_match("/^$wanted_re\$/s", $output)) {
- if (file_exists($temp_file)) {
- unlink($temp_file);
- }
- if (!isset($this->_options['quiet'])) {
- $this->_logger->log(0, "PASS $tested$info");
- }
- if (isset($old_php)) {
- $php = $old_php;
+ if (!$returnfail && preg_match("/^$wanted_re\$/s", $output)) {
+ if (file_exists($temp_file)) {
+ unlink($temp_file);
+ }
+
+ if (array_key_exists('FAIL', $section_text)) {
+ break;
+ }
+ if (!isset($this->_options['quiet'])) {
+ $this->_logger->log(0, "PASS $tested$info");
+ }
+ if (isset($old_php)) {
+ $php = $old_php;
+ }
+ if (isset($this->_options['tapoutput'])) {
+ return array('ok', ' - ' . $tested);
+ }
+ return 'PASSED';
}
- if (isset($this->_options['tapoutput'])) {
- return array('ok', ' - ' . $tested);
+
+ } else {
+ $wanted = trim($section_text['EXPECT']);
+ $wanted = preg_replace('/\r\n/',"\n",$wanted);
+ // compare and leave on success
+ $ok = (0 == strcmp($output,$wanted));
+ if (!$returnfail && $ok) {
+ if (file_exists($temp_file)) {
+ unlink($temp_file);
+ }
+ if (array_key_exists('FAIL', $section_text)) {
+ break;
+ }
+ if (!isset($this->_options['quiet'])) {
+ $this->_logger->log(0, "PASS $tested$info");
+ }
+ if (isset($old_php)) {
+ $php = $old_php;
+ }
+ if (isset($this->_options['tapoutput'])) {
+ return array('ok', ' - ' . $tested);
+ }
+ return 'PASSED';
}
- return 'PASSED';
}
+ } while (false);
- } else {
- $wanted = trim($section_text['EXPECT']);
- $wanted = preg_replace('/\r\n/',"\n",$wanted);
- // compare and leave on success
- $ok = (0 == strcmp($output,$wanted));
- if (!$returnfail && $ok) {
- if (file_exists($temp_file)) {
- unlink($temp_file);
- }
+ if (array_key_exists('FAIL', $section_text)) {
+ // we expect a particular failure
+ // this is only used for testing PEAR_RunTest
+ $faildiff = $this->generate_diff(
+ $wanted,
+ $output,
+ null,
+ isset($section_text['EXPECTF']) ? $wanted_re : null);
+ $wanted = explode("\n", trim($section_text['FAIL']));
+ $wanted = implode("\r\n", $wanted);
+ if ($faildiff == $wanted) {
if (!isset($this->_options['quiet'])) {
$this->_logger->log(0, "PASS $tested$info");
}
@@ -528,6 +562,12 @@
}
return 'PASSED';
}
+ unset($section_text['EXPECTF']);
+ $output = $faildiff;
+ if (isset($section_text['RETURNS'])) {
+ return PEAR::raiseError('Cannot have both RETURNS and FAIL in the same test:
' .
+ $file);
+ }
}
// Test failed so we need to report details.
@@ -558,7 +598,7 @@
// write .exp
if (strpos($log_format,'E') !== FALSE) {
- $logname = $log_filename;
+ $logname = $exp_filename;
if (!$log = fopen($logname,'w')) {
return PEAR::raiseError("Cannot create test log - $logname");
}