OSDN Git Service

- fixed bug "ethna pear-local list -a" command emits error.
authormumumu-org <mumumu-org@2ef88817-412d-0410-a32c-8029a115e976>
Thu, 26 Mar 2009 06:48:22 +0000 (06:48 +0000)
committermumumu-org <mumumu-org@2ef88817-412d-0410-a32c-8029a115e976>
Thu, 26 Mar 2009 06:48:22 +0000 (06:48 +0000)
-- https://sourceforge.jp/ticket/browse.php?group_id=1343&tid=15760

CHANGES
class/Ethna_Getopt.php
test/Ethna_Getopt_Test.php
test/Ethna_MockProject.php
test/Plugin/Handle/Ethna_Plugin_Handle_I18n_Test.php
test/Plugin/Handle/Ethna_Plugin_Handle_PearLocal_Test.php [new file with mode: 0644]

diff --git a/CHANGES b/CHANGES
index 3d402b6..0806ff1 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -6,6 +6,8 @@
 
 *** bug fix
 
+- "ethna pear-local list -a" の実行結果がエラーになってしまうバグを修正
+-- https://sourceforge.jp/ticket/browse.php?group_id=1343&tid=15760
 - safe-mode が ON の際に、CacheManager_Localfile がディレクトリを生成できないので、tmp ディレクトリ直下にキャッシュファイルを作成するようにした
 -- skel/skel.app_manager.php も修正
 - APPID-ini.php が存在しない場合,またはURLが設定にない場合,デフォルトURLが HTTP_HOST で設定されていたが,末尾に / がなかったので修正
index e0b6033..3af565b 100644 (file)
@@ -228,7 +228,17 @@ class Ethna_Getopt
                  } 
 
              } else {  // オプションとして解釈されない
-                 $nonparsed_arguments[] = $arg;
+
+                 //   non-parsed なオプションに辿り着いた
+                 //   ら、それ以降の解釈を停止する
+                 //   つまり、それ以降は全て値として解釈する
+                 //
+                 //   これは POSIX_CORRECT な実装であって
+                 //   GNU Getopt な実装ではないが、実際に
+                 //   Console_Getopt で行われている以上、
+                 //   それに従った実装
+                 $nonparsed_arguments = array_slice($args, $pos);
+                 break;
              }
         }
   
index c1ddf9e..0d345ac 100644 (file)
@@ -181,14 +181,13 @@ class Ethna_Getopt_Test extends Ethna_UnitTestBase
         $parsed_arg = array_shift($r);
         $this->assertEqual('a', $parsed_arg[0][0]);
         $this->assertNULL($parsed_arg[0][1]);
-        $this->assertEqual('c', $parsed_arg[1][0]);
-        $this->assertEqual('d', $parsed_arg[1][1]);
-        $this->assertEqual('e', $parsed_arg[2][0]);
-        $this->assertNULL($parsed_arg[2][1]);
  
         $nonparsed_arg = array_shift($r);
         $this->assertEqual('b', $nonparsed_arg[0]);
-        $this->assertEqual('f', $nonparsed_arg[1]);
+        $this->assertEqual('-c', $nonparsed_arg[1]);
+        $this->assertEqual('d', $nonparsed_arg[2]);
+        $this->assertEqual('-e', $nonparsed_arg[3]);
+        $this->assertEqual('f', $nonparsed_arg[4]);
     }
 
     function test_shortopt_complex()
@@ -196,7 +195,7 @@ class Ethna_Getopt_Test extends Ethna_UnitTestBase
         //  complex option part 1.
         $args = array();
         $shortopt = 'ab:c::';
-        $args = array('-abc', '-cd');
+        $args = array('-abcd', '-cd');
         $r = $this->opt->getopt($args, $shortopt);
         $this->assertFalse(Ethna::isError($r));
 
@@ -205,7 +204,7 @@ class Ethna_Getopt_Test extends Ethna_UnitTestBase
         $this->assertNULL($parsed_arg[0][1]);
 
         $this->assertEqual('b', $parsed_arg[1][0]);
-        $this->assertEqual('c', $parsed_arg[1][1]);
+        $this->assertEqual('cd', $parsed_arg[1][1]);
 
         $this->assertEqual('c', $parsed_arg[2][0]);
         $this->assertEqual('d', $parsed_arg[2][1]);
@@ -289,8 +288,8 @@ class Ethna_Getopt_Test extends Ethna_UnitTestBase
         $nonparsed_arg = array_shift($r);
         $this->assertEqual('hoge', $nonparsed_arg[0]);
  
-        // --foo option value is bar. hoge is nonparsed.
-        $args = array('--foo', 'bar', 'hoge');
+        // --foo option value is bar. hoge, -fuga is nonparsed.
+        $args = array('--foo', 'bar', 'hoge', '-fuga');
         $shortopt = NULL;
         $longopt = array("foo=");
         $r = $this->opt->getopt($args, $shortopt, $longopt);
@@ -302,6 +301,7 @@ class Ethna_Getopt_Test extends Ethna_UnitTestBase
 
         $nonparsed_arg = array_shift($r);
         $this->assertEqual('hoge', $nonparsed_arg[0]);
+        $this->assertEqual('-fuga', $nonparsed_arg[1]);
     }
 
     function test_longopt_optional()
@@ -417,12 +417,11 @@ class Ethna_Getopt_Test extends Ethna_UnitTestBase
         $this->assertEqual('bar', $parsed_arg[1][1]);
         $this->assertequal('--bar', $parsed_arg[2][0]);
         $this->assertEqual('moge', $parsed_arg[2][1]);
