getopt 1.4.2 → 1.4.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f54f1e6653d0a5c7be3fe5980cd54dbadb36ee6a
4
- data.tar.gz: 18ee08f16d15ad19931458fbd3146257adeb84aa
3
+ metadata.gz: e01b97f25a4930c245cb4297d867d3c99db93bea
4
+ data.tar.gz: bae1d1f080a05aa8c87010f7b141caaefe71d94a
5
5
  SHA512:
6
- metadata.gz: 450e1d25c05e828390a3b333e5d39eb474ab2c63b26643b8cddf71efa9ff548498d7340115c651099fc84b545dffd10902279e8013671fccc91df38bb4b9fe14
7
- data.tar.gz: cccc37509314d516557763cd97615f8562afca023311374ca704c0a03f3690dc00a23a83cd3d83f3e74f1c0ef975f2df2ed4dd11550a871cf4073f007c1cbeee
6
+ metadata.gz: cb33d4cc4bc8b1f1afa3a99b3297f8e3bb79cebfd1a7bd2f7e97493c6198dc1ab6b3f0654bb22ed509a2b1079facb83e11ffe82428fa17f4676424373a3907fa
7
+ data.tar.gz: 6c8cd8707a430ee5727a43b5cb1854e169ad8838f6f42c95a37a2550c8d1e4f9c22e390be55487431f8cbe861ddf33ba8817d4dbf288eb9771b66224d8424283
Binary file
Binary file
data/CHANGES CHANGED
@@ -1,3 +1,8 @@
1
+ == 1.4.3 - 7-Jan-2016
2
+ * This gem is now signed.
3
+ * The gem related tasks in the Rakefile now assume Rubygems 2.x.
4
+ * Added getopt.rb, getopt-std.rb and getopt-long.rb files for convenience.
5
+
1
6
  == 1.4.2 - 12-Oct-2014
2
7
  * Updated Rakefile, README and gemspec.
3
8
  * Minor updates to the test file and examples.
data/MANIFEST CHANGED
@@ -3,9 +3,13 @@
3
3
  * README
4
4
  * Rakefile
5
5
  * getopt.gemspec
6
+ * certs/djberg96_pub.pem
6
7
  * examples/example_std.rb
7
8
  * examples/example_long.rb
8
- * lib/getopt/std.rb
9
+ * lib/getopt.rb
10
+ * lib/getopt-long.rb
11
+ * lib/getopt-std.rb
9
12
  * lib/getopt/long.rb
10
- * test/test_getopt_std.rb
13
+ * lib/getopt/std.rb
11
14
  * test/test_getopt_long.rb
15
+ * test/test_getopt_std.rb
data/README CHANGED
@@ -184,7 +184,7 @@ INCREMENT
184
184
  Artistic 2.0
185
185
 
186
186
  = Copyright
187
- (C) 2005-2014, Daniel J. Berger
187
+ (C) 2005-2016, Daniel J. Berger
188
188
  All Rights Reserved
189
189
 
190
190
  = Author
data/Rakefile CHANGED
@@ -7,13 +7,10 @@ CLEAN.include("**/*.gem", "**/*.rbc")
7
7
  namespace :gem do
8
8
  desc "Create the getopt gem"
9
9
  task :create => [:clean] do
10
+ require 'rubygems/package'
10
11
  spec = eval(IO.read('getopt.gemspec'))
11
- if Gem::VERSION < "2.0"
12
- Gem::Builder.new(spec).build
13
- else
14
- require 'rubygems/package'
15
- Gem::Package.build(spec)
16
- end
12
+ spec.signing_key = File.join(Dir.home, '.ssh', 'gem-private_key.pem')
13
+ Gem::Package.build(spec, true)
17
14
  end
18
15
 
19
16
  desc "Install the getopt gem"
@@ -0,0 +1,21 @@
1
+ -----BEGIN CERTIFICATE-----
2
+ MIIDcDCCAligAwIBAgIBATANBgkqhkiG9w0BAQUFADA/MREwDwYDVQQDDAhkamJl
3
+ cmc5NjEVMBMGCgmSJomT8ixkARkWBWdtYWlsMRMwEQYKCZImiZPyLGQBGRYDY29t
4
+ MB4XDTE1MDkwMjIwNDkxOFoXDTE2MDkwMTIwNDkxOFowPzERMA8GA1UEAwwIZGpi
5
+ ZXJnOTYxFTATBgoJkiaJk/IsZAEZFgVnbWFpbDETMBEGCgmSJomT8ixkARkWA2Nv
6
+ bTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAMyTkvXqRp6hLs9eoJOS
7
+ Hmi8kRYbq9Vkf15/hMxJpotYMgJVHHWrmDcC5Dye2PbnXjTkKf266Zw0PtT9h+lI
8
+ S3ts9HO+vaCFSMwFFZmnWJSpQ3CNw2RcHxjWkk9yF7imEM8Kz9ojhiDXzBetdV6M
9
+ gr0lV/alUr7TNVBDngbXEfTWscyXh1qd7xZ4EcOdsDktCe5G45N/o3662tPQvJsi
10
+ FOF0CM/KuBsa/HL1/eoEmF4B3EKIRfTHrQ3hu20Kv3RJ88QM4ec2+0dd97uX693O
11
+ zv6981fyEg+aXLkxrkViM/tz2qR2ZE0jPhHTREPYeMEgptRkTmWSKAuLVWrJEfgl
12
+ DtkCAwEAAaN3MHUwCQYDVR0TBAIwADALBgNVHQ8EBAMCBLAwHQYDVR0OBBYEFEwe
13
+ nn6bfJADmuIDiMSOzedOrL+xMB0GA1UdEQQWMBSBEmRqYmVyZzk2QGdtYWlsLmNv
14
+ bTAdBgNVHRIEFjAUgRJkamJlcmc5NkBnbWFpbC5jb20wDQYJKoZIhvcNAQEFBQAD
15
+ ggEBAHmNOCWoDVD75zHFueY0viwGDVP1BNGFC+yXcb7u2GlK+nEMCORqzURbYPf7
16
+ tL+/hzmePIRz7i30UM//64GI1NLv9jl7nIwjhPpXpf7/lu2I9hOTsvwSumb5UiKC
17
+ /sqBxI3sfj9pr79Wpv4MuikX1XPik7Ncb7NPsJPw06Lvyc3Hkg5X2XpPtLtS+Gr2
18
+ wKJnmzb5rIPS1cmsqv0M9LPWflzfwoZ/SpnmhagP+g05p8bRNKjZSA2iImM/GyYZ
19
+ EJYzxdPOrx2n6NYR3Hk+vHP0U7UBSveI6+qx+ndQYaeyCn+GRX2PKS9h66YF/Q1V
20
+ tGSHgAmcLlkdGgan182qsE/4kKM=
21
+ -----END CERTIFICATE-----
@@ -2,7 +2,7 @@ require 'rubygems'
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = 'getopt'
5
- spec.version = '1.4.2'
5
+ spec.version = '1.4.3'
6
6
  spec.author = 'Daniel J. Berger'
