From: Stig Bakken Date: Sun, 30 Jul 2000 17:41:31 +0000 (+0000) Subject: @Added XML_Parser class in PEAR (Stig) X-Git-Tag: PRE_FILE_COMPILE_API_CHANGE~71 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=def1424b12e839195168ec7aef911490511c22a2;p=php @Added XML_Parser class in PEAR (Stig) @Added "make test" target in pear/ and added some regression tests (Stig) Also fixed a bug in the PEAR class that was discovered when testing :-) --- diff --git a/pear/Makefile.in b/pear/Makefile.in index bafbedc8fa..bca3b6911d 100644 --- a/pear/Makefile.in +++ b/pear/Makefile.in @@ -93,8 +93,15 @@ install-headers: 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) diff --git a/pear/PEAR.php.in b/pear/PEAR.php.in index 4759ebcf56..b1b4182a90 100644 --- a/pear/PEAR.php.in +++ b/pear/PEAR.php.in @@ -31,6 +31,11 @@ define('PEAR_EXTENSION_DIR', '@EXTENSION_DIR@'); $_PEAR_destructor_object_list = array(); +// +// Tests needed: - PEAR inheritance +// - destructors +// + /** * Base class for other PEAR classes. Provides rudimentary * emulation of destructors. @@ -38,19 +43,25 @@ $_PEAR_destructor_object_list = array(); * 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: $this->PEAR();. + * 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 error_log(), syslog() or + * something like that instead. * * @since PHP 4.0.2 * @author Stig Bakken */ class PEAR { + // {{{ properties + + var $_debug = false; + + // }}} + // {{{ constructor /** @@ -60,16 +71,24 @@ class PEAR 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() { } @@ -85,7 +104,9 @@ class 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"))); } // }}} diff --git a/pear/PEAR/Installer.php b/pear/PEAR/Installer.php index 25c99f46df..ae706d10e0 100644 --- a/pear/PEAR/Installer.php +++ b/pear/PEAR/Installer.php @@ -250,10 +250,11 @@ class PEAR_Installer extends PEAR { 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; } } diff --git a/pear/run-tests.in b/pear/run-tests.in index 4710a10878..d147f0a806 100755 --- a/pear/run-tests.in +++ b/pear/run-tests.in @@ -1,4 +1,4 @@ -#!@prefix@/bin/php +#!@prefix@/bin/php -f 1) { $start = implode(" ", $argv); } @@ -19,29 +18,68 @@ $fp = popen("find $start -name tests -type d -print", "r"); 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/. + +"); +} + ?> diff --git a/pear/tests/PEAR.r b/pear/tests/PEAR.r index 0bcaa956f5..e8210eee35 100644 --- a/pear/tests/PEAR.r +++ b/pear/tests/PEAR.r @@ -1 +1,3 @@ -int(0) +test class __TestPEAR1 +PEAR constructor called, class=__testpear1 +string(11) "__testpear1" diff --git a/pear/tests/PEAR.t b/pear/tests/PEAR.t index 11df9b8178..6c8346adc7 100644 --- a/pear/tests/PEAR.t +++ b/pear/tests/PEAR.t @@ -1,8 +1,16 @@ -_debug = true; + $this->PEAR(); + } +} -?> \ No newline at end of file +print "test class __TestPEAR1\n"; +$o = new __TestPEAR1; +var_dump(get_class($o)); + +?> diff --git a/pear/tests/PEAR_Error.r b/pear/tests/PEAR_Error.r new file mode 100644 index 0000000000..fce8a664a7 --- /dev/null +++ b/pear/tests/PEAR_Error.r @@ -0,0 +1,20 @@ +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) diff --git a/pear/tests/PEAR_Error.t b/pear/tests/PEAR_Error.t new file mode 100644 index 0000000000..4fae7b4cda --- /dev/null +++ b/pear/tests/PEAR_Error.t @@ -0,0 +1,18 @@ +