~ubuntu-branches/debian/sid/ruby-cri/sid

« back to all changes in this revision

Viewing changes to test/test_command_dsl.rb

  • Committer: Package Import Robot
  • Author(s): Cédric Boutillier
  • Date: 2014-04-14 15:15:48 UTC
  • mfrom: (1.1.3)
  • Revision ID: package-import@ubuntu.com-20140414151548-xni482c106hiik3q
Tags: 2.6.0-1
* Imported Upstream version 2.6.0
* Add asciidoctor to Build-Depends, now that the README file has a .adoc
  extension
* Add privacy-breach.patch to remove remote badges from the README file

Show diffs side-by-side

added added

removed removed

Lines of Context:
5
5
  def test_create_command
6
6
    # Define
7
7
    dsl = Cri::CommandDSL.new
8
 
    dsl.instance_eval do 
 
8
    dsl.instance_eval do
9
9
      name        'moo'
10
10
      usage       'dunno whatever'
11
11
      summary     'does stuff'
12
12
      description 'This command does a lot of stuff.'
13
13
 
14
 
      option    :a, :aaa, 'opt a', :argument => :optional
 
14
      option    :a, :aaa, 'opt a', :argument => :optional, :multiple => true
15
15
      required  :b, :bbb, 'opt b'
16
16
      optional  :c, :ccc, 'opt c'
17
17
      flag      :d, :ddd, 'opt d'
36
36
 
37
37
    # Check options
38
38
    expected_option_definitions = Set.new([
39
 
      { :short => 'a', :long => 'aaa', :desc => 'opt a', :argument => :optional,  :block => nil },
40
 
      { :short => 'b', :long => 'bbb', :desc => 'opt b', :argument => :required,  :block => nil },
41
 
      { :short => 'c', :long => 'ccc', :desc => 'opt c', :argument => :optional,  :block => nil },
42
 
      { :short => 'd', :long => 'ddd', :desc => 'opt d', :argument => :forbidden, :block => nil },
43
 
      { :short => 'e', :long => 'eee', :desc => 'opt e', :argument => :forbidden, :block => nil }
 
39
      { :short => 'a', :long => 'aaa', :desc => 'opt a', :argument => :optional, :multiple => true,   :block => nil },
 
40
      { :short => 'b', :long => 'bbb', :desc => 'opt b', :argument => :required, :multiple => false,  :block => nil },
 
41
      { :short => 'c', :long => 'ccc', :desc => 'opt c', :argument => :optional, :multiple => false,  :block => nil },
 
42
      { :short => 'd', :long => 'ddd', :desc => 'opt d', :argument => :forbidden, :multiple => false, :block => nil },
 
43
      { :short => 'e', :long => 'eee', :desc => 'opt e', :argument => :forbidden, :multiple => false, :block => nil }
44
44
      ])
45
45
    actual_option_definitions = Set.new(command.option_definitions)
46
46
    assert_equal expected_option_definitions, actual_option_definitions
71
71
 
72
72
    # Check options
73
73
    expected_option_definitions = Set.new([
74
 
      { :short => 's', :long => nil,    :desc => 'short', :argument => :forbidden, :block => nil },
75
 
      { :short => nil, :long => 'long', :desc => 'long',  :argument => :forbidden, :block => nil }
76
 
      ])
77
 
    actual_option_definitions = Set.new(command.option_definitions)
78
 
    assert_equal expected_option_definitions, actual_option_definitions
79
 
  end
80
 
 
81
 
  def test_optional_options
82
 
    # Define
83
 
    dsl = Cri::CommandDSL.new
 
74
      { :short => 's', :long => nil,    :desc => 'short', :argument => :forbidden, :multiple => false, :block => nil },
 
75
      { :short => nil, :long => 'long', :desc => 'long',  :argument => :forbidden, :multiple => false, :block => nil }
 
76
    ])
 
77
    actual_option_definitions = Set.new(command.option_definitions)
 
78
    assert_equal expected_option_definitions, actual_option_definitions
 
79
  end
 
80
 
 
81
  def test_multiple
 
82
    # Define
 
83
    dsl = Cri::CommandDSL.new
 
84
    dsl.instance_eval do
 
85
      flag     :f, :flag,     'sample flag option',     :multiple => true
 
86
      required :r, :required, 'sample required option', :multiple => true
 
87
      optional :o, :optional, 'sample optional option', :multiple => true
 
88
 
 
89
      run { |opts, args| }
 
90
    end
 
91
    command = dsl.command
 
92
 
 
93
    # Check options
 
94
    expected_option_definitions = Set.new([
 
95
      { :short => 'f', :long => 'flag',     :desc => 'sample flag option',     :argument => :forbidden, :multiple => true, :block => nil },
 
96
      { :short => 'r', :long => 'required', :desc => 'sample required option', :argument => :required,  :multiple => true, :block => nil },
 
97
      { :short => 'o', :long => 'optional', :desc => 'sample optional option', :argument => :optional,  :multiple => true, :block => nil },
 
98
    ])
 
99
    actual_option_definitions = Set.new(command.option_definitions)
 
100
    assert_equal expected_option_definitions, actual_option_definitions
 
101
  end
 
102
 
 
103
  def test_required_short_and_long
 
104
    # Define
 
105
    dsl = Cri::CommandDSL.new
 
106
    assert_raises ArgumentError do
 
107
      dsl.instance_eval do
 
108
        option nil, nil, 'meh'
 
109
      end
 
110
    end
84
111
    assert_raises ArgumentError do
85
112
      dsl.instance_eval do
86
113
        flag nil, nil, 'meh'
87
114
      end
88
115
    end
 
116
    assert_raises ArgumentError do
 
117
      dsl.instance_eval do
 
118
        required nil, nil, 'meh'
 
119
      end
 
120
    end
 
121
    assert_raises ArgumentError do
 
122
      dsl.instance_eval do
 
123
        optional nil, nil, 'meh'
 
124
      end
 
125
    end
89
126
  end
90
127
 
91
128
  def test_subcommand
117
154
    assert_equal %w( aah moo ), command.aliases.sort
118
155
  end
119
156
 
 
157
  def test_run_arity
 
158
    dsl = Cri::CommandDSL.new
 
159
    assert_raises ArgumentError do
 
160
      dsl.instance_eval do
 
161
        run do |a, b, c, d, e|
 
162
        end
 
163
      end
 
164
    end
 
165
  end
 
166
 
120
167
  def test_runner
121
168
    # Define
122
169
    dsl = Cri::CommandDSL.new