]> git.donarmstrong.com Git - biopieces.git/commitdiff
trouble with list of list and class Cast
authormartinahansen <martinahansen@74ccb610-7750-0410-82ae-013aeee3265d>
Fri, 28 May 2010 15:11:44 +0000 (15:11 +0000)
committermartinahansen <martinahansen@74ccb610-7750-0410-82ae-013aeee3265d>
Fri, 28 May 2010 15:11:44 +0000 (15:11 +0000)
git-svn-id: http://biopieces.googlecode.com/svn/trunk@979 74ccb610-7750-0410-82ae-013aeee3265d

code_ruby/Maasha/lib/biopieces.rb
code_ruby/Maasha/test/test_biopieces.rb

index 2459394029ea5f06545c5d00c7c5d97770d6582e..f1a448e02575b22d7ed83f051bd1c24a59a05b85 100644 (file)
@@ -28,10 +28,9 @@ class Biopieces
   # and finally checking the options according to the casts. Returns nil if
   # argv is empty, otherwise an options hash.
   def parse(argv,cast_list=[],script_path=$0)
-    casts        = Casts.new(cast_list)
+    casts = Casts.new(cast_list)
     
-    pp casts.class
-    pp casts.methods
+    pp casts
 
     @script_path = script_path
 
@@ -465,18 +464,19 @@ class Casts < Array
   TYPES     = %w[flag string list int uint float file file! files files! dir dir! genome]
   MANDATORY = %w[long short type mandatory default allowed disallowed]
 
-  def initialize(casts=[])
-    @casts = casts
+  def initialize(cast_list=[])
+    @cast_list = cast_list
     ubiquitous
     check
+    self << @cast_list
   end
 
   # Add ubiquitous options casts.
   def ubiquitous
-    @casts << {:long => 'help',       :short => '?', :type => 'flag',   :mandatory => false, :default => nil, :allowed => nil, :disallowed => nil}
-    @casts << {:long => 'stream_in',  :short => 'I', :type => 'files!', :mandatory => false, :default => nil, :allowed => nil, :disallowed => nil}
-    @casts << {:long => 'stream_out', :short => 'O', :type => 'file',   :mandatory => false, :default => nil, :allowed => nil, :disallowed => nil}
-    @casts << {:long => 'verbose',    :short => 'v', :type => 'flag',   :mandatory => false, :default => nil, :allowed => nil, :disallowed => nil}
+    @cast_list << {:long => 'help',       :short => '?', :type => 'flag',   :mandatory => false, :default => nil, :allowed => nil, :disallowed => nil}
+    @cast_list << {:long => 'stream_in',  :short => 'I', :type => 'files!', :mandatory => false, :default => nil, :allowed => nil, :disallowed => nil}
+    @cast_list << {:long => 'stream_out', :short => 'O', :type => 'file',   :mandatory => false, :default => nil, :allowed => nil, :disallowed => nil}
+    @cast_list << {:long => 'verbose',    :short => 'v', :type => 'flag',   :mandatory => false, :default => nil, :allowed => nil, :disallowed => nil}
   end
 
   # Check integrity of the casts.
@@ -488,7 +488,7 @@ class Casts < Array
   
   # Check if all mandatory keys are present in casts and raise if not.
   def check_keys
-    @casts.each do |cast|
+    @cast_list.each do |cast|
       MANDATORY.each do |mandatory|
         raise CastError, "Missing symbol in cast: '#{mandatory.to_sym}'" unless cast.has_key? mandatory.to_sym
       end
@@ -497,7 +497,7 @@ class Casts < Array
 
   # Check if all values in casts are valid.
   def check_values
-    @casts.each do |cast|
+    @cast_list.each do |cast|
       check_val_long(cast)
       check_val_short(cast)
       check_val_type(cast)
@@ -568,7 +568,7 @@ class Casts < Array
   # Check cast for duplicate long or short options names.
   def check_duplicates
     check_hash = {}
-    @casts.each do |cast|
+    @cast_list.each do |cast|
       raise CastError, "Duplicate argument: '--#{cast[:long]}'" if check_hash.has_key? cast[:long]
       raise CastError, "Duplicate argument: '-#{cast[:short]}'" if check_hash.has_key? cast[:short]
       check_hash[cast[:long]]  = true
index 1baa8e3e800f3581977241520f22013126b6ae77..d007d356085cfe1093cc80126c9ceefa9b9c7341 100755 (executable)
@@ -341,14 +341,4 @@ class OptionTest < Test::Unit::TestCase
       assert_nothing_raised(ArgumentError) { @bp.parse(argv, casts, SCRIPT_PATH) }
     end
   end
-
-  test "Biopieces#puts outputs correctly" do
-    argv    = []
-    casts   = []
-    @bp.expects(:print_usage_and_exit).with()
-    options = @bp.parse(argv, casts, SCRIPT_PATH)
-    record  = {"foo" => "bar"}
-
-    assert_equal("foo: bar\n---\n", @bp.puts(record))
-  end
 end