summaryrefslogtreecommitdiff
path: root/run-tests.php
diff options
context:
space:
mode:
authorSteph Fox <sfox@php.net>2008-06-11 16:48:41 +0000
committerSteph Fox <sfox@php.net>2008-06-11 16:48:41 +0000
commitfbcbb85cbcdde287d10b26d109f1df0046a92f82 (patch)
tree8c089614de3fb64f5b72b269ccf29cfa397c6b7e /run-tests.php
parent018f493cf3cedf18231ec817e07548a731e3af88 (diff)
downloadphp-git-fbcbb85cbcdde287d10b26d109f1df0046a92f82.tar.gz
- binary safety
Diffstat (limited to 'run-tests.php')
-rwxr-xr-xrun-tests.php101
1 files changed, 84 insertions, 17 deletions
diff --git a/run-tests.php b/run-tests.php
index 53b6e6ec56..f8fda8ab56 100755
--- a/run-tests.php
+++ b/run-tests.php
@@ -980,6 +980,10 @@ function system_with_timeout($commandline, $env = null, $stdin = null)
break;
}
+ if (is_binary($line)) {
+ $data = (binary)$data;
+ }
+
$data .= $line;
}
}
@@ -1601,7 +1605,11 @@ COMMAND $cmd
}
// 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 @@ COMMAND $cmd
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 @@ COMMAND $cmd
$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 @@ COMMAND $cmd
}
// 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 @@ $output
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 @@ function generate_array_diff($ar1, $ar2, $is_reg, $w)
$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_array_diff($ar1, $ar2, $is_reg, $w)
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);
}