sfox            Wed Jun 11 16:48:41 2008 UTC

  Modified files:              
    /php-src    run-tests.php 
  Log:
  - binary safety
  
http://cvs.php.net/viewvc.cgi/php-src/run-tests.php?r1=1.351&r2=1.352&diff_format=u
Index: php-src/run-tests.php
diff -u php-src/run-tests.php:1.351 php-src/run-tests.php:1.352
--- php-src/run-tests.php:1.351 Wed Jun 11 15:42:06 2008
+++ php-src/run-tests.php       Wed Jun 11 16:48:41 2008
@@ -24,7 +24,7 @@
    +----------------------------------------------------------------------+
  */
 
-/* $Id: run-tests.php,v 1.351 2008/06/11 15:42:06 sfox Exp $ */
+/* $Id: run-tests.php,v 1.352 2008/06/11 16:48:41 sfox Exp $ */
 
 /* Sanity check to ensure that pcre extension needed by this script is 
available.
  * In the event it is not, print a nice error message indicating that this 
script will
@@ -445,7 +445,7 @@
                                        $html_output = is_resource($html_file);
                                        break;
                                case '--version':
-                                       echo '$Revision: 1.351 $'."\n";
+                                       echo '$Revision: 1.352 $'."\n";
                                        exit(1);
                                default:
                                        echo "Illegal switch specified!\n";
@@ -980,6 +980,10 @@
                                break;
                        }
 
+                       if (is_binary($line)) {
+                               $data = (binary)$data;
+                       }
+
                        $data .= $line;
                }
        }
@@ -1601,7 +1605,11 @@
        }
 
        // Does the output match what is expected?
-       $output = str_replace("\r\n", "\n", trim($out));
+       if (is_binary($out)) {
+               $output = preg_replace(b'/\r\n/', b"\n", trim($out));
+       } else {
+               $output = str_replace("\r\n", "\n", trim($out));
+       }
 
        /* when using CGI, strip the headers from the output */
        $headers = "";
@@ -1688,8 +1696,14 @@
                print(str_repeat('=', 80) . "\n");
                var_dump($output);
 */
-               if (preg_match("/^$wanted_re\$/s", $output)) {
-                       $passed = true;
+               if (is_binary($output)) {
+                       if (preg_match((binary)"/^$wanted_re\$/s", $output)) {
+                               $passed = true;
+                       }
+               } else {
+                       if (preg_match("/^$wanted_re\$/s", $output)) {
+                               $passed = true;
+                       }
                }
 
                if ($passed) {
@@ -1711,13 +1725,12 @@
 
                $wanted = trim($section_text['EXPECT']);
 
-               if (is_unicode($wanted)) {
-                       /* workaround until preg_replace() or str_replace() are 
upgraded */
-                       $wanted = unicode_encode($wanted, 
ini_get('unicode.output_encoding') ?: 'utf-8');
+               if (is_binary($wanted)) {
+                       $wanted = preg_replace(b'/\r\n/', b"\n", 
(binary)$wanted);
+               } else {
+                       $wanted = preg_replace('/\r\n/', "\n", $wanted);
                }
 
-               $wanted = preg_replace('/\r\n/', "\n", $wanted);
-
                show_file_block('exp', $wanted);
 
                // compare and leave on success
@@ -1789,13 +1802,25 @@
                }
 
                // write .log
-               if (strpos($log_format,'L') !== false && 
file_put_contents($log_filename, "
+               if (is_binary($output)) {
+                       $content = b"
 ---- EXPECTED OUTPUT
 $wanted
 ---- ACTUAL OUTPUT
 $output
 ---- FAILED
-") === false) {
+";
+               } else {
+                       $content = "
+---- EXPECTED OUTPUT
+$wanted
+---- ACTUAL OUTPUT
+$output
+---- FAILED
+";
+               }
+
+               if (strpos($log_format, 'L') !== false && 
file_put_contents($log_filename, $content) === false) {
                        error("Cannot create test log - $log_filename");
                        error_report($file, $log_filename, $tested);
                }
@@ -1823,8 +1848,19 @@
 function comp_line($l1, $l2, $is_reg)
 {
        if ($is_reg) {
+
+               if (is_binary($l2)) {
+                       return preg_match((binary)"/^$l1\$/s", (binary)$l2);
+               }
+
                return preg_match("/^$l1$/s", $l2);
+
        } else {
+
+               if (is_binary($l2)) {
+                       return !strcmp((binary)$l1, (binary)$l2);
+               }
+
                return !strcmp($l1, $l2);
        }
 }
@@ -1891,14 +1927,34 @@
                        $c2 = count_array_diff($ar1, $ar2, $is_reg, $w, $idx1, 
$idx2+1, $cnt1,  $cnt2, 10);
 
                        if ($c1 > $c2) {
-                               $old1[$idx1] = sprintf("%03d- ", $idx1+1) . 
$w[$idx1++];
+
+                               if (is_binary($w[$idx1])) {
+                                       $old1[$idx1] = (binary)sprintf("%03d- 
", $idx1+1) . $w[$idx1++];
+                               } else {
+                                       $old1[$idx1] = sprintf("%03d- ", 
$idx1+1) . $w[$idx1++];
+                               }
+
                                $last = 1;
+
                        } else if ($c2 > 0) {
-                               $old2[$idx2] = sprintf("%03d+ ", $idx2+1) . 
$ar2[$idx2++];
+
+                               if (is_binary($ar2[$idx2])) {
+                                       $old2[$idx2] = (binary)sprintf("%03d+ 
", $idx2+1) . $ar2[$idx2++];
+                               } else {
+                                       $old2[$idx2] = sprintf("%03d+ ", 
$idx2+1) . $ar2[$idx2++];
+                               }
+
                                $last = 2;
+
                        } else {
-                               $old1[$idx1] = sprintf("%03d- ", $idx1+1) . 
$w[$idx1++];
-                               $old2[$idx2] = sprintf("%03d+ ", $idx2+1) . 
$ar2[$idx2++];
+
+                               if (is_binary($ar2[$idx2])) {
+                                       $old1[$idx1] = (binary)sprintf("%03d- 
", $idx1+1) . $w[$idx1++];
+                                       $old2[$idx2] = (binary)sprintf("%03d+ 
", $idx2+1) . $ar2[$idx2++];
+                               } else {
+                                       $old1[$idx1] = sprintf("%03d- ", 
$idx1+1) . $w[$idx1++];
+                                       $old2[$idx2] = sprintf("%03d+ ", 
$idx2+1) . $ar2[$idx2++];
+                               }
                        }
                }
        }
@@ -1940,11 +1996,22 @@
 
 function generate_diff($wanted, $wanted_re, $output)
 {
-       $w = explode("\n", $wanted);
-       $o = explode("\n", $output);
-       $r = is_null($wanted_re) ? $w : explode("\n", $wanted_re);
+       if (is_binary($output)) {
+               $w = explode(b"\n", $wanted);
+               $o = explode(b"\n", $output);
+               $r = is_null($wanted_re) ? $w : explode(b"\n", $wanted_re);
+       } else {
+               $w = explode("\n", $wanted);
+               $o = explode("\n", $output);
+               $r = is_null($wanted_re) ? $w : explode("\n", $wanted_re);
+       }
+
        $diff = generate_array_diff($r, $o, !is_null($wanted_re), $w);
 
+       if (is_binary($output)) {
+               return implode(b"\r\n", $diff);
+       }
+
        return implode("\r\n", $diff);
 }
 



-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to