From c4dd7a1a684490673e25aaf4fabec5df138854c4 Mon Sep 17 00:00:00 2001 From: Lorry Tar Creator Date: Thu, 14 Mar 2013 05:42:27 +0000 Subject: Imported from /home/lorry/working-area/delta_php2/php-5.4.13.tar.bz2. --- tests/quicktester.inc | 75 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 tests/quicktester.inc (limited to 'tests/quicktester.inc') diff --git a/tests/quicktester.inc b/tests/quicktester.inc new file mode 100644 index 0000000..48ed6b5 --- /dev/null +++ b/tests/quicktester.inc @@ -0,0 +1,75 @@ +$test) +{ + // ignore empty lines + if (!$test) continue; + + // warn for trailing ; + if (substr(trim($test), -1, 1) === ';') { + echo "WARNING: trailing ';' found in test ".($n+1)."\n"; + exit; + } + + // try for operators + $operators = array('===', '~=='); + $operator = NULL; + foreach ($operators as $a_operator) { + if (strpos($test, $a_operator)!== FALSE) { + $operator = $a_operator; + list($left,$right) = explode($operator, $test); + break; + } + } + if (!$operator) { + echo "WARNING: unknown operator in '$test' (1)\n"; + exit; + } + + $left = eval("return ($left );"); + $right = eval("return ($right);"); + switch (@$operator) { + case '===': // exact match + $result = $left === $right; + break; + case '~==': // may differ after 12th significant number + if ( !is_float($left ) && !is_int($left ) + || !is_float($right) && !is_int($right)) { + $result = FALSE; + break; + } + $result = abs(($left-$right) / $left) < 1e-12; + break; + default: + echo "WARNING: unknown operator in '$test' (2)\n"; + exit; + } + + $success = $success && $result; + if (!$result) { + echo "\nAssert failed:\n"; + echo "$test\n"; + echo "Left: ";var_dump($left ); + echo "Right: ";var_dump($right); + } +} +if ($success) echo "OK"; + -- cgit v1.2.1