7
7
  spec.license = 'Artistic 2.0'
8
8
  spec.email = 'djberg96@gmail.com'
@@ -10,6 +10,7 @@ Gem::Specification.new do |spec|
10
10
  spec.summary = 'Getopt::Std and Getopt::Long option parsers for Ruby'
11
11
  spec.test_files = Dir['test/*.rb']
12
12
  spec.files = Dir['**/*'].reject{ |f| f.include?('git') }
13
+ spec.cert_chain = Dir['certs/*']
13
14
 
14
15
  spec.extra_rdoc_files = ['README', 'CHANGES', 'MANIFEST']
15
16
 
@@ -0,0 +1 @@
1
+ require_relative 'getopt/long'
@@ -0,0 +1 @@
1
+ require_relative 'getopt/std'
@@ -0,0 +1,2 @@
1
+ require_relative 'getopt/std'
2
+ require_relative 'getopt/long'
@@ -17,7 +17,7 @@ module Getopt
17
17
  class Error < StandardError; end
18
18
 
19
19
  # The version of the getopt library
20
- VERSION = '1.4.2'
20
+ VERSION = '1.4.3'
21
21
 
22
22
  # Takes an array of switches. Each array consists of up to three
23
23
  # elements that indicate the name and type of switch. Returns a hash
@@ -10,7 +10,7 @@ module Getopt
10
10
  class Error < StandardError; end
11
11
 
12
12
  # The version of the getopt library
13
- VERSION = '1.4.2'
13
+ VERSION = '1.4.3'
14
14
 
15
15
  # Processes single character command line options with option
16
16
  # clustering. This information is parsed from ARGV and returned
@@ -9,256 +9,256 @@ require 'getopt/long'
9
9
  include Getopt
10
10
 
11
11
  class TC_Getopt_Long < Test::Unit::TestCase
12
- def setup
13
- @opts = nil
14
- end
12
+ def setup
13
+ @opts = nil
14
+ end
15
15
 
16
- def test_version
17
- assert_equal('1.4.2', Long::VERSION)
18
- end
16
+ def test_version
17
+ assert_equal('1.4.3', Long::VERSION)
18
+ end
19
19
 
20
- def test_constants
21
- assert_not_nil(BOOLEAN)
22
- assert_not_nil(OPTIONAL)
23
- assert_not_nil(REQUIRED)
24
- assert_not_nil(INCREMENT)
25
- end
20
+ def test_constants
21
+ assert_not_nil(BOOLEAN)
22
+ assert_not_nil(OPTIONAL)
23
+ assert_not_nil(REQUIRED)
24
+ assert_not_nil(INCREMENT)
25
+ end
26
26
 
27
- def test_getopts_basic
28
- assert_respond_to(Long, :getopts)
29
- assert_nothing_raised{
30
- Long.getopts(["--test"],["--help"],["--foo"])
31
- }
32
- assert_nothing_raised{
33
- Long.getopts(["--test", "-x"],["--help", "-y"],["--foo", "-z"])
34
- }
35
- assert_nothing_raised{
36
- Long.getopts(
37
- ["--test", "-x", BOOLEAN],
38
- ["--help", "-y", REQUIRED],
39
- ["--foo", "-z", OPTIONAL],
40
- ["--more", "-m", INCREMENT]
41
- )
42
- }
43
- assert_kind_of(Hash, Long.getopts("--test"))
44
- end
27
+ def test_getopts_basic
28
+ assert_respond_to(Long, :getopts)
29
+ assert_nothing_raised{
30
+ Long.getopts(["--test"],["--help"],["--foo"])
31
+ }
32
+ assert_nothing_raised{
33
+ Long.getopts(["--test", "-x"],["--help", "-y"],["--foo", "-z"])
34
+ }
35
+ assert_nothing_raised{
36
+ Long.getopts(
37
+ ["--test", "-x", BOOLEAN],
38
+ ["--help", "-y", REQUIRED],
39
+ ["--foo", "-z", OPTIONAL],
40
+ ["--more", "-m", INCREMENT]
41
+ )
42
+ }
43
+ assert_kind_of(Hash, Long.getopts("--test"))
44
+ end
45
45
 