-        $this->assertequal('--hoge', $parsed_arg[3][0]);
-        $this->assertNULL($parsed_arg[3][1]);
 
 
         $nonparsed_arg = array_shift($r);
         $this->assertEqual('hoge', $nonparsed_arg[0]);
+        $this->assertEqual('--hoge', $nonparsed_arg[1]);
     }
     // }}}
 }
index 593986c..7427d5a 100644 (file)
@@ -104,8 +104,8 @@ class Ethna_MockProject
             }
         }
         if (!$in_basedir_opt) { 
-            $options[] = '-b';
-            $options[] = $this->proj_basedir;
+            $base_opt = array('-b', $this->proj_basedir);
+            $options = array_merge($base_opt, $options);
         }
 
         $eh =& new Ethna_Handle();
index 9179cf2..96d1bb8 100644 (file)
@@ -124,6 +124,44 @@ class Ethna_Plugin_Handle_I18n_Test extends Ethna_UnitTestBase
         $this->assertTrue(isset($catalog['template i18n multiple modifier']));
     } 
 
+    function test_cmd_option()
+    {
+        //    unrecognized option
+        $r = $this->proj->runCmd('i18n', array('-k'));
+        $this->assertTrue(Ethna::isError($r));
+        $this->assertEqual('unrecognized option -k', $r->getMessage());
+
+        //    --locale(requires an argument)
+        $r = $this->proj->runCmd('i18n', array('-l'));
+        $this->assertTrue(Ethna::isError($r));
+        $this->assertEqual('option -l requires an argument', $r->getMessage());
+
+        $r = $this->proj->runCmd('i18n', array('-l', 'ko_KR'));
+        $this->assertFalse(Ethna::isError($r));
+        
+        $r = $this->proj->runCmd('i18n', array('--locale'));
+        $this->assertTrue(Ethna::isError($r));
+        $this->assertEqual('option --locale requires an argument', $r->getMessage());
+
+        //    --gettext option only
+        $r = $this->proj->runCmd('i18n', array('-g'));
+        $this->assertFalse(Ethna::isError($r));
+
+        $r = $this->proj->runCmd('i18n', array('--gettext'));
+        $this->assertFalse(Ethna::isError($r));
+
+        //    --gettext not allowed an argument 
+        $r = $this->proj->runCmd('i18n', array('--gettext=foo'));
+        $this->assertTrue(Ethna::isError($r));
+        $this->assertEqual("option --gettext doesn't allow an argument", $r->getMessage());
+
+        //    --locale and --gettext mixin
+        $r = $this->proj->runCmd('i18n', array('-g', '-l', 'ko_KR'));
+        $this->assertFalse(Ethna::isError($r));
+
+        $r = $this->proj->runCmd('i18n', array('--gettext', '--locale=ko_KR'));
+        $this->assertFalse(Ethna::isError($r));
+    }
    
     function run_i18n_cmd()
     {
@@ -133,6 +171,8 @@ class Ethna_Plugin_Handle_I18n_Test extends Ethna_UnitTestBase
             return;
         }
     } 
+
+
 }
 // }}}
 
diff --git a/test/Plugin/Handle/Ethna_Plugin_Handle_PearLocal_Test.php b/test/Plugin/Handle/Ethna_Plugin_Handle_PearLocal_Test.php
new file mode 100644 (file)
index 0000000..f63ef51
--- /dev/null
@@ -0,0 +1,64 @@
+<?php
+// vim: foldmethod=marker
+/**
+ *  Ethna_Plugin_Handle_PearLocal_Test.php
+ *
+ *  @author     Yoshinari Takaoka <takaoka@beatcraft.com>
+ *  @version    $Id$
+ */
+
+require_once ETHNA_BASE . '/test/Ethna_MockProject.php';
+
+//{{{  Ethna_Plugin_Handle_PearLocal_Test
+/**
+ *  Test Case For Ethna_Plugin_Handle_PearLocal_Test
+ *
+ *  @access public
+ */
+class Ethna_Plugin_Handle_PearLocal_Test extends Ethna_UnitTestBase 
+{
+    var $proj;
+
+    function setUp()
+    {
+        $this->proj = new Ethna_MockProject();
+        $r = $this->proj->create();
+        if (Ethna::isError($r)) {
+            $this->fail($r->getMessage());    
+        }
+    }
+
+    function tearDown()
+    {
+        $this->proj->delete();
+    }
+
+    function test_cmd_option()
+    {
+        //    unrecognized option
+        $r = $this->proj->runCmd('pear-local', array('-k'));
+        $this->assertTrue(Ethna::isError($r));
+        $this->assertEqual('unrecognized option -k', $r->getMessage());
+
+        //    pear list -a(get no error)
+        //    @see http://sourceforge.jp/ticket/browse.php?group_id=1343&tid=15760
+        $r = $this->proj->runCmd('pear-local', array('list', '-a'));
+        $this->assertFalse(Ethna::isError($r));
+
+        //    channel requires an argument
+        $r = $this->proj->runCmd('pear-local', array('-c'));
+        $this->assertTrue(Ethna::isError($r));
+        $this->assertEqual('option -c requires an argument', $r->getMessage());
+
+        $r = $this->proj->runCmd('pear-local', array('--channel'));
+        $this->assertTrue(Ethna::isError($r));
+        $this->assertEqual('option --channel requires an argument', $r->getMessage());
+
+        //    normal command exexute
+        $r = $this->proj->runCmd('pear-local', array('install', 'Date'));
+        $this->assertFalse(Ethna::isError($r));
+    }
+}
+// }}}
+
+?>