com php-src: Add runtime_compile_time_binary_operands .phpt: Zend/tests/runtime_compile_time_binary_ope rands.phpt
| From: | Bob Weinand | Date: | Wed, 27 Feb 2019 11:59:06 +0000 |
| Subject: | com php-src: Add runtime_compile_time_binary_operands .phpt: Zend/tests/runtime_compile_time_binary_ope rands.phpt | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-104871@lists.php.net to get a copy of this message | ||
Commit: fcfec9102b638298f2a137ef915e29dc23ddd6f2
Author: rjhdby <andrewgrom@rambler.ru> Mon, 25 Feb 2019 17:46:30 +0300
Committer: Bob Weinand <bobwei9@hotmail.com> Wed, 27 Feb 2019 12:59:06 +0100
Parents: b9ab686179ca81a9784ec44409765806dcbfe8de
Branches: PHP-7.4
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=fcfec9102b638298f2a137ef915e29dc23ddd6f2
Log:
Add runtime_compile_time_binary_operands.phpt
Changed paths:
A Zend/tests/runtime_compile_time_binary_operands.phpt
Diff:
diff --git a/Zend/tests/runtime_compile_time_binary_operands.phpt
b/Zend/tests/runtime_compile_time_binary_operands.phpt
new file mode 100644
index 0000000..237692f
--- /dev/null
+++ b/Zend/tests/runtime_compile_time_binary_operands.phpt
@@ -0,0 +1,156 @@
+--TEST--
+Test binary operands exposing the same behavior at compile as at run time
+--INI--
+memory_limit=256M
+--FILE--
+<?php
+
+$operands = [
+ "==",
+ "!=",
+ "===",
+ "!==",
+ "<",
+ "<=",
+ ">",
+ ">=",
+ "<=>",
+ "+",
+ "-",
+ "*",
+ "/",
+ "%",
+ "**",
+ "..",
+ "|",
+ "&",
+ "^",
+ "or",
+ "and",
+ "xor",
+ "||",
+ "&&",
+];
+
+$input = [
+ 0,
+ 1,
+ 2,
+ -1,
+ 2.0,
+ 2.1,
+ -2.0,
+ -2.1,
+ PHP_INT_MAX,
+ PHP_INT_MIN,
+ PHP_INT_MAX * 2,
+ PHP_INT_MIN * 2,
+ INF,
+ NAN,
+ [],
+ [1, 2],
+ [1, 2, 3],
+ [1 => 2, 0 => 1],
+ [1, 'a' => 2],
+ [1, 4],
+ [1, 'a'],
+ [1, 2 => 2],
+ [1, [ 2 ]],
+ null,
+ false,
+ true,
+ "",
+ " ",
+ "banana",
+ "Banana",
+ "banan",
+ "0",
+ "200",
+ "20",
+ "20a",
+ " \t\n\r\v\f20",
+ "20 ",
+ "2e1",
+ "2e150",
+ "9179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858368",
+ "-9179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858368",
+ "0.1",
+ "-0.1",
+ "1e-1",
+ "-20",
+ "-20.0",
+ "0x14",
+ (string) PHP_INT_MAX * 2,
+ (string) PHP_INT_MIN * 2,
+];
+
+function makeParam($param) {
+ if ($param === PHP_INT_MIN) {
+ return "PHP_INT_MIN";
+ }
+ if ($param === PHP_INT_MAX) {
+ return "PHP_INT_MAX";
+ }
+ if (is_string($param)) {
+ return '"' . strtr($param, ["\t" => '\t', "\n"
=> '\n', "\r" => '\r', "\v" => '\v',
"\f" => '\f', '$' => '\$', '"' =>
'\"']) .. '"';
+ }
+ return "(" . str_replace("\n", "", var_export($param, true)) .
")";
+}
+
+$c = 0;
+$f = 0;
+
+function prepareLine($op1, $op2, $cmp, $operator) {
+
+ $op1_p = makeParam($op1);
+ $op2_p = makeParam($op2);
+
+ $error = "echo '" . addcslashes("$op1_p $operator $op2_p",
"\\'") . '\', "\n"; $f++;';
+
+ $compare = "@($op1_p $operator $op2_p)";
+ $line = "\$c++; try { ";
+ try {
+ $result = makeParam($cmp());
+ $line .= "if (" . ($result === "(NAN)" ? "!is_nan($compare)" :
"$compare !== $result") . ") { $error } } catch (Error \$e) { $error }";
+ } catch (Error $e) {
+ if (get_class($e) == "Error") {
+ return "// exempt $op1_p $operator $op2_p from checking, it generates a compile time
error";
+ }
+ $msg = makeParam($e->getMessage());
+ $line .= "$compare; $error } catch (Error \$e) { if (\$e->getMessage() !== $msg) { $error
} }";
+ }
+ return $line;
+}
+
+$filename = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'compare_binary_operands_temp.php';
+$file = fopen($filename, "w");
+
+fwrite($file, "<?php\n");
+
+foreach ($input as $left) {
+ foreach ($input as $right) {
+ foreach ($operands as $operand) {
+ fwrite($file, prepareLine($left, $right, function() use ($left, $right, $operand) { return
eval("return @(\$left $operand \$right);"); }, $operand) . "\n");
+ }
+ }
+}
+
+fclose($file);
+
+include $filename;
+
+if($c === 0) {
+ echo "Completely failed\n";
+} else {
+ echo "Failed: $f\n";
+}
+?>
+===DONE===
+--CLEAN--
+<?php
+$fl = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'compare_equality_temp.php';
+//@unlink($fl);
+?>
+--EXPECTF--
+Failed: 0
+===DONE===