2000-08-28 03:46:06 +08:00
|
|
|
<?php
|
2000-08-29 17:12:44 +08:00
|
|
|
/*
|
|
|
|
+----------------------------------------------------------------------+
|
|
|
|
| PHP version 4.0 |
|
|
|
|
+----------------------------------------------------------------------+
|
2001-02-26 14:11:02 +08:00
|
|
|
| Copyright (c) 1997-2001 The PHP Group |
|
2000-08-29 17:12:44 +08:00
|
|
|
+----------------------------------------------------------------------+
|
|
|
|
| This source file is subject to version 2.02 of the PHP license, |
|
|
|
|
| that is bundled with this package in the file LICENSE, and is |
|
|
|
|
| available at through the world-wide-web at |
|
|
|
|
| http://www.php.net/license/2_02.txt. |
|
|
|
|
| If you did not receive a copy of the PHP license and are unable to |
|
|
|
|
| obtain it through the world-wide-web, please send a note to |
|
|
|
|
| license@php.net so we can mail you a copy immediately. |
|
|
|
|
+----------------------------------------------------------------------+
|
|
|
|
| Authors: Stig Bakken <ssb@fast.no> |
|
|
|
|
| (based on the PHP 3 test framework by Rasmus Lerdorf) |
|
|
|
|
+----------------------------------------------------------------------+
|
|
|
|
*/
|
|
|
|
|
2000-12-08 08:21:09 +08:00
|
|
|
/*
|
|
|
|
* TODO:
|
|
|
|
* - look for test-specific php.ini files
|
2001-03-21 14:04:36 +08:00
|
|
|
* - implement module skipping for PEAR
|
|
|
|
* - do not test PEAR components if base class and/or component class cannot be instanciated
|
2000-12-08 08:21:09 +08:00
|
|
|
*/
|
|
|
|
|
2000-10-23 15:40:05 +08:00
|
|
|
ob_implicit_flush();
|
2000-08-28 03:46:06 +08:00
|
|
|
|
|
|
|
define('TEST_PASSED', 0);
|
|
|
|
define('TEST_FAILED', -1);
|
|
|
|
define('TEST_SKIPPED', -2);
|
|
|
|
define('TEST_INTERNAL_ERROR', -3);
|
|
|
|
|
2001-03-21 14:04:36 +08:00
|
|
|
define('EXT_DIR_NAME','/php4/ext/');
|
|
|
|
define('EXT_DIR_NAME_LEN',strlen(EXT_DIR_NAME));
|
|
|
|
|
2000-08-28 03:46:06 +08:00
|
|
|
initialize();
|
2000-08-29 17:12:44 +08:00
|
|
|
/*
|
2000-08-28 03:46:06 +08:00
|
|
|
$opts = parse_options(&$argc, &$argv);
|
|
|
|
if ($opts['help']) {
|
|
|
|
usage();
|
|
|
|
exit;
|
|
|
|
}
|
2000-08-29 17:12:44 +08:00
|
|
|
*/
|
2000-09-03 17:37:20 +08:00
|
|
|
do_testing($argc, $argv);
|
2000-08-28 03:46:06 +08:00
|
|
|
|
|
|
|
exit;
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
2000-12-08 08:21:09 +08:00
|
|
|
function usage()
|
|
|
|
{
|
2000-12-15 10:57:11 +08:00
|
|
|
dowriteln("Usage: run-tests.php [-d] [-h] [dir|file...]");
|
2000-08-28 03:46:06 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2000-12-15 10:57:11 +08:00
|
|
|
* Please use dowrite() and dowriteln() for all screen output.
|
2000-08-28 03:46:06 +08:00
|
|
|
* This makes it easier to convert to HTML output later.
|
|
|
|
*/
|
|
|
|
|
2000-12-13 22:24:15 +08:00
|
|
|
function dowrite($str)
|
2000-12-08 08:21:09 +08:00
|
|
|
{
|
2000-08-28 03:46:06 +08:00
|
|
|
global $term_bold, $term_norm;
|
|
|
|
$str = str_replace("%b", $term_bold, $str);
|
|
|
|
$str = str_replace("%B", $term_norm, $str);
|
|
|
|
print $str;
|
|
|
|
}
|
|
|
|
|
2000-12-13 22:24:15 +08:00
|
|
|
function dowriteln($str)
|
2000-12-08 08:21:09 +08:00
|
|
|
{
|
2000-12-13 22:24:15 +08:00
|
|
|
dowrite("$str\n");
|
2000-08-28 03:46:06 +08:00
|
|
|
}
|
|
|
|
|
2001-03-21 14:04:36 +08:00
|
|
|
function create_compiled_in_modules_list() {
|
2001-05-03 00:39:04 +08:00
|
|
|
global $compiled_in_modules;
|
|
|
|
$compiled_in_modules = @get_loaded_extensions();
|
2001-03-21 14:04:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
function extract_module_name_from_path($path) {
|
|
|
|
if ($pos1=strpos($path,EXT_DIR_NAME)) {
|
|
|
|
$pos3=strpos($path,'/',$pos1+EXT_DIR_NAME_LEN);
|
|
|
|
return substr($path,$pos2=$pos1+EXT_DIR_NAME_LEN,$pos3-$pos2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function create_found_tests_4_modules_list() {
|
|
|
|
global $modules_2_test,$testdirs;
|
|
|
|
|
|
|
|
foreach ($testdirs AS $path) {
|
|
|
|
if ($mod_name=extract_module_name_from_path($path))
|
|
|
|
$modules_2_test[$mod_name]=TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function create_modules_2_test_list() {
|
|
|
|
global $compiled_in_modules,$modules_2_test,$modules_available;
|
|
|
|
foreach ($compiled_in_modules AS $value)
|
|
|
|
if ($modules_2_test[$value]) $modules_available[]=$value;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2001-08-28 04:17:36 +08:00
|
|
|
function in_path($program, $windows_p)
|
2001-08-28 00:39:49 +08:00
|
|
|
{
|
|
|
|
global $HTTP_ENV_VARS;
|
2001-08-28 04:17:36 +08:00
|
|
|
if ($windows_p) {
|
2001-08-28 00:39:49 +08:00
|
|
|
$delim = ";";
|
|
|
|
$ext = ".exe";
|
|
|
|
} else {
|
|
|
|
$delim = ":";
|
|
|
|
$ext = "";
|
|
|
|
}
|
|
|
|
$slash = DIRECTORY_SEPARATOR;
|
|
|
|
$path_components = explode($delim, $HTTP_ENV_VARS['PATH']);
|
2001-08-28 04:17:36 +08:00
|
|
|
if ($windows_p) {
|
|
|
|
$cwd = getcwd() . DIRECTORY_SEPARATOR;
|
|
|
|
array_unshift($path_components, "{$cwd}Release_TS_Inline", "{$cwd}Release_TS");
|
|
|
|
}
|
2001-08-28 00:39:49 +08:00
|
|
|
foreach ($path_components as $path) {
|
|
|
|
$test = "{$path}{$slash}php{$ext}";
|
|
|
|
if (@is_executable($test)) {
|
|
|
|
return $test;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-12-08 08:21:09 +08:00
|
|
|
function initialize()
|
|
|
|
{
|
2000-08-28 03:46:06 +08:00
|
|
|
global $term, $windows_p, $php, $skip, $testdirs, $tmpfile,
|
2000-12-08 08:21:09 +08:00
|
|
|
$skipped, $failed, $passed, $total, $term_bold, $term_norm,
|
|
|
|
$tests_in_dir;
|
2000-08-28 03:46:06 +08:00
|
|
|
|
|
|
|
// XXX Should support HTML output as well.
|
2001-08-28 00:39:49 +08:00
|
|
|
$php = "";
|
|
|
|
if((substr(PHP_OS, 0, 3) == "WIN")) {
|
|
|
|
$ext = ".exe";
|
|
|
|
$windows_p = true;
|
|
|
|
$term = getenv("COMSPEC");
|
2000-08-28 03:46:06 +08:00
|
|
|
} else {
|
2001-08-28 00:39:49 +08:00
|
|
|
$ext = "";
|
|
|
|
$term = getenv("TERM");
|
|
|
|
if (ereg('^(xterm|vt220)', $term)) {
|
|
|
|
$term_bold = sprintf("%c%c%c%c", 27, 91, 49, 109);
|
|
|
|
$term_norm = sprintf("%c%c%c", 27, 91, 109);
|
|
|
|
} elseif (ereg('^vt100', $term)) {
|
|
|
|
$term_bold = sprintf("%c%c%c%c", 27, 91, 49, 109);
|
|
|
|
$term_norm = sprintf("%c%c%c", 27, 91, 109);
|
2001-04-17 07:28:58 +08:00
|
|
|
} else {
|
2001-08-28 00:39:49 +08:00
|
|
|
$term_bold = $term_norm = "";
|
2001-04-17 07:28:58 +08:00
|
|
|
}
|
2000-08-28 03:46:06 +08:00
|
|
|
}
|
2001-03-21 21:00:33 +08:00
|
|
|
|
2001-08-28 00:39:49 +08:00
|
|
|
if (isset($GLOBALS["TOP_BUILDDIR"]) && @is_executable($GLOBALS["TOP_BUILDDIR"]."/php{$ext}")) {
|
|
|
|
$php = $GLOBALS["TOP_BUILDDIR"]."/php{$ext}";
|
|
|
|
} elseif (@is_executable("./php{$ext}")) {
|
|
|
|
$php = getcwd() . "/php{$ext}";
|
|
|
|
}
|
|
|
|
if (empty($php)) {
|
2001-08-28 04:17:36 +08:00
|
|
|
$php = in_path("php", $windows_p);
|
2001-08-28 00:39:49 +08:00
|
|
|
}
|
|
|
|
if (empty($php)) {
|
|
|
|
dowriteln("Unable to find PHP executable (php{$ext}).");
|
|
|
|
dowriteln("Please build PHP as a CGI executable or make sure it is");
|
|
|
|
dowriteln("available in the PATH environment variable.");
|
2000-12-08 08:21:09 +08:00
|
|
|
exit;
|
2000-08-28 03:46:06 +08:00
|
|
|
}
|
2001-08-28 04:29:33 +08:00
|
|
|
if ($windows_p) {
|
|
|
|
// modify path to help Windows find DLL files
|
|
|
|
$path = dirname($php) . ";" . getenv("PATH");
|
|
|
|
setenv("PATH={$path}");
|
|
|
|
}
|
2000-08-28 03:46:06 +08:00
|
|
|
|
2001-08-28 00:39:49 +08:00
|
|
|
create_compiled_in_modules_list();
|
|
|
|
|
2000-08-28 03:46:06 +08:00
|
|
|
$skip = array(
|
2000-12-08 08:21:09 +08:00
|
|
|
"CVS" => 1
|
|
|
|
);
|
2000-08-28 03:46:06 +08:00
|
|
|
$testdirs = array();
|
|
|
|
$tmpfile = array();
|
|
|
|
$tests_in_dir = array();
|
|
|
|
|
|
|
|
register_shutdown_function("delete_tmpfiles");
|
|
|
|
|
|
|
|
$skipped = $failed = $passed = $total = 0;
|
|
|
|
}
|
|
|
|
|
2000-12-08 08:21:09 +08:00
|
|
|
function &parse_options(&$argc, &$argv)
|
|
|
|
{
|
2000-08-28 03:46:06 +08:00
|
|
|
$options = array();
|
|
|
|
while ($argc > 0 && ($opt = substr($argv[0], 0, 2)) == "--") {
|
2000-12-08 08:21:09 +08:00
|
|
|
$opt = array_shift($argv);
|
|
|
|
$argc--;
|
|
|
|
if ($arg == "--") {
|
|
|
|
return $options;
|
|
|
|
}
|
2001-05-27 17:09:00 +08:00
|
|
|
if (ereg('^--([^=]+)=(.*)$', $opt, $matches)) {
|
2000-12-08 08:21:09 +08:00
|
|
|
$opt = $matches[1];
|
|
|
|
$arg = $matches[2];
|
|
|
|
} else {
|
|
|
|
$arg = true;
|
|
|
|
}
|
|
|
|
$options[$opt] = $arg;
|
2000-08-28 03:46:06 +08:00
|
|
|
}
|
|
|
|
return $options;
|
|
|
|
}
|
|
|
|
|
2000-12-08 08:21:09 +08:00
|
|
|
function do_testing($argc, &$argv)
|
|
|
|
{
|
2000-08-28 03:46:06 +08:00
|
|
|
global $term, $windows_p, $php, $skip, $testdirs, $tmpfile, $opts,
|
2001-03-21 14:04:36 +08:00
|
|
|
$skipped, $failed, $passed, $total, $term_bold, $term_norm, $skipped_extensions;
|
2000-08-28 03:46:06 +08:00
|
|
|
|
2000-12-03 18:45:53 +08:00
|
|
|
if ($argc > 1) {
|
2000-12-08 08:21:09 +08:00
|
|
|
if (is_dir($argv[1])) {
|
|
|
|
$dir = $argv[1];
|
|
|
|
} else {
|
|
|
|
for ($i = 1; $i < $argc; $i++) {
|
|
|
|
switch (run_test($argv[$i])) {
|
|
|
|
case TEST_SKIPPED:
|
|
|
|
case TEST_INTERNAL_ERROR:
|
|
|
|
$skipped++;
|
|
|
|
break;
|
|
|
|
case TEST_FAILED:
|
|
|
|
$failed++;
|
|
|
|
break;
|
|
|
|
case TEST_PASSED:
|
|
|
|
$passed++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
$total++;
|
|
|
|
}
|
|
|
|
}
|
2000-08-28 03:46:06 +08:00
|
|
|
} else {
|
2001-03-21 14:04:36 +08:00
|
|
|
// $dir = $GLOBALS["TOP_SRCDIR"]; // XXX ??? where should this variable be set?
|
2001-05-03 00:39:04 +08:00
|
|
|
$dir=str_replace('\\','/',trim(($windows_p ? getenv("TEST_DIR"):`pwd`)));
|
2000-08-28 03:46:06 +08:00
|
|
|
}
|
2000-12-16 07:18:50 +08:00
|
|
|
if (isset($dir) && $dir) {
|
2000-12-08 08:21:09 +08:00
|
|
|
find_testdirs($dir);
|
2001-05-03 00:39:04 +08:00
|
|
|
|
2001-03-21 14:04:36 +08:00
|
|
|
create_found_tests_4_modules_list();
|
|
|
|
create_modules_2_test_list();
|
2001-05-03 00:39:04 +08:00
|
|
|
|
2000-12-08 08:21:09 +08:00
|
|
|
for ($i = 0; $i < sizeof($testdirs); $i++) {
|
|
|
|
run_tests_in_dir($testdirs[$i]);
|
|
|
|
}
|
2000-08-28 03:46:06 +08:00
|
|
|
}
|
|
|
|
|
2000-09-01 06:21:47 +08:00
|
|
|
$counting = $total - $skipped;
|
|
|
|
|
|
|
|
if ($counting <= 0) {
|
2000-12-13 22:24:15 +08:00
|
|
|
dowriteln("No tests were run.");
|
2000-12-08 08:21:09 +08:00
|
|
|
return;
|
2000-08-28 03:46:06 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
$total_d = (double)$total;
|
2000-09-01 06:21:47 +08:00
|
|
|
$counting_d = (double)$counting;
|
|
|
|
$passed_p = 100 * ($passed / $counting_d);
|
|
|
|
$failed_p = 100 * ($failed / $counting_d);
|
2000-08-28 03:46:06 +08:00
|
|
|
$skipped_p = 100 * ($skipped / $total_d);
|
|
|
|
$passed_pstr = sprintf($passed_p < 10.0 ? "%1.1f" : "%3.0f", $passed_p);
|
|
|
|
$failed_pstr = sprintf($failed_p < 10.0 ? "%1.1f" : "%3.0f", $failed_p);
|
|
|
|
$skipped_pstr = sprintf($skipped_p < 10.0 ? "%1.1f" : "%3.0f", $skipped_p);
|
|
|
|
|
2000-12-13 22:24:15 +08:00
|
|
|
dowriteln("TEST RESULT SUMMARY");
|
|
|
|
dowriteln("=============================");
|
|
|
|
dowriteln(sprintf("Number of tests: %4d", $total));
|
|
|
|
dowriteln(sprintf("Tests skipped: %4d (%s%%)", $skipped, $skipped_pstr));
|
|
|
|
dowriteln(sprintf("Tests failed: %4d (%s%%)", $failed, $failed_pstr));
|
|
|
|
dowriteln(sprintf("Tests passed: %4d (%s%%)", $passed, $passed_pstr));
|
2001-03-21 14:04:36 +08:00
|
|
|
dowriteln("=============================");
|
|
|
|
dowriteln("Skipped ".sizeof($skipped_extensions)." extensions.");
|
2001-03-29 20:07:37 +08:00
|
|
|
dowriteln("PHP Version: ".phpversion());
|
2000-08-28 03:46:06 +08:00
|
|
|
}
|
|
|
|
|
2000-12-08 08:21:09 +08:00
|
|
|
function find_testdirs($dir = '.', $first_pass = true)
|
|
|
|
{
|
2000-08-28 03:46:06 +08:00
|
|
|
global $testdirs, $skip;
|
|
|
|
|
|
|
|
if ($first_pass && is_dir($dir)) {
|
2000-12-08 08:21:09 +08:00
|
|
|
$testdirs[] = $dir;
|
2000-08-28 03:46:06 +08:00
|
|
|
}
|
|
|
|
$dp = @opendir($dir);
|
|
|
|
if (!$dp) {
|
2000-12-08 08:21:09 +08:00
|
|
|
print "Warning: could not open directory $dir\n";
|
|
|
|
return false;
|
2000-08-28 03:46:06 +08:00
|
|
|
}
|
|
|
|
while ($ent = readdir($dp)) {
|
2000-12-08 08:21:09 +08:00
|
|
|
$path = "$dir/$ent";
|
2001-05-03 00:39:04 +08:00
|
|
|
|
2001-03-21 14:04:36 +08:00
|
|
|
if ((isset($skip[$ent]) && $skip[$ent])
|
|
|
|
|| substr($ent, 0, 1) == "."
|
|
|
|
|| !is_dir($path)
|
2001-05-03 00:39:04 +08:00
|
|
|
|
2001-03-21 14:04:36 +08:00
|
|
|
) {
|
2000-12-08 08:21:09 +08:00
|
|
|
continue;
|
2001-03-21 14:04:36 +08:00
|
|
|
}
|
2001-05-03 00:39:04 +08:00
|
|
|
|
2000-12-08 08:21:09 +08:00
|
|
|
if (strstr("/$path/", "/tests/")) {
|
|
|
|
$testdirs[] = $path;
|
|
|
|
}
|
|
|
|
find_testdirs($path, false);
|
2000-08-28 03:46:06 +08:00
|
|
|
}
|
|
|
|
closedir($dp);
|
2001-05-03 00:39:04 +08:00
|
|
|
|
2000-08-28 03:46:06 +08:00
|
|
|
}
|
|
|
|
|
2000-12-08 08:21:09 +08:00
|
|
|
function run_tests_in_dir($dir = '.')
|
|
|
|
{
|
2001-03-21 14:04:36 +08:00
|
|
|
global $skip, $skipped, $failed, $passed, $total, $opts, $tests_in_dir,$modules_available,$skipped_extensions;
|
2000-08-28 03:46:06 +08:00
|
|
|
$dp = opendir($dir);
|
|
|
|
if (!$dp) {
|
2000-12-08 08:21:09 +08:00
|
|
|
print "Warning: could not run tests in $dir\n";
|
|
|
|
return false;
|
2000-08-28 03:46:06 +08:00
|
|
|
}
|
|
|
|
$testfiles = array();
|
|
|
|
while ($ent = readdir($dp)) {
|
2000-12-08 08:21:09 +08:00
|
|
|
if ((isset($skip[$ent]) && $skip[$ent]) || substr($ent, 0, 1) == "." || substr($ent, -5) != ".phpt") {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
$testfiles[] = "$dir/$ent";
|
|
|
|
if(isset($tests_in_dir[$dir])) $tests_in_dir[$dir]++; else $tests_in_dir[$dir]=1;
|
2000-08-28 03:46:06 +08:00
|
|
|
}
|
|
|
|
closedir($dp);
|
2000-10-23 15:40:05 +08:00
|
|
|
if (isset($tests_in_dir[$dir]) && ($tests_in_dir[$dir] == 0)) {
|
2000-12-08 08:21:09 +08:00
|
|
|
return true;
|
2000-08-28 03:46:06 +08:00
|
|
|
}
|
|
|
|
$oskipped = $skipped;
|
2000-12-08 20:57:11 +08:00
|
|
|
if (sizeof($testfiles) == 0) {
|
|
|
|
return;
|
|
|
|
}
|
2001-05-03 00:39:04 +08:00
|
|
|
|
2001-03-21 14:04:36 +08:00
|
|
|
if ($mod_name=extract_module_name_from_path($dir)) {
|
|
|
|
if ($ext_found=in_array($mod_name,$modules_available))
|
|
|
|
dowriteln("Testing extension: $mod_name");
|
|
|
|
else $skipped_extensions[$mod_name]=TRUE;
|
2000-08-28 03:46:06 +08:00
|
|
|
}
|
2001-05-03 00:39:04 +08:00
|
|
|
|
2001-07-11 21:19:07 +08:00
|
|
|
if (!isset($ext_found) or $ext_found!==FALSE) {
|
2001-03-21 14:04:36 +08:00
|
|
|
dowriteln("%bRunning tests in $dir%B");
|
|
|
|
dowriteln("=================".str_repeat("=", strlen($dir)));
|
|
|
|
sort($testfiles);
|
|
|
|
for ($i = 0; $i < sizeof($testfiles); $i++) {
|
|
|
|
switch (run_test($testfiles[$i])) {
|
|
|
|
case TEST_SKIPPED:
|
|
|
|
case TEST_INTERNAL_ERROR:
|
|
|
|
$skipped++;
|
|
|
|
break;
|
|
|
|
case TEST_FAILED:
|
|
|
|
$failed++;
|
|
|
|
break;
|
|
|
|
case TEST_PASSED:
|
|
|
|
$passed++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
$total++;
|
|
|
|
}
|
|
|
|
if ($oskipped + (isset($tests_in_dir[$dir])?$tests_in_dir[$dir]:0) == $skipped) {
|
|
|
|
$skippednow = $skipped - $oskipped;
|
|
|
|
dowriteln("[all $skippednow test(s) skipped]");
|
|
|
|
}
|
|
|
|
dowriteln("");
|
2000-08-28 03:46:06 +08:00
|
|
|
}
|
2001-03-21 14:04:36 +08:00
|
|
|
|
2000-08-28 03:46:06 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2000-12-08 08:21:09 +08:00
|
|
|
function skip_headers($fp)
|
|
|
|
{
|
2000-08-28 03:46:06 +08:00
|
|
|
while (!feof($fp)) {
|
2000-12-08 08:21:09 +08:00
|
|
|
if (trim(fgets($fp, 1024)) == "") {
|
|
|
|
break;
|
|
|
|
}
|
2000-08-28 03:46:06 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-12-08 08:21:09 +08:00
|
|
|
function delete_tmpfiles()
|
|
|
|
{
|
2000-08-28 03:46:06 +08:00
|
|
|
global $tmpfile;
|
|
|
|
reset($tmpfile);
|
|
|
|
while (list($k, $v) = each($tmpfile)) {
|
2000-12-08 08:21:09 +08:00
|
|
|
if (file_exists($v)) {
|
2001-03-21 14:04:36 +08:00
|
|
|
//print "unlink($v): "; var_dump(unlink($v));
|
2000-12-08 08:21:09 +08:00
|
|
|
unlink($v);
|
|
|
|
}
|
2000-08-28 03:46:06 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Compares two files, ignoring blank lines.
|
|
|
|
*
|
|
|
|
* @param $file1 string name of first file to compare
|
|
|
|
* @param $file2 string name of second file to compare
|
|
|
|
*
|
|
|
|
* @return bool whether the files were "equal"
|
|
|
|
*/
|
2000-12-08 08:21:09 +08:00
|
|
|
function compare_results($file1, $file2)
|
2001-05-03 00:39:04 +08:00
|
|
|
{
|
2000-12-08 08:21:09 +08:00
|
|
|
$data1 = $data2 = "";
|
2000-08-28 03:46:06 +08:00
|
|
|
if (!($fp1 = @fopen($file1, "r")) || !($fp2 = @fopen($file2, "r"))) {
|
2000-12-08 08:21:09 +08:00
|
|
|
return false;
|
2000-08-28 03:46:06 +08:00
|
|
|
}
|
2001-03-21 14:04:36 +08:00
|
|
|
|
2000-08-28 03:46:06 +08:00
|
|
|
while (!(feof($fp1) || feof($fp2))) {
|
2000-12-08 08:21:09 +08:00
|
|
|
if (!feof($fp1) && trim($line1 = fgets($fp1, 10240)) != "") {
|
|
|
|
//print "adding line1 $line1\n";
|
2001-05-03 00:39:04 +08:00
|
|
|
|
2001-03-21 21:00:33 +08:00
|
|
|
$data1 .= trim($line1);
|
2000-12-08 08:21:09 +08:00
|
|
|
}
|
|
|
|
if (!feof($fp2) && trim($line2 = fgets($fp2, 10240)) != "") {
|
|
|
|
//print "adding line2 $line2\n";
|
2001-05-03 00:39:04 +08:00
|
|
|
|
2001-03-21 21:00:33 +08:00
|
|
|
$data2 .= trim($line2);
|
2000-12-08 08:21:09 +08:00
|
|
|
}
|
2000-08-28 03:46:06 +08:00
|
|
|
}
|
|
|
|
fclose($fp1);
|
|
|
|
fclose($fp2);
|
2001-03-21 14:04:36 +08:00
|
|
|
if ((trim($data1) != trim($data2))
|
|
|
|
|| ($data1=='' && $data2=='')) {
|
|
|
|
//print "data1=";var_dump($data1);
|
|
|
|
//print "data2=";var_dump($data2);
|
2000-12-08 08:21:09 +08:00
|
|
|
return false;
|
2000-08-28 03:46:06 +08:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2000-12-08 08:21:09 +08:00
|
|
|
function run_test($file)
|
|
|
|
{
|
2001-05-03 00:39:04 +08:00
|
|
|
global $php, $tmpfile, $term_bold, $term_norm, $term, $windows_p;
|
2000-08-28 03:46:06 +08:00
|
|
|
|
|
|
|
$variables = array("TEST", "POST", "GET", "FILE", "EXPECT", "SKIPIF",
|
2000-12-08 08:21:09 +08:00
|
|
|
"OUTPUT");
|
2000-08-28 03:46:06 +08:00
|
|
|
$fp = @fopen($file, "r");
|
|
|
|
if (!$fp) {
|
2000-12-08 08:21:09 +08:00
|
|
|
return TEST_INTERNAL_ERROR;
|
2000-08-28 03:46:06 +08:00
|
|
|
}
|
|
|
|
$tmpdir = dirname($file);
|
|
|
|
$tmpfix = "phpt.";
|
|
|
|
$tmpfile["FILE"] = tempnam($tmpdir, $tmpfix);
|
|
|
|
$tmpfile["SKIPIF"] = tempnam($tmpdir, $tmpfix);
|
|
|
|
$tmpfile["POST"] = tempnam($tmpdir, $tmpfix);
|
2001-05-03 00:39:04 +08:00
|
|
|
|
2000-08-28 03:46:06 +08:00
|
|
|
$tmpfile["EXPECT"] = tempnam($tmpdir, $tmpfix);
|
|
|
|
$tmpfile["OUTPUT"] = tempnam($tmpdir, $tmpfix);
|
2001-05-03 00:39:04 +08:00
|
|
|
|
|
|
|
|
2000-08-28 03:46:06 +08:00
|
|
|
while ($line = fgets($fp, 4096)) {
|
2001-05-27 17:09:00 +08:00
|
|
|
if (ereg('^--([A-Z]+)--', $line, $matches)) {
|
2000-12-08 08:21:09 +08:00
|
|
|
$var = $matches[1];
|
|
|
|
if (isset($tmpfile[$var]) && $tmpfile[$var]) {
|
|
|
|
$fps[$var] = @fopen($tmpfile[$var], "w");
|
|
|
|
} else {
|
|
|
|
$$var = '';
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (isset($var) && $var) {
|
|
|
|
if ($var == "POST") {
|
|
|
|
$line = trim($line);
|
|
|
|
}
|
|
|
|
if (isset($fps[$var]) && $fps[$var]) {
|
|
|
|
fwrite($fps[$var], $line);
|
|
|
|
} else {
|
|
|
|
$$var .= $line;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2000-08-28 03:46:06 +08:00
|
|
|
}
|
2000-12-08 08:21:09 +08:00
|
|
|
if(isset($fps) && is_array($fps)) {
|
|
|
|
reset($fps);
|
|
|
|
while (list($k, $v) = each($fps)) {
|
|
|
|
if (is_resource($v)) {
|
|
|
|
fclose($v);
|
|
|
|
}
|
|
|
|
}
|
2000-08-28 03:46:06 +08:00
|
|
|
}
|
|
|
|
putenv("PHP_TEST=1");
|
|
|
|
putenv("REDIRECT_STATUS=1");
|
|
|
|
putenv("CONTENT_LENGTH=");
|
2000-10-23 15:40:05 +08:00
|
|
|
putenv("QUERY_STRING=".(isset($GET)?$GET:""));
|
2000-12-13 22:24:15 +08:00
|
|
|
$include_path = ini_get("include_path");
|
2000-08-28 03:46:06 +08:00
|
|
|
if (isset($fps["SKIPIF"])) {
|
2000-12-08 08:21:09 +08:00
|
|
|
$tmpfile["SKIPIF_OUTPUT"] = tempnam($tmpdir, $tmpfix);
|
|
|
|
putenv("REQUEST_METHOD=GET");
|
|
|
|
putenv("CONTENT_TYPE=");
|
|
|
|
putenv("PATH_TRANSLATED=$tmpfile[SKIPIF]");
|
|
|
|
putenv("SCRIPT_FILENAME=$tmpfile[SKIPIF]");
|
|
|
|
$skipifcmd = "$php -q -f $tmpfile[SKIPIF] > $tmpfile[SKIPIF_OUTPUT]";
|
|
|
|
system($skipifcmd, $ret);
|
|
|
|
$sp = @fopen($tmpfile["SKIPIF_OUTPUT"], "r");
|
|
|
|
if ($sp) {
|
|
|
|
skip_headers($sp);
|
|
|
|
$skip = trim(fgets($sp, 1024));
|
|
|
|
fclose($sp);
|
|
|
|
if ($skip == "skip") {
|
|
|
|
delete_tmpfiles();
|
|
|
|
return TEST_SKIPPED;
|
|
|
|
}
|
|
|
|
}
|
2000-08-28 03:46:06 +08:00
|
|
|
}
|
|
|
|
putenv("PATH_TRANSLATED=$tmpfile[FILE]");
|
|
|
|
putenv("SCRIPT_FILENAME=$tmpfile[FILE]");
|
|
|
|
if (isset($fps["POST"])) {
|
2000-12-08 08:21:09 +08:00
|
|
|
putenv("REQUEST_METHOD=POST");
|
|
|
|
putenv("CONTENT_TYPE=application/x-www-form-urlencoded");
|
|
|
|
putenv("CONTENT_LENGTH=".filesize($tmpfile["POST"]));
|
2000-08-28 03:46:06 +08:00
|
|
|
} else {
|
2000-12-08 08:21:09 +08:00
|
|
|
putenv("REQUEST_METHOD=GET");
|
|
|
|
putenv("CONTENT_TYPE=");
|
|
|
|
putenv("CONTENT_LENGTH=");
|
2000-08-28 03:46:06 +08:00
|
|
|
}
|
2000-09-09 08:37:39 +08:00
|
|
|
if (isset($fps["POST"])) {
|
2001-05-03 00:39:04 +08:00
|
|
|
if(!$windows_p) {
|
2001-05-27 17:09:00 +08:00
|
|
|
$cmd = "2>&1 $php -q $tmpfile[FILE] < $tmpfile[POST]";
|
2001-05-03 00:39:04 +08:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
$cmd = "$term /c " . realpath($php) ." -q $tmpfile[FILE] < $tmpfile[POST]";
|
|
|
|
}
|
2000-09-09 08:37:39 +08:00
|
|
|
} else {
|
2001-05-03 00:39:04 +08:00
|
|
|
if(!$windows_p) {
|
2001-05-27 17:09:00 +08:00
|
|
|
$cmd = "2>&1 $php -q $tmpfile[FILE]";
|
2001-05-03 00:39:04 +08:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
$cmd = "$term /c " . realpath($php) ." -q $tmpfile[FILE]";;
|
|
|
|
}
|
2000-09-09 08:37:39 +08:00
|
|
|
}
|
2000-08-28 03:46:06 +08:00
|
|
|
$ofp = @fopen($tmpfile["OUTPUT"], "w");
|
|
|
|
if (!$ofp) {
|
2000-12-15 10:57:11 +08:00
|
|
|
dowriteln("Error: could not write to output file");
|
2000-12-08 08:21:09 +08:00
|
|
|
delete_tmpfiles();
|
|
|
|
return TEST_INTERNAL_ERROR;
|
2000-08-28 03:46:06 +08:00
|
|
|
}
|
2001-03-21 21:00:33 +08:00
|
|
|
//echo $cmd;
|
2000-08-28 03:46:06 +08:00
|
|
|
$cp = popen($cmd, "r");
|
|
|
|
if (!$cp) {
|
2000-12-15 10:57:11 +08:00
|
|
|
dowriteln("Error: could not execute: $cmd");
|
2000-12-08 08:21:09 +08:00
|
|
|
delete_tmpfiles();
|
|
|
|
return TEST_INTERNAL_ERROR;
|
2000-08-28 03:46:06 +08:00
|
|
|
}
|
|
|
|
skip_headers($cp);
|
|
|
|
while ($data = fread($cp, 2048)) {
|
2000-12-08 08:21:09 +08:00
|
|
|
fwrite($ofp, $data);
|
2000-08-28 03:46:06 +08:00
|
|
|
}
|
|
|
|
fclose($ofp);
|
|
|
|
pclose($cp);
|
2000-10-29 15:19:35 +08:00
|
|
|
$desc = isset($TEST)?trim($TEST):"";
|
2001-05-27 17:09:00 +08:00
|
|
|
$outfile = ereg_replace('\.phpt$', '.out', $file);
|
|
|
|
$expectfile = ereg_replace('\.phpt$', '.exp', $file);
|
|
|
|
$phpfile = ereg_replace('\.phpt$', '.php', $file);
|
2000-08-28 03:46:06 +08:00
|
|
|
if (compare_results($tmpfile["OUTPUT"], $tmpfile["EXPECT"])) {
|
2000-12-08 08:21:09 +08:00
|
|
|
$status = TEST_PASSED;
|
|
|
|
$text = "passed";
|
|
|
|
$pre = $post = "";
|
|
|
|
if (file_exists($outfile)) {
|
|
|
|
unlink($outfile);
|
|
|
|
}
|
|
|
|
if (file_exists($expectfile)) {
|
|
|
|
unlink($expectfile);
|
|
|
|
}
|
|
|
|
if (file_exists($phpfile)) {
|
|
|
|
unlink($phpfile);
|
|
|
|
}
|
2000-08-28 03:46:06 +08:00
|
|
|
} else {
|
2000-12-08 08:21:09 +08:00
|
|
|
//system("env");
|
|
|
|
$status = TEST_FAILED;
|
|
|
|
$text = "failed";
|
|
|
|
$pre = $term_bold;
|
|
|
|
$post = $term_norm;
|
|
|
|
$desc .= " (".basename($file).")";
|
|
|
|
if (file_exists($outfile)) {
|
|
|
|
unlink($outfile);
|
|
|
|
}
|
|
|
|
copy($tmpfile["OUTPUT"], $outfile);
|
|
|
|
copy($tmpfile["EXPECT"], $expectfile);
|
|
|
|
copy($tmpfile["FILE"], $phpfile);
|
2000-08-28 03:46:06 +08:00
|
|
|
}
|
2000-12-13 22:24:15 +08:00
|
|
|
dowriteln(sprintf("%s%-68s ... %s%s", $pre, substr($desc, 0, 68),
|
2000-12-08 08:21:09 +08:00
|
|
|
$text, $post));
|
2000-08-28 03:46:06 +08:00
|
|
|
// if ($status == TEST_FAILED) {
|
2000-12-08 08:21:09 +08:00
|
|
|
// for ($i = 0; $i < sizeof($variables); $i++) {
|
|
|
|
// $var = $variables[$i];
|
|
|
|
// print "$var:\n";
|
|
|
|
// if ($tmpfile[$var]) {
|
|
|
|
// if (file_exists($tmpfile[$var])) {
|
|
|
|
// system("cat ".$tmpfile[$var]);
|
|
|
|
// }
|
|
|
|
// } else {
|
|
|
|
// print $$var;
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// print "--\n\n";
|
2000-08-28 03:46:06 +08:00
|
|
|
// }
|
|
|
|
delete_tmpfiles();
|
|
|
|
return $status;
|
|
|
|
}
|
|
|
|
|
2001-05-27 17:09:00 +08:00
|
|
|
?>
|