46
- def test_getopts_using_equals
47
- ARGV.push("--foo=hello","-b","world")
48
- assert_nothing_raised{
49
- @opts = Long.getopts(
50
- ["--foo", "-f", REQUIRED],
51
- ["--bar", "-b", OPTIONAL]
52
- )
53
- }
54
- assert_equal("hello", @opts["foo"])
55
- assert_equal("hello", @opts["f"])
56
- assert_equal("world", @opts["bar"])
57
- assert_equal("world", @opts["b"])
58
- end
46
+ def test_getopts_using_equals
47
+ ARGV.push("--foo=hello","-b","world")
48
+ assert_nothing_raised{
49
+ @opts = Long.getopts(
50
+ ["--foo", "-f", REQUIRED],
51
+ ["--bar", "-b", OPTIONAL]
52
+ )
53
+ }
54
+ assert_equal("hello", @opts["foo"])
55
+ assert_equal("hello", @opts["f"])
56
+ assert_equal("world", @opts["bar"])
57
+ assert_equal("world", @opts["b"])
58
+ end
59
59
 
60
- def test_getopts_long_embedded_hyphens
61
- ARGV.push('--foo-bar', 'hello', '--test1-test2-test3', 'world')
62
- assert_nothing_raised{
63
- @opts = Long.getopts(
64
- ['--foo-bar', '-f', REQUIRED],
65
- ['--test1-test2-test3', '-t', REQUIRED]
66
- )
67
- }
68
- assert_equal('hello', @opts['foo-bar'])
69
- assert_equal('hello', @opts['f'])
70
- assert_equal('world', @opts['test1-test2-test3'])
71
- assert_equal('world', @opts['t'])
72
- end
60
+ def test_getopts_long_embedded_hyphens
61
+ ARGV.push('--foo-bar', 'hello', '--test1-test2-test3', 'world')
62
+ assert_nothing_raised{
63
+ @opts = Long.getopts(
64
+ ['--foo-bar', '-f', REQUIRED],
65
+ ['--test1-test2-test3', '-t', REQUIRED]
66
+ )
67
+ }
68
+ assert_equal('hello', @opts['foo-bar'])
69
+ assert_equal('hello', @opts['f'])
70
+ assert_equal('world', @opts['test1-test2-test3'])
71
+ assert_equal('world', @opts['t'])
72
+ end
73
73
 
74
- def test_getopts_long_embedded_hyphens_using_equals_sign
75
- ARGV.push('--foo-bar=hello', '--test1-test2-test3=world')
76
- assert_nothing_raised{
77
- @opts = Long.getopts(
78
- ['--foo-bar', '-f', REQUIRED],
79
- ['--test1-test2-test3', '-t', REQUIRED]
80
- )
81
- }
82
- assert_equal('hello', @opts['foo-bar'])
83
- assert_equal('hello', @opts['f'])
84
- assert_equal('world', @opts['test1-test2-test3'])
85
- assert_equal('world', @opts['t'])
86
- end
74
+ def test_getopts_long_embedded_hyphens_using_equals_sign
75
+ ARGV.push('--foo-bar=hello', '--test1-test2-test3=world')
76
+ assert_nothing_raised{
77
+ @opts = Long.getopts(
78
+ ['--foo-bar', '-f', REQUIRED],
79
+ ['--test1-test2-test3', '-t', REQUIRED]
80
+ )
81
+ }
82
+ assert_equal('hello', @opts['foo-bar'])
83
+ assert_equal('hello', @opts['f'])
84
+ assert_equal('world', @opts['test1-test2-test3'])
85
+ assert_equal('world', @opts['t'])
86
+ end
87
87
 
88
- def test_getopts_short_switch_squished
89
- ARGV.push("-f", "hello", "-bworld")
90
- assert_nothing_raised{
91
- @opts = Long.getopts(
92
- ["--foo", "-f", REQUIRED],
93
- ["--bar", "-b", OPTIONAL]
94
- )
95
- }
96
- assert_equal("hello", @opts["f"])
97
- assert_equal("world", @opts["b"])
98
- end
88
+ def test_getopts_short_switch_squished
89
+ ARGV.push("-f", "hello", "-bworld")
90
+ assert_nothing_raised{
91
+ @opts = Long.getopts(
92
+ ["--foo", "-f", REQUIRED],
93
+ ["--bar", "-b", OPTIONAL]
94
+ )
95
+ }
96
+ assert_equal("hello", @opts["f"])
97
+ assert_equal("world", @opts["b"])
98
+ end
99
99
 
100
- def test_getopts_increment_type
101
- ARGV.push("-m","-m")
102
- assert_nothing_raised{
103
- @opts = Long.getopts(["--more", "-m", INCREMENT])
104
- }
105
- assert_equal(2, @opts["more"])
106
- assert_equal(2, @opts["m"])
107
- end
100
+ def test_getopts_increment_type
101
+ ARGV.push("-m","-m")
102
+ assert_nothing_raised{
103
+ @opts = Long.getopts(["--more", "-m", INCREMENT])
104
+ }
105
+ assert_equal(2, @opts["more"])
106
+ assert_equal(2, @opts["m"])
107
+ end
108
108
 
