X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=tests%2Fgetopt%2Fgetopt001.phpt;h=71af2c7fdbe178bd1bfe4977271c8f0aaa3536c8;hb=9aeae2c241e303c537d8be18dd6c9f8776b2f044;hp=462b4709bafe4696dc1974737e3792cf1ec27386;hpb=a107dfcca2dfd0fc5a2779a8d679f778cb8f3290;p=m6w6%2Fext-psi diff --git a/tests/getopt/getopt001.phpt b/tests/getopt/getopt001.phpt index 462b470..71af2c7 100644 --- a/tests/getopt/getopt001.phpt +++ b/tests/getopt/getopt001.phpt @@ -3,9 +3,10 @@ getopt --INI-- psi.directory={PWD}:{PWD}/../../psi.d --SKIPIF-- - --ENV-- POSIXLY_CORRECT= @@ -19,27 +20,31 @@ $args = [ $opts = "v::x:s:"; -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; +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; + } } -} -$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); ?> @@ -53,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"