[svn:parrot] r46571 - in trunk: runtime/parrot/library/Getopt t/library

cotto at svn.parrot.org cotto at svn.parrot.org
Thu May 13 05:28:38 UTC 2010


Author: cotto
Date: Thu May 13 05:28:38 2010
New Revision: 46571
URL: https://trac.parrot.org/parrot/changeset/46571

Log:
[getopt] apply getopt fix from branch to trunk

Modified:
   trunk/runtime/parrot/library/Getopt/Obj.pir
   trunk/t/library/getopt_obj.t

Modified: trunk/runtime/parrot/library/Getopt/Obj.pir
==============================================================================
--- trunk/runtime/parrot/library/Getopt/Obj.pir	Thu May 13 05:04:21 2010	(r46570)
+++ trunk/runtime/parrot/library/Getopt/Obj.pir	Thu May 13 05:28:38 2010	(r46571)
@@ -189,8 +189,23 @@
     unless type == 'Boolean' goto endif_4
     val = 1
     goto beginstore_1
+
 endif_4:
+    # just a --foo type, do the optarg check here
+    $I0 = spec."optarg"()
     if $I0 goto beginstore_1
+    $I0 = index arg, '='
+    if $I0 != -1 goto else_4
+    delete argv[i]
+    argc = argv
+    unless i < argc goto error_1
+#    # XXX/TODO doesn't yet check the value of argv[i]
+#    #          to see if it's a possible argument
+#    # argv[i] gets deleted before going to the next arg
+    val = argv[i]
+    goto beginstore
+
+else_4:
     if_null val, error_0
     goto beginstore_1
 error_0:

Modified: trunk/t/library/getopt_obj.t
==============================================================================
--- trunk/t/library/getopt_obj.t	Thu May 13 05:04:21 2010	(r46570)
+++ trunk/t/library/getopt_obj.t	Thu May 13 05:28:38 2010	(r46571)
@@ -20,7 +20,7 @@
 .sub main :main
     .include 'test_more.pir'
     load_bytecode "Getopt/Obj.pbc"
-    plan(48)
+    plan(49)
 
     test_basic_long_options()
     test_basic_short_options()
@@ -47,6 +47,8 @@
         push argv, '--bar=3.14'
         push argv, '--bax=3'
         push argv, '--baz'
+        push argv, '--quux'
+        push argv, 'frobz'
 
         .local pmc getopts
         getopts = new ['Getopt';'Obj']
@@ -66,6 +68,11 @@
         $P0 = getopts."add"()
         $P0."long"("baz")
 
+        $P0 = getopts."add"()
+        $P0."long"("quux")
+        $P0."type"("String")
+        $P0.'optarg'(0)
+
         $P1 = getopts."get_options"(argv)
 
         $S0 = $P1["foo"]
@@ -79,6 +86,9 @@
 
         $S0 = $P1["baz"]
         is($S0, 1, 'basic long options')
+
+        $S0 = $P1["quux"]
+        is($S0, 'frobz', 'basic long options')
 .end
 
 # 2


More information about the parrot-commits mailing list