109
- def test_switches_exist
110
- ARGV.push("--verbose","--test","--foo")
111
- assert_nothing_raised{ @opts = Long.getopts("--verbose --test --foo") }
112
- assert_equal(true, @opts.has_key?("verbose"))
113
- assert_equal(true, @opts.has_key?("test"))
114
- assert_equal(true, @opts.has_key?("foo"))
115
- end
109
+ def test_switches_exist
110
+ ARGV.push("--verbose","--test","--foo")
111
+ assert_nothing_raised{ @opts = Long.getopts("--verbose --test --foo") }
112
+ assert_equal(true, @opts.has_key?("verbose"))
113
+ assert_equal(true, @opts.has_key?("test"))
114
+ assert_equal(true, @opts.has_key?("foo"))
115
+ end
116
116
 
117
- def test_short_switch_synonyms
118
- ARGV.push("--verbose","--test","--foo")
119
- assert_nothing_raised{ @opts = Long.getopts("--verbose --test --foo") }
120
- assert_equal(true, @opts.has_key?("v"))
121
- assert_equal(true, @opts.has_key?("t"))
122
- assert_equal(true, @opts.has_key?("f"))
123
- end
117
+ def test_short_switch_synonyms
118
+ ARGV.push("--verbose","--test","--foo")
119
+ assert_nothing_raised{ @opts = Long.getopts("--verbose --test --foo") }
120
+ assert_equal(true, @opts.has_key?("v"))
121
+ assert_equal(true, @opts.has_key?("t"))
122
+ assert_equal(true, @opts.has_key?("f"))
123
+ end
124
124
 
125
- def test_short_switch_synonyms_with_explicit_types
126
- ARGV.push("--verbose", "--test", "hello", "--foo")
127
- assert_nothing_raised{
128
- @opts = Long.getopts(
129
- ["--verbose", BOOLEAN],
130
- ["--test", REQUIRED],
131
- ["--foo", BOOLEAN]
132
- )
133
- }
134
- assert(@opts.has_key?("v"))
135
- assert(@opts.has_key?("t"))
136
- assert(@opts.has_key?("f"))
137
- end
125
+ def test_short_switch_synonyms_with_explicit_types
126
+ ARGV.push("--verbose", "--test", "hello", "--foo")
127
+ assert_nothing_raised{
128
+ @opts = Long.getopts(
129
+ ["--verbose", BOOLEAN],
130
+ ["--test", REQUIRED],
131
+ ["--foo", BOOLEAN]
132
+ )
133
+ }
134
+ assert(@opts.has_key?("v"))
135
+ assert(@opts.has_key?("t"))
136
+ assert(@opts.has_key?("f"))
137
+ end
138
138
 
139
- def test_switches_with_required_arguments
140
- ARGV.push("--foo","1","--bar","hello")
141
- assert_nothing_raised{
142
- @opts = Long.getopts(
143
- ["--foo", "-f", REQUIRED],
144
- ["--bar", "-b", REQUIRED]
145
- )
146
- }
147
- assert_equal({"foo"=>"1", "bar"=>"hello", "f"=>"1", "b"=>"hello"}, @opts)
148
- end
139
+ def test_switches_with_required_arguments
140
+ ARGV.push("--foo","1","--bar","hello")
141
+ assert_nothing_raised{
142
+ @opts = Long.getopts(
143
+ ["--foo", "-f", REQUIRED],
144
+ ["--bar", "-b", REQUIRED]
145
+ )
146
+ }
147
+ assert_equal({"foo"=>"1", "bar"=>"hello", "f"=>"1", "b"=>"hello"}, @opts)
148
+ end
149
149
 
150
- def test_compressed_switches
151
- ARGV.push("-fb")
152
- assert_nothing_raised{
153
- @opts = Long.getopts(
154
- ["--foo", "-f", BOOLEAN],
155
- ["--bar", "-b", BOOLEAN]
156
- )
157
- }
158
- assert_equal({"foo"=>true, "f"=>true, "b"=>true, "bar"=>true}, @opts)
159
- end
150
+ def test_compressed_switches
151
+ ARGV.push("-fb")
152
+ assert_nothing_raised{
153
+ @opts = Long.getopts(
154
+ ["--foo", "-f", BOOLEAN],
155
+ ["--bar", "-b", BOOLEAN]
156
+ )
157
+ }
158
+ assert_equal({"foo"=>true, "f"=>true, "b"=>true, "bar"=>true}, @opts)
159
+ end
160
160
 
161
- def test_compress_switches_with_required_arg
162
- ARGV.push("-xf", "foo.txt")
163
- assert_nothing_raised{
164
- @opts = Long.getopts(
165
- ["--expand", "-x", BOOLEAN],
166
- ["--file", "-f", REQUIRED]
167
- )
168
- }
169
- assert_equal(
170
- {"x"=>true, "expand"=>true, "f"=>"foo.txt", "file"=>"foo.txt"}, @opts
161
+ def test_compress_switches_with_required_arg
162
+ ARGV.push("-xf", "foo.txt")
163
+ assert_nothing_raised{
164
+ @opts = Long.getopts(
165
+ ["--expand", "-x", BOOLEAN],
166
+ ["--file", "-f", REQUIRED]
171
167
  )
172
- end
168
+ }
169
+ assert_equal(
170
+ {"x"=>true, "expand"=>true, "f"=>"foo.txt", "file"=>"foo.txt"}, @opts
171
+ )
172
+ end
173
173
 
174
- def test_compress_switches_with_compressed_required_arg
175
- ARGV.push("-xffoo.txt")
176
- assert_nothing_raised{
177
- @opts = Long.getopts(
178
- ["--expand", "-x", BOOLEAN],
179
- ["--file", "-f", REQUIRED]
180
- )
181
- }
182
- assert_equal(
183
- {"x"=>true, "expand"=>true, "f"=>"foo.txt", "file"=>"foo.txt"}, @opts
174
+ def test_compress_switches_with_compressed_required_arg
175
+ ARGV.push("-xffoo.txt")
176
+ assert_nothing_raised{
177
+ @opts = Long.getopts(
178
+ ["--expand", "-x", BOOLEAN],
179
+ ["--file", "-f", REQUIRED]
184
180
  )
185
- end
181
+ }
182
+ assert_equal(
183
+ {"x"=>true, "expand"=>true, "f"=>"foo.txt", "file"=>"foo.txt"}, @opts
184
+ )
185
+ end
186
186
 
187
- def test_compress_switches_with_optional_arg_not_defined
188
- ARGV.push("-xf")
189
- assert_nothing_raised{
190
- @opts = Long.getopts(
191
- ["--expand", "-x", BOOLEAN],
192
- ["--file", "-f", OPTIONAL]
193
- )
194
- }
195
- assert_equal(
196
- {"x"=>true, "expand"=>true, "f"=>nil, "file"=>nil}, @opts
187
+ def test_compress_switches_with_optional_arg_not_defined
188
+ ARGV.push("-xf")
189
+ assert_nothing_raised{
190
+ @opts = Long.getopts(
191
+ ["--expand", "-x", BOOLEAN],
192
+ ["--file", "-f", OPTIONAL]
197
193
  )
198
- end
194
+ }
195
+ assert_equal(
196
+ {"x"=>true, "expand"=>true, "f"=>nil, "file"=>nil}, @opts
197
+ )
198
+ end
199
199
 
200
- def test_compress_switches_with_optional_arg
201
- ARGV.push("-xf", "boo.txt")
202
- assert_nothing_raised{
203
- @opts = Long.getopts(
204
- ["--expand", "-x", BOOLEAN],
205
- ["--file", "-f", OPTIONAL]
206
- )
207
- }
208
- assert_equal(
209
- {"x"=>true, "expand"=>true, "f"=>"boo.txt", "file"=>"boo.txt"}, @opts
200
+ def test_compress_switches_with_optional_arg
201
+ ARGV.push("-xf", "boo.txt")
202
+ assert_nothing_raised{
203
+ @opts = Long.getopts(
204
+ ["--expand", "-x", BOOLEAN],
205
+ ["--file", "-f", OPTIONAL]
210
206
  )
211
- end
207
+ }
208
+ assert_equal(
209
+ {"x"=>true, "expand"=>true, "f"=>"boo.txt", "file"=>"boo.txt"}, @opts
210
+ )
211
+ end
212
212
 
213
- def test_compress_switches_with_compressed_optional_arg
214
- ARGV.push("-xfboo.txt")
215
- assert_nothing_raised{
216
- @opts = Long.getopts(
217
- ["--expand", "-x", BOOLEAN],
218
- ["--file", "-f", OPTIONAL]
219
- )
220
- }
221
- assert_equal(
222
- {"x"=>true, "expand"=>true, "f"=>"boo.txt", "file"=>"boo.txt"}, @opts
213
+ def test_compress_switches_with_compressed_optional_arg
214
+ ARGV.push("-xfboo.txt")
215
+ assert_nothing_raised{
216
+ @opts = Long.getopts(
217
+ ["--expand", "-x", BOOLEAN],
218
+ ["--file", "-f", OPTIONAL]
223
219
  )
224
- end
220
+ }
221
+ assert_equal(
222
+ {"x"=>true, "expand"=>true, "f"=>"boo.txt", "file"=>"boo.txt"}, @opts
223
+ )
224
+ end
225
225
 
226
- def test_compressed_short_and_long_mixed
227
- ARGV.push("-xb", "--file", "boo.txt", "-v")
228
- assert_nothing_raised{
229
- @opts = Long.getopts(
230
- ["--expand", "-x", BOOLEAN],
231
- ["--verbose", "-v", BOOLEAN],
232
- ["--file", "-f", REQUIRED],
233
- ["--bar", "-b", OPTIONAL]
234
- )
235
- assert_equal(
236
- { "x"=>true, "expand"=>true,
237
- "v"=>true, "verbose"=>true,
238
- "f"=>"boo.txt", "file"=>"boo.txt",
239
- "b"=>nil, "bar"=>nil
240
- },
241
- @opts
242
- )
243
- }
244
- end
226
+ def test_compressed_short_and_long_mixed
227
+ ARGV.push("-xb", "--file", "boo.txt", "-v")
228
+ assert_nothing_raised{
229
+ @opts = Long.getopts(
230
+ ["--expand", "-x", BOOLEAN],
231
+ ["--verbose", "-v", BOOLEAN],
232
+ ["--file", "-f", REQUIRED],
233
+ ["--bar", "-b", OPTIONAL]
234
+ )
235
+ assert_equal(
236
+ { "x"=>true, "expand"=>true,
237
+ "v"=>true, "verbose"=>true,
238
+ "f"=>"boo.txt", "file"=>"boo.txt",
239
+ "b"=>nil, "bar"=>nil
240
+ },
241
+ @opts
242
+ )
243
+ }
244
+ end
245
245
 
246
- def test_multiple_similar_long_switches_with_no_short_switches
247
- ARGV.push('--to','1','--too','2','--tooo','3')
248
- assert_nothing_raised{
249
- @opts = Long.getopts(
250
- ["--to", REQUIRED],
251
- ["--too", REQUIRED],
252
- ["--tooo", REQUIRED]
253
- )
254
- }
255
- assert_equal('1', @opts['to'])
256
- assert_equal('2', @opts['too'])
257
- assert_equal('3', @opts['tooo'])
258
- end
246
+ def test_multiple_similar_long_switches_with_no_short_switches
247
+ ARGV.push('--to','1','--too','2','--tooo','3')
248
+ assert_nothing_raised{
249
+ @opts = Long.getopts(
250
+ ["--to", REQUIRED],
251
+ ["--too", REQUIRED],
252
+ ["--tooo", REQUIRED]
253
+ )
254
+ }
255
+ assert_equal('1', @opts['to'])
256
+ assert_equal('2', @opts['too'])
257
+ assert_equal('3', @opts['tooo'])
258
+ end
259
259
 
260
- def teardown
261
- @opts = nil
262
- ARGV.clear
263
- end
260
+ def teardown
261
+ @opts = nil
262
+ ARGV.clear
263
+ end
264
264
  end
@@ -9,117 +9,116 @@ require 'getopt/std'
9
9
  include Getopt
10
10
 
11
11
  class TC_Getopt_Std < Test::Unit::TestCase
12
-
13
- def test_version
14
- assert_equal('1.4.2', Std::VERSION)
15
- end
16
-
17
- def test_getopts_basic
18
- assert_respond_to(Std, :getopts)
19
- assert_nothing_raised{ Std.getopts("ID") }
20
- assert_kind_of(Hash, Std.getopts("ID"))
21
- end
22
-
23
- def test_getopts_separated_switches
24
- ARGV.push("-I", "-D")
25
- assert_equal({"I"=>true, "D"=>true}, Std.getopts("ID"))
26
- end
27
-
28
- # Inspired by RF bug #23477
29
- def test_getopts_arguments_that_match_switch_are_ok
30
- ARGV.push("-d", "d")
31
- assert_equal({"d" => "d"}, Std.getopts("d:"))
32
-
33
- ARGV.push("-d", "ad")
34
- assert_equal({"d" => "ad"}, Std.getopts("d:"))
35
-
36
- ARGV.push("-a", "ad")
37
- assert_equal({"a" => "ad"}, Std.getopts("d:a:"))
38
-
39
- ARGV.push("-a", "da")
40
- assert_equal({"a" => "da"}, Std.getopts("d:a:"))
41
-
42
- ARGV.push("-a", "d")
43
- assert_equal({"a" => "d"}, Std.getopts("d:a:"))
44
-
45
- ARGV.push("-a", "dad")
46
- assert_equal({"a" => "dad"}, Std.getopts("d:a:"))
47
-
48
- ARGV.push("-d", "d", "-a", "a")
49
- assert_equal({"d" => "d", "a" => "a"}, Std.getopts("d:a:"))
50
- end
51
-
52
- def test_getopts_joined_switches
53
- ARGV.push("-ID")
54
- assert_equal({"I"=>true, "D"=>true}, Std.getopts("ID"))
55
- end
56
-
57
- def test_getopts_separated_switches_with_mandatory_arg
58
- ARGV.push("-o", "hello", "-I", "-D")
59
- assert_equal({"o"=>"hello", "I"=>true, "D"=>true}, Std.getopts("o:ID"))
60
- end
61
-
62
- def test_getopts_joined_switches_with_mandatory_arg
63
- ARGV.push("-IDo", "hello")
64
- assert_equal({"o"=>"hello", "I"=>true, "D"=>true}, Std.getopts("o:ID"))
65
- end
66
-
67
- def test_getopts_no_args
68
- assert_nothing_raised{ Std.getopts("ID") }
69
- assert_equal({}, Std.getopts("ID"))
70
- assert_nil(Std.getopts("ID")["I"])
71
- assert_nil(Std.getopts("ID")["D"])
72
- end
73
-
74
- # If a switch that accepts an argument appears more than once, the values
75
- # are rolled into an array.
76
- def test_getopts_switch_repeated
77
- ARGV.push("-I", "-I", "-o", "hello", "-o", "world")
78
- assert_equal({"o" => ["hello","world"], "I"=>true}, Std.getopts("o:ID"))
79
- end
80
-
81
- # EXPECTED ERRORS
82
-
83
- def test_getopts_expected_errors_passing_switch_to_another_switch
84
- ARGV.push("-d", "-d")
85
- assert_raise(Getopt::Std::Error){ Std.getopts("d:a:") }
86
-
87
- ARGV.push("-d", "-a")
88
- assert_raise(Getopt::Std::Error){ Std.getopts("d:a:") }
89
-
90
- ARGV.push("-a", "-d")
91
- assert_raise(Getopt::Std::Error){ Std.getopts("d:a:") }
92
-
93
- ARGV.push("-d", "-d")
94
- assert_raise_message("cannot use switch '-d' as argument to another switch"){ Std.getopts("d:a:") }
95
- end
96
-
97
- def test_getopts_expected_errors_missing_arg
98
- ARGV.push("-ID")
99
- assert_raises(Std::Error){ Std.getopts("I:D") }
100
-
101
- ARGV.push("-ID")
102
- assert_raises(Std::Error){ Std.getopts("ID:") }
103
- end
104
-
105
- def test_getopts_expected_errors_extra_arg
106
- ARGV.push("-I", "-D", "-X")
107
- assert_raises(Std::Error){ Std.getopts("ID") }
108
-
109
- ARGV.push("-IDX")
110
- assert_raises(Std::Error){ Std.getopts("ID") }
111
-
112
- ARGV.push("-IDX")
113
- assert_raise_message("invalid option 'X'"){ Std.getopts("ID") }
114
- end
115
-
116
- def test_getopts_expected_errors_basic
117
- assert_raises(ArgumentError){ Std.getopts }
118
- assert_raises(NoMethodError){ Std.getopts(0) }
119
- assert_raises(NoMethodError){ Std.getopts(nil) }
120
- end
121
-
122
- def teardown
123
- ARGV.clear
124
- end
12
+ def test_version
13
+ assert_equal('1.4.3', Std::VERSION)
14
+ end
15
+
16
+ def test_getopts_basic
17
+ assert_respond_to(Std, :getopts)
18
+ assert_nothing_raised{ Std.getopts("ID") }
19
+ assert_kind_of(Hash, Std.getopts("ID"))
20
+ end
21
+
22
+ def test_getopts_separated_switches
23
+ ARGV.push("-I", "-D")
24
+ assert_equal({"I"=>true, "D"=>true}, Std.getopts("ID"))
25
+ end
26
+
27
+ # Inspired by RF bug #23477
28
+ def test_getopts_arguments_that_match_switch_are_ok
29
+ ARGV.push("-d", "d")
30
+ assert_equal({"d" => "d"}, Std.getopts("d:"))
31
+
32
+ ARGV.push("-d", "ad")
33
+ assert_equal({"d" => "ad"}, Std.getopts("d:"))
34
+
35
+ ARGV.push("-a", "ad")
36
+ assert_equal({"a" => "ad"}, Std.getopts("d:a:"))
37
+
38
+ ARGV.push("-a", "da")
39
+ assert_equal({"a" => "da"}, Std.getopts("d:a:"))
40
+
41
+ ARGV.push("-a", "d")
42
+ assert_equal({"a" => "d"}, Std.getopts("d:a:"))
43
+
44
+ ARGV.push("-a", "dad")
45
+ assert_equal({"a" => "dad"}, Std.getopts("d:a:"))
46
+
47
+ ARGV.push("-d", "d", "-a", "a")
48
+ assert_equal({"d" => "d", "a" => "a"}, Std.getopts("d:a:"))
49
+ end
50
+
51
+ def test_getopts_joined_switches
52
+ ARGV.push("-ID")
53
+ assert_equal({"I"=>true, "D"=>true}, Std.getopts("ID"))
54
+ end
55
+
56
+ def test_getopts_separated_switches_with_mandatory_arg
57
+ ARGV.push("-o", "hello", "-I", "-D")
58
+ assert_equal({"o"=>"hello", "I"=>true, "D"=>true}, Std.getopts("o:ID"))
59
+ end
60
+
61
+ def test_getopts_joined_switches_with_mandatory_arg
62
+ ARGV.push("-IDo", "hello")
63
+ assert_equal({"o"=>"hello", "I"=>true, "D"=>true}, Std.getopts("o:ID"))
64
+ end
65
+
66
+ def test_getopts_no_args
67
+ assert_nothing_raised{ Std.getopts("ID") }
68
+ assert_equal({}, Std.getopts("ID"))
69
+ assert_nil(Std.getopts("ID")["I"])
70
+ assert_nil(Std.getopts("ID")["D"])
71
+ end
72
+
73
+ # If a switch that accepts an argument appears more than once, the values
74
+ # are rolled into an array.
75
+ def test_getopts_switch_repeated
76
+ ARGV.push("-I", "-I", "-o", "hello", "-o", "world")
77
+ assert_equal({"o" => ["hello","world"], "I"=>true}, Std.getopts("o:ID"))
78
+ end
79
+
80
+ # EXPECTED ERRORS
81
+
82
+ def test_getopts_expected_errors_passing_switch_to_another_switch
83
+ ARGV.push("-d", "-d")
84
+ assert_raise(Getopt::Std::Error){ Std.getopts("d:a:") }
85
+
86
+ ARGV.push("-d", "-a")
87
+ assert_raise(Getopt::Std::Error){ Std.getopts("d:a:") }
88
+
89
+ ARGV.push("-a", "-d")
90
+ assert_raise(Getopt::Std::Error){ Std.getopts("d:a:") }
91
+
92
+ ARGV.push("-d", "-d")
93
+ assert_raise_message("cannot use switch '-d' as argument to another switch"){ Std.getopts("d:a:") }
94
+ end
95
+
96
+ def test_getopts_expected_errors_missing_arg
97
+ ARGV.push("-ID")
98
+ assert_raises(Std::Error){ Std.getopts("I:D") }
99
+
100
+ ARGV.push("-ID")
101
+ assert_raises(Std::Error){ Std.getopts("ID:") }
102
+ end
103
+
104
+ def test_getopts_expected_errors_extra_arg
105
+ ARGV.push("-I", "-D", "-X")
106
+ assert_raises(Std::Error){ Std.getopts("ID") }
107
+
108
+ ARGV.push("-IDX")
109
+ assert_raises(Std::Error){ Std.getopts("ID") }
110
+
111
+ ARGV.push("-IDX")
112
+ assert_raise_message("invalid option 'X'"){ Std.getopts("ID") }
113
+ end
114
+
115
+ def test_getopts_expected_errors_basic
116
+ assert_raises(ArgumentError){ Std.getopts }
117
+ assert_raises(NoMethodError){ Std.getopts(0) }
118
+ assert_raises(NoMethodError){ Std.getopts(nil) }
119
+ end
120
+
121
+ def teardown
122
+ ARGV.clear
123
+ end
125
124
  end
metadata CHANGED
@@ -1,14 +1,36 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: getopt
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.2
4
+ version: 1.4.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel J. Berger
8
8
  autorequire:
9
9
  bindir: bin
10
- cert_chain: []
11
- date: 2014-10-13 00:00:00.000000000 Z
10
+ cert_chain:
11
+ - |
12
+ -----BEGIN CERTIFICATE-----
13
+ MIIDcDCCAligAwIBAgIBATANBgkqhkiG9w0BAQUFADA/MREwDwYDVQQDDAhkamJl
14
+ cmc5NjEVMBMGCgmSJomT8ixkARkWBWdtYWlsMRMwEQYKCZImiZPyLGQBGRYDY29t
15
+ MB4XDTE1MDkwMjIwNDkxOFoXDTE2MDkwMTIwNDkxOFowPzERMA8GA1UEAwwIZGpi
16
+ ZXJnOTYxFTATBgoJkiaJk/IsZAEZFgVnbWFpbDETMBEGCgmSJomT8ixkARkWA2Nv
17
+ bTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAMyTkvXqRp6hLs9eoJOS
18
+ Hmi8kRYbq9Vkf15/hMxJpotYMgJVHHWrmDcC5Dye2PbnXjTkKf266Zw0PtT9h+lI
19
+ S3ts9HO+vaCFSMwFFZmnWJSpQ3CNw2RcHxjWkk9yF7imEM8Kz9ojhiDXzBetdV6M
20
+ gr0lV/alUr7TNVBDngbXEfTWscyXh1qd7xZ4EcOdsDktCe5G45N/o3662tPQvJsi
21
+ FOF0CM/KuBsa/HL1/eoEmF4B3EKIRfTHrQ3hu20Kv3RJ88QM4ec2+0dd97uX693O
22
+ zv6981fyEg+aXLkxrkViM/tz2qR2ZE0jPhHTREPYeMEgptRkTmWSKAuLVWrJEfgl
23
+ DtkCAwEAAaN3MHUwCQYDVR0TBAIwADALBgNVHQ8EBAMCBLAwHQYDVR0OBBYEFEwe
24
+ nn6bfJADmuIDiMSOzedOrL+xMB0GA1UdEQQWMBSBEmRqYmVyZzk2QGdtYWlsLmNv
25
+ bTAdBgNVHRIEFjAUgRJkamJlcmc5NkBnbWFpbC5jb20wDQYJKoZIhvcNAQEFBQAD
26
+ ggEBAHmNOCWoDVD75zHFueY0viwGDVP1BNGFC+yXcb7u2GlK+nEMCORqzURbYPf7
27
+ tL+/hzmePIRz7i30UM//64GI1NLv9jl7nIwjhPpXpf7/lu2I9hOTsvwSumb5UiKC
28
+ /sqBxI3sfj9pr79Wpv4MuikX1XPik7Ncb7NPsJPw06Lvyc3Hkg5X2XpPtLtS+Gr2
29
+ wKJnmzb5rIPS1cmsqv0M9LPWflzfwoZ/SpnmhagP+g05p8bRNKjZSA2iImM/GyYZ
30
+ EJYzxdPOrx2n6NYR3Hk+vHP0U7UBSveI6+qx+ndQYaeyCn+GRX2PKS9h66YF/Q1V
31
+ tGSHgAmcLlkdGgan182qsE/4kKM=
32
+ -----END CERTIFICATE-----
33
+ date: 2016-01-07 00:00:00.000000000 Z
12
34
  dependencies:
13
35
  - !ruby/object:Gem::Dependency
14
36
  name: test-unit
@@ -37,15 +59,24 @@ extra_rdoc_files:
37
59
  - CHANGES
38
60
  - MANIFEST
39
61
  files:
62
+ - certs
63
+ - certs/djberg96_pub.pem
40
64
  - CHANGES
41
- - MANIFEST
42
- - README
43
- - Rakefile
65
+ - examples
44
66
  - examples/example_long.rb
45
67
  - examples/example_std.rb
46
68
  - getopt.gemspec
69
+ - lib
70
+ - lib/getopt
47
71
  - lib/getopt/long.rb
48
72
  - lib/getopt/std.rb
73
+ - lib/getopt-long.rb
74
+ - lib/getopt-std.rb
75
+ - lib/getopt.rb
76
+ - MANIFEST
77
+ - Rakefile
78
+ - README
79
+ - test
49
80
  - test/test_getopt_long.rb
50
81
  - test/test_getopt_std.rb
51
82
  homepage: https://github.com/djberg96/getopt
@@ -68,7 +99,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
68
99
  version: '0'
69
100
  requirements: []
70
101
  rubyforge_project:
71
- rubygems_version: 2.4.2
102
+ rubygems_version: 2.5.1
72
103
  signing_key:
73
104
  specification_version: 4
74
105
  summary: Getopt::Std and Getopt::Long option parsers for Ruby
Binary file