]> granicus.if.org Git - php/commitdiff
@Added XML_Parser class in PEAR (Stig)
authorStig Bakken <ssb@php.net>
Sun, 30 Jul 2000 17:41:31 +0000 (17:41 +0000)
committerStig Bakken <ssb@php.net>
Sun, 30 Jul 2000 17:41:31 +0000 (17:41 +0000)
@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 :-)

pear/Makefile.in
pear/PEAR.php.in
pear/PEAR/Installer.php
pear/run-tests.in
pear/tests/PEAR.r
pear/tests/PEAR.t
pear/tests/PEAR_Error.r [new file with mode: 0644]
pear/tests/PEAR_Error.t [new file with mode: 0644]

index bafbedc8fa66117d3abc0f58e5ad945bfb0f0cd6..bca3b6911d5d89ff3056e596c4927b3d32e76008 100644 (file)
@@ -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)
index 4759ebcf56e6f02cbf268f2127c1e6ea23e9eedb..b1b4182a9048c4e42197ff70e3c00ba56db92136 100644 (file)
@@ -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: <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
 
     /**
@@ -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")));
        }
 
     // }}}
index 25c99f46dfe6d0e4f271e2d10661fc970d1c84ed..ae706d10e08eeaab4d18860b184f3645d4077ea8 100644 (file)
@@ -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;
            }
        }
 
index 4710a10878cf1d07e1d2fbfff68fc04a2cd6295e..d147f0a8061c95d3d86ec0c55148f09b9115faaf 100755 (executable)
@@ -1,4 +1,4 @@
-#!@prefix@/bin/php
+#!@prefix@/bin/php -f
 <?php // -*- C++ -*-
 
 $prefix = "@prefix@";
@@ -11,7 +11,6 @@ $abs_srcdir = '@abs_srcdir@/pear';
 $incpath = ".:$abs_srcdir/pear/tests:$abs_srcdir/pear/tests";
 
 $start = "*";
-print "argc=$argc\n";
 if ($argc > 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/.
+
+");
+}
+
 ?>
index 0bcaa956f587ca26c16a9271c2a917c2335acbbc..e8210eee352534889769f68fc948380950d6bf52 100644 (file)
@@ -1 +1,3 @@
-int(0)
+test class __TestPEAR1
+PEAR constructor called, class=__testpear1
+string(11) "__testpear1"
index 11df9b8178a27b6707a49de756fa67d47c600370..6c8346adc70176397e2c73d53d4b242d02b6e143 100644 (file)
@@ -1,8 +1,16 @@
-<?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));
+
+?>
diff --git a/pear/tests/PEAR_Error.r b/pear/tests/PEAR_Error.r
new file mode 100644 (file)
index 0000000..fce8a66
--- /dev/null
@@ -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 (file)
index 0000000..4fae7b4
--- /dev/null
@@ -0,0 +1,18 @@
+<?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));
+
+?>