cd $(top_builddir)/$$i && cp -p *.h $(phpincludedir)/$$i) 2>/dev/null || true; \
done
+test: run-tests Makefile
+ @./run-tests
+
+Makefile: Makefile.in $(top_builddir)/config.status
+ (cd ..;CONFIG_FILES=pear/Makefile CONFIG_HEADERS= $(top_builddir)/config.status)
+
run-tests: run-tests.in $(top_builddir)/config.status
- (cd ..;CONFIG_FILES=pear/run-tests CONFIG_HEADERS= $(top_builddir)/config.status)
+ (cd ..;CONFIG_FILES=pear/$@ CONFIG_HEADERS= $(top_builddir)/config.status)
+ chmod +x $@
pear: pear.in $(top_builddir)/config.status
(cd ..;CONFIG_FILES=pear/pear CONFIG_HEADERS= $(top_builddir)/config.status)
$_PEAR_destructor_object_list = array();
+//
+// Tests needed: - PEAR inheritance
+// - destructors
+//
+
/**
* Base class for other PEAR classes. Provides rudimentary
* emulation of destructors.
* If you want a destructor in your class, inherit PEAR and make a
* destructor method called _yourclassname (same name as the
* constructor, but with a "_" prefix). Also, in your constructor you
- * have to call the PEAR constructor: "$this->PEAR();". The
- * destructor method will be called without parameters. Note that at
- * in some SAPI implementations (such as Apache), any output during
+ * have to call the PEAR constructor: <code>$this->PEAR();</code>.
+ * The destructor method will be called without parameters. Note that
+ * at in some SAPI implementations (such as Apache), any output during
* the request shutdown (in which destructors are called) seems to be
* discarded. If you need to get any debug information from your
- * destructor, use error_log(), syslog() or something like that
- * instead.
+ * destructor, use <code>error_log()</code>, <code>syslog()</code> or
+ * something like that instead.
*
* @since PHP 4.0.2
* @author Stig Bakken <ssb@fast.no>
*/
class PEAR
{
+ // {{{ properties
+
+ var $_debug = false;
+
+ // }}}
+
// {{{ constructor
/**
function PEAR() {
global $_PEAR_destructor_object_list;
$_PEAR_destructor_object_list[] = &$this;
+ if ($this->_debug) {
+ printf("PEAR constructor called, class=%s\n",
+ get_class($this));
+ }
}
// }}}
// {{{ destructor
/**
- * Destructor (the emulated type of...).
+ * Destructor (the emulated type of...). Does nothing right now,
+ * but is included for forward compatibility, so subclass
+ * destructors should always call it.
*
* See the note in the class desciption about output from
* destructors.
+ *
+ * @access public
*/
function _PEAR() {
}
* @return bool true if $data is an error
*/
function isError(&$data) {
- return is_object($data) && is_subclass_of($data, "PEAR_Error");
+ return (bool)(is_object($data) &&
+ (get_class($data) == "pear_error" ||
+ is_subclass_of($data, "pear_error")));
}
// }}}
while ($data = fread($fp, 2048)) {
if (!xml_parse($xp, $data, feof($fp))) {
- return new PEAR_Installer_Error(sprintf("XML error: %s at line %d",
+ $err = new PEAR_Installer_Error(sprintf("XML error: %s at line %d",
xml_error_string(xml_get_error_code($xp)),
xml_get_current_line_number($xp)));
xml_parser_free($xp);
+ return $err;
}
}
-#!@prefix@/bin/php
+#!@prefix@/bin/php -f
<?php // -*- C++ -*-
$prefix = "@prefix@";
$incpath = ".:$abs_srcdir/pear/tests:$abs_srcdir/pear/tests";
$start = "*";
-print "argc=$argc\n";
if ($argc > 1) {
$start = implode(" ", $argv);
}
if (!$fp) {
die("Could not run find!\n");
}
+
+$failed = 0;
+$passed = 0;
+$tests = 0;
+
while ($dir = trim(fgets($fp, 1024))) {
- print "dir=$dir\n";
+ print "DIRECTORY : $dir\n";
+ //print "dir=$dir\n";
$dp = opendir($dir);
while ($ent = readdir($dp)) {
- if (substr($ent, -2) != ".t") {
+ if (substr($ent, 0, 1) == "." || substr($ent, -2) != ".t") {
continue;
}
- $res = "$dir/".substr($ent, 0, -1) . 'r';
- $out = "$dir/".substr($ent, 0, -1) . 'o';
- $cmd = ("$php -d include_path=$incpath -d auto_prepend_file=none ".
- "-f $dir/$ent | tee $out | cmp -s $res -");
- print "cmd=$cmd\n";
+ $res = substr($ent, 0, -1) . 'r';
+ $out = substr($ent, 0, -1) . 'o';
+ $cmd = ("cd $dir; $php -d include_path=$incpath ".
+ "-d auto_prepend_file=none ".
+ "-d html_errors=no ".
+ "-f $ent 2>/dev/null | ".
+ "tee $out 2>/dev/null | cmp -s $res -");
+ //print "cmd=$cmd\n";
$err = 0;
system($cmd, &$err);
- print "$dir/$ent: ";
if ($err) {
- print "failed\n";
+ print "FAILED : ";
+ $failed++;
} else {
- print "passed\n";
+ unlink("$dir/$out");
+ print "PASSED : ";
+ $passed++;
+ }
+ $tests++;
+ print "$dir/$ent";
+ if ($err) {
+ print " (see $dir/$out)";
}
+ print "\n";
}
closedir($dp);
}
pclose($fp);
+$percent = $failed ? ($passed * 100) / $tests : 100;
+$percentstr = sprintf($percent < 10.0 ? "%.1f%%" : "%.0f%%", $percent);
+print "\n----------- SUMMARY -----------\n";
+printf("Tests performed: %d\n".
+ "Tests passed: %d\n".
+ "Tests failed: %d\n".
+ "Success rate: %s\n",
+ $tests, $passed, $failed, $percentstr);
+if ($failed) {
+ die("
+One or more tests failed. The file where you can find the output
+from the test (.o file) should be listed after the FAILED message. The
+expected output can be found in the corresponding .r file, the source code
+for the test can be found in the .t file.
+
+Please compare the actual output with the expected output and see if
+it is a local configuration problem or an actual bug. If it is a bug,
+please report it at http://bugs.php.net/.
+
+");
+}
+
?>
-int(0)
+test class __TestPEAR1
+PEAR constructor called, class=__testpear1
+string(11) "__testpear1"
-<?php
+<?php // -*- C++ -*-
-require "PEAR.php";
+require_once "PEAR.php";
-$err = new PEAR_Error;
-var_dump(PEAR::isError($err));
+class __TestPEAR1 extends PEAR {
+ function __TestPEAR1() {
+ $this->_debug = true;
+ $this->PEAR();
+ }
+}
-?>
\ No newline at end of file
+print "test class __TestPEAR1\n";
+$o = new __TestPEAR1;
+var_dump(get_class($o));
+
+?>
--- /dev/null
+new PEAR_Error object(pear_error)(8) {
+ ["classname"]=>
+ string(10) "pear_error"
+ ["error_message_prefix"]=>
+ string(0) ""
+ ["error_prepend"]=>
+ string(0) ""
+ ["error_append"]=>
+ string(0) ""
+ ["mode"]=>
+ int(0)
+ ["level"]=>
+ int(1024)
+ ["message"]=>
+ string(13) "unknown error"
+ ["code"]=>
+ int(0)
+}
+isError 1 bool(true)
+isError 2 bool(false)
--- /dev/null
+<?php // -*- C++ -*-
+
+// Test for: PEAR.php
+// Parts tested: - PEAR_Error class
+// - PEAR::isError static method
+// testing PEAR_Error
+
+require_once "PEAR.php";
+
+print "new PEAR_Error ";
+var_dump($err = new PEAR_Error);
+print "isError 1 ";
+var_dump(PEAR::isError($err));
+print "isError 2 ";
+$str = "not an error";
+var_dump(PEAR::isError($str));
+
+?>