helly           Sat Oct 26 12:54:30 2002 EDT

  Modified files:              
    /php4       README.TESTING run-tests.php 
  Log:
  -introduce EXPECTREGEX
  -add %c for EXPECTF
  #i think we must escape the special characters for EXPECTF: ".()" and such
  
  
Index: php4/README.TESTING
diff -u php4/README.TESTING:1.15 php4/README.TESTING:1.16
--- php4/README.TESTING:1.15    Fri Oct 25 14:09:55 2002
+++ php4/README.TESTING Sat Oct 26 12:54:30 2002
@@ -160,15 +160,17 @@
 As you can see the file is devided into several sections. Below is a
 list of all possible sections:
 
-"--TEST--"    is title of the test (required).
-"--SKIPIF--"  is condition when to skip this test (optional).
-"--POST--"    is POST variable passed to test script (optional).
-"--GET--"     is GET variable passed to test script (optional).
-"--INI--"     each line contains an ini setting e.g. foo=bar (optional).
-"--FILE--"    is the test script (required).
-"--EXPECT--"  is the expected output from the test script (required).
-"--EXPECTF--" this is the alternative of --EXPECT--. The difference is
-              that this form uses sscanf for output validation (alternative).
+"--TEST--"        is title of the test (required).
+"--SKIPIF--"      is condition when to skip this test (optional).
+"--POST--"        is POST variable passed to test script (optional).
+"--GET--"         is GET variable passed to test script (optional).
+"--INI--"         each line contains an ini setting e.g. foo=bar (optional).
+"--FILE--"        is the test script (required).
+"--EXPECT--"      is the expected output from the test script (required).
+"--EXPECTF--"     is an alternative of --EXPECT--. The difference is that
+                  this form uses sscanf for output validation (alternative).
+"--EXPECTREGEX--" is an alternative of --EXPECT--. This form allows the tester
+                  to specify the result in a regular expression (alternative).
 
 A test must at least contain the sections TEST, FILE and either EXPECT
 or EXPECTF. When a test is called run-test.php takes the name from the
@@ -182,7 +184,8 @@
 changed and sometimes the machine used to execute the code has influence 
 on the result of shuffle. But it always returns a three character string 
 detectable by %s. Other scan-able forms are %i for integers, %d for numbers
-only, %f for floating point values and %x for hexadecimal values.
+only, %f for floating point values, %c for single characters and %x for 
+hexadecimal values.
 
 ==== /ext/standard/tests/strings/str_shuffle.phpt ===
 --TEST--
@@ -198,6 +201,26 @@
 string(3) %s
 string(3) "123"
 ==== end of /ext/standard/tests/strings/str_shuffle.phpt ===
+
+/ext/standard/tests/strings/strings001.phpt is a good example for using 
+EXPECTREGEX instead of EXPECT. This test also shows that in both EXPECTF
+and EXPECTREGEX some characters need to be escaped since otherwise they
+would be interpreted as a regular expression.
+
+==== /ext/standard/tests/strings/strings001.phpt ===
+--TEST--
+Test whether strstr() and strrchr() are binary safe.
+--FILE--
+<?php
+/* Do not change this test it is a REATME.TESTING example. */
+$s = "alabala nica".chr(0)."turska panica";
+var_dump(strstr($s, "nic"));
+var_dump(strrchr($s," nic"));
+?>
+--EXPECTREGEX--
+string\(18\) \"nica\x00turska panica\"
+string\(19\) \" nica\x00turska panica\"
+==== end of /ext/standard/tests/strings/strings001.phpt ===
 
 Some tests depend on modules or functions available only in certain versions 
 or they even require minimum version of php or zend. These tests should be 
Index: php4/run-tests.php
diff -u php4/run-tests.php:1.90 php4/run-tests.php:1.91
--- php4/run-tests.php:1.90     Fri Oct 25 13:24:09 2002
+++ php4/run-tests.php  Sat Oct 26 12:54:30 2002
@@ -559,17 +559,24 @@
        $output = trim($out);
        $output = preg_replace('/\r\n/',"\n",$output);
 
-       if (isset($section_text['EXPECTF'])) {
-               $wanted = trim($section_text['EXPECTF']);
+       if (isset($section_text['EXPECTF']) || isset($section_text['EXPECTREGEX'])) {
+               if (isset($section_text['EXPECTF'])) {
+                       $wanted = trim($section_text['EXPECTF']);
+               } else {
+                       $wanted = trim($section_text['EXPECTREGEX']);
+               }
                $wanted_re = preg_replace('/\r\n/',"\n",$wanted);
-               $wanted_re = preg_quote($wanted_re, '/');
-               // Stick to basics
-               $wanted_re = str_replace("%s", ".+?", $wanted_re); //not greedy
-               $wanted_re = str_replace("%i", "[+\-]?[0-9]+", $wanted_re);
-               $wanted_re = str_replace("%d", "[0-9]+", $wanted_re);
-               $wanted_re = str_replace("%x", "[0-9a-fA-F]+", $wanted_re);
-               $wanted_re = str_replace("%f", "[+\-]?\.?[0-9]+\.?[0-9]*", $wanted_re);
-               // %f allows two points "-.0.0" but that is the best *simple* 
expression
+               if (isset($section_text['EXPECTF'])) {
+                       $wanted_re = preg_quote($wanted_re, '/');
+                       // Stick to basics
+                       $wanted_re = str_replace("%s", ".+?", $wanted_re); //not greedy
+                       $wanted_re = str_replace("%i", "[+\-]?[0-9]+", $wanted_re);
+                       $wanted_re = str_replace("%d", "[0-9]+", $wanted_re);
+                       $wanted_re = str_replace("%x", "[0-9a-fA-F]+", $wanted_re);
+                       $wanted_re = str_replace("%f", "[+\-]?\.?[0-9]+\.?[0-9]*", 
+$wanted_re);
+                       $wanted_re = str_replace("%c", ".", $wanted_re);
+                       // %f allows two points "-.0.0" but that is the best *simple* 
+expression
+               }
 /* DEBUG YOUR REGEX HERE
                var_dump($wanted);
                print(str_repeat('=', 80) . "\n");



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

Reply via email to