test/test_command.rb in cri-2.0a2 vs test/test_command.rb in cri-2.0a3

- old
+ new

@@ -7,20 +7,20 @@ name 'moo' usage 'dunno whatever' summary 'does stuff' description 'This command does a lot of stuff.' - option :a, :aaa, 'opt a', :argument => :optional do |value| - $stdout.puts "#{name}:#{value}" + option :a, :aaa, 'opt a', :argument => :optional do |value, cmd| + $stdout.puts "#{cmd.name}:#{value}" end required :b, :bbb, 'opt b' optional :c, :ccc, 'opt c' flag :d, :ddd, 'opt d' forbidden :e, :eee, 'opt e' - run do |opts, args| - $stdout.puts "Awesome #{name}!" + run do |opts, args, c| + $stdout.puts "Awesome #{c.name}!" $stdout.puts args.join(',') opts_strings = [] opts.each_pair { |k,v| opts_strings << "#{k}=#{v}" } @@ -43,12 +43,12 @@ name 'super' usage 'super [command] [options] [arguments]' summary 'does super stuff' description 'This command does super stuff.' - option :a, :aaa, 'opt a', :argument => :optional do |value| - $stdout.puts "#{name}:#{value}" + option :a, :aaa, 'opt a', :argument => :optional do |value, cmd| + $stdout.puts "#{cmd.name}:#{value}" end required :b, :bbb, 'opt b' optional :c, :ccc, 'opt c' flag :d, :ddd, 'opt d' forbidden :e, :eee, 'opt e' @@ -218,11 +218,24 @@ def test_help_for_bare_cmd bare_cmd.help end - def test_modify + def test_modify_with_block_argument + cmd = Cri::Command.define do |c| + c.name 'build' + end + assert_equal 'build', cmd.name + + cmd.modify do |c| + c.name 'compile' + end + + assert_equal 'compile', cmd.name + end + + def test_modify_without_block_argument cmd = Cri::Command.define do name 'build' end assert_equal 'build', cmd.name @@ -244,8 +257,42 @@ assert_equal 'help', opt_def[:long] # Check subcommand assert_equal 1, cmd.subcommands.size assert_equal 'help', cmd.subcommands.to_a[0].name + end + + def test_define_with_block_argument + cmd = Cri::Command.define do |c| + c.name 'moo' + end + + assert_equal 'moo', cmd.name + end + + def test_define_without_block_argument + cmd = Cri::Command.define do + name 'moo' + end + + assert_equal 'moo', cmd.name + end + + def test_define_subcommand_with_block_argument + cmd = bare_cmd + cmd.define_command do |c| + c.name 'baresub' + end + + assert_equal 'baresub', cmd.subcommands.to_a[0].name + end + + def test_define_subcommand_without_block_argument + cmd = bare_cmd + cmd.define_command do + name 'baresub' + end + + assert_equal 'baresub', cmd.subcommands.to_a[0].name end end