travis: update
[m6w6/ext-psi] / tests / getopt / getopt001.phpt
1 --TEST--
2 getopt
3 --INI--
4 psi.directory={PWD}:{PWD}/../../psi.d
5 --SKIPIF--
6 <?php
7 PHP_OS === "Linux" or die("skip - only for Linux");
8 ?>
9 --ENV--
10 POSIXLY_CORRECT=
11 --FILE--
12 ===TEST===
13 <?php
14
15 $args = [
16 "progname", "huh", "-v", "-x", 1, "-s", "foo", "--", "-gotcha", "--bar", "baz"
17 ];
18
19 $opts = "v::x:s:";
20
21 for ($i = 0; $i<3; ++$i) {
22 psi\opterr(0);
23 psi\optind\set(1);
24
25 while (($opt = chr(psi\getopt($args, $opts)))) {
26 switch ($opt) {
27 case "v":
28 printf("got v\n");
29 break;
30 case "x":
31 case "s":
32 printf("got %s: %s\n", $opt, psi\optarg());
33 break;
34 default:
35 printf("error '%s'\n", $opt);
36 case chr(-1):
37 break 2;
38 }
39 }
40
41 $pos = psi\optind\get();
42 while ($pos < count($args)) {
43 printf("arg: %s\n", $args[$pos++]);
44 }
45 }
46 var_dump($args);
47
48 ?>
49 ===DONE===
50 --EXPECT--
51 ===TEST===
52 got v
53 got x: 1
54 got s: foo
55 arg: huh
56 arg: -gotcha
57 arg: --bar
58 arg: baz
59 got v
60 got x: 1
61 got s: foo
62 arg: huh
63 arg: -gotcha
64 arg: --bar
65 arg: baz
66 got v
67 got x: 1
68 got s: foo
69 arg: huh
70 arg: -gotcha
71 arg: --bar
72 arg: baz
73 array(11) {
74 [0]=>
75 string(8) "progname"
76 [1]=>
77 string(2) "-v"
78 [2]=>
79 string(2) "-x"
80 [3]=>
81 string(1) "1"
82 [4]=>
83 string(2) "-s"
84 [5]=>
85 string(3) "foo"
86 [6]=>
87 string(2) "--"
88 [7]=>
89 string(3) "huh"
90 [8]=>
91 string(7) "-gotcha"
92 [9]=>
93 string(5) "--bar"
94 [10]=>
95 string(3) "baz"
96 }
97 ===DONE===