raising the head after a three-weeks refactoring
[m6w6/ext-psi] / tests / getopt / getopt001.phpt
index 2209d09c86d98d441c16ac29054fee3c92809d93..71af2c7fdbe178bd1bfe4977271c8f0aaa3536c8 100644 (file)
@@ -3,9 +3,10 @@ getopt
 --INI--
 psi.directory={PWD}:{PWD}/../../psi.d
 --SKIPIF--
-<?php 
+<?php
 extension_loaded("psi") or die("skip - need ext/psi");
-function_exists("psi\\div") or die("skip - need psi\\div()");
+PHP_OS === "Linux" or die("skip - only for Linux");
+function_exists("psi\\getopt") or die("skip - need psi\\getopt()");
 ?>
 --ENV--
 POSIXLY_CORRECT=
@@ -19,29 +20,31 @@ $args = [
 
 $opts = "v::x:s:";
 
-psi\opterr(0);
+for ($i = 0; $i<3; ++$i) {
+       psi\opterr(0);
+       psi\optind\set(1);
 
-while (($opt = chr(psi\getopt($args, $opts)))) {
-       switch ($opt) {
-       case "v":
-               printf("got v\n");
-               break;
-       case "x":
-       case "s":
-               printf("got %s: %s\n", $opt, psi\optarg());
-               break;
-       default: 
-               printf("error '%s'\n", $opt);
-       case chr(-1):
-               break 2;
+       while (($opt = chr(psi\getopt($args, $opts)))) {
+               switch ($opt) {
+               case "v":
+                       printf("got v\n");
+                       break;
+               case "x":
+               case "s":
+                       printf("got %s: %s\n", $opt, psi\optarg());
+                       break;
+               default:
+                       printf("error '%s'\n", $opt);
+               case chr(-1):
+                       break 2;
+               }
        }
-}
 
-$pos = psi\optind();
-while ($pos < count($args)) {
-       printf("arg: %s\n", $args[$pos++]);
+       $pos = psi\optind\get();
+       while ($pos < count($args)) {
+               printf("arg: %s\n", $args[$pos++]);
+       }
 }
-
 var_dump($args);
 
 ?>
@@ -55,6 +58,20 @@ arg: huh
 arg: -gotcha
 arg: --bar
 arg: baz
+got v
+got x: 1
+got s: foo
+arg: huh
+arg: -gotcha
+arg: --bar
+arg: baz
+got v
+got x: 1
+got s: foo
+arg: huh
+arg: -gotcha
+arg: --bar
+arg: baz
 array(11) {
   [0]=>
   string(8) "progname"