getopt 1.3.7 → 1.3.8
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +69 -61
- data/MANIFEST +11 -11
- data/Rakefile +22 -22
- data/examples/example_long.rb +65 -65
- data/examples/example_std.rb +38 -38
- data/lib/getopt/long.rb +234 -234
- data/lib/getopt/std.rb +87 -79
- data/test/test_getopt_long.rb +267 -264
- data/test/test_getopt_std.rb +128 -82
- metadata +13 -8
- data/getopt.gemspec +0 -24
data/test/test_getopt_std.rb
CHANGED
@@ -1,82 +1,128 @@
|
|
1
|
-
###################################################################
|
2
|
-
#
|
3
|
-
#
|
4
|
-
# Test suite for the Getopt::Std class. You should run this test
|
5
|
-
# via the 'rake test' task.
|
6
|
-
###################################################################
|
7
|
-
require '
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
ARGV.push("-
|
40
|
-
assert_equal({"
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
ARGV.push("-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
def
|
80
|
-
ARGV.
|
81
|
-
|
82
|
-
end
|
1
|
+
###################################################################
|
2
|
+
# test_getopt_std.rb
|
3
|
+
#
|
4
|
+
# Test suite for the Getopt::Std class. You should run this test
|
5
|
+
# via the 'rake test' task.
|
6
|
+
###################################################################
|
7
|
+
require 'rubygems'
|
8
|
+
gem 'test-unit'
|
9
|
+
|
10
|
+
require 'test/unit'
|
11
|
+
require 'getopt/std'
|
12
|
+
include Getopt
|
13
|
+
|
14
|
+
class TC_Getopt_Std < Test::Unit::TestCase
|
15
|
+
|
16
|
+
def test_version
|
17
|
+
assert_equal('1.3.8', Std::VERSION)
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_getopts_basic
|
21
|
+
assert_respond_to(Std, :getopts)
|
22
|
+
assert_nothing_raised{ Std.getopts("ID") }
|
23
|
+
assert_kind_of(Hash, Std.getopts("ID"))
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_getopts_separated_switches
|
27
|
+
ARGV.push("-I", "-D")
|
28
|
+
assert_equal({"I"=>true, "D"=>true}, Std.getopts("ID"))
|
29
|
+
end
|
30
|
+
|
31
|
+
# Inspired by RF bug #23477
|
32
|
+
def test_getopts_arguments_that_match_switch_are_ok
|
33
|
+
ARGV.push("-d", "d")
|
34
|
+
assert_equal({"d" => "d"}, Std.getopts("d:"))
|
35
|
+
|
36
|
+
ARGV.push("-d", "ad")
|
37
|
+
assert_equal({"d" => "ad"}, Std.getopts("d:"))
|
38
|
+
|
39
|
+
ARGV.push("-a", "ad")
|
40
|
+
assert_equal({"a" => "ad"}, Std.getopts("d:a:"))
|
41
|
+
|
42
|
+
ARGV.push("-a", "da")
|
43
|
+
assert_equal({"a" => "da"}, Std.getopts("d:a:"))
|
44
|
+
|
45
|
+
ARGV.push("-a", "d")
|
46
|
+
assert_equal({"a" => "d"}, Std.getopts("d:a:"))
|
47
|
+
|
48
|
+
ARGV.push("-a", "dad")
|
49
|
+
assert_equal({"a" => "dad"}, Std.getopts("d:a:"))
|
50
|
+
|
51
|
+
ARGV.push("-d", "d", "-a", "a")
|
52
|
+
assert_equal({"d" => "d", "a" => "a"}, Std.getopts("d:a:"))
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_getopts_joined_switches
|
56
|
+
ARGV.push("-ID")
|
57
|
+
assert_equal({"I"=>true, "D"=>true}, Std.getopts("ID"))
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_getopts_separated_switches_with_mandatory_arg
|
61
|
+
ARGV.push("-o", "hello", "-I", "-D")
|
62
|
+
assert_equal({"o"=>"hello", "I"=>true, "D"=>true}, Std.getopts("o:ID"))
|
63
|
+
end
|
64
|
+
|
65
|
+
def test_getopts_joined_switches_with_mandatory_arg
|
66
|
+
ARGV.push("-IDo", "hello")
|
67
|
+
assert_equal({"o"=>"hello", "I"=>true, "D"=>true}, Std.getopts("o:ID"))
|
68
|
+
end
|
69
|
+
|
70
|
+
def test_getopts_no_args
|
71
|
+
assert_nothing_raised{ Std.getopts("ID") }
|
72
|
+
assert_equal({}, Std.getopts("ID"))
|
73
|
+
assert_nil(Std.getopts("ID")["I"])
|
74
|
+
assert_nil(Std.getopts("ID")["D"])
|
75
|
+
end
|
76
|
+
|
77
|
+
# If a switch that accepts an argument appears more than once, the values
|
78
|
+
# are rolled into an array.
|
79
|
+
def test_getopts_switch_repeated
|
80
|
+
ARGV.push("-I", "-I", "-o", "hello", "-o", "world")
|
81
|
+
assert_equal({"o" => ["hello","world"], "I"=>true}, Std.getopts("o:ID"))
|
82
|
+
end
|
83
|
+
|
84
|
+
# EXPECTED ERRORS
|
85
|
+
|
86
|
+
def test_getopts_expected_errors_passing_switch_to_another_switch
|
87
|
+
ARGV.push("-d", "-d")
|
88
|
+
assert_raise(Getopt::Std::Error){ Std.getopts("d:a:") }
|
89
|
+
|
90
|
+
ARGV.push("-d", "-a")
|
91
|
+
assert_raise(Getopt::Std::Error){ Std.getopts("d:a:") }
|
92
|
+
|
93
|
+
ARGV.push("-a", "-d")
|
94
|
+
assert_raise(Getopt::Std::Error){ Std.getopts("d:a:") }
|
95
|
+
|
96
|
+
ARGV.push("-d", "-d")
|
97
|
+
assert_raise_message("cannot use switch '-d' as argument to another switch"){ Std.getopts("d:a:") }
|
98
|
+
end
|
99
|
+
|
100
|
+
def test_getopts_expected_errors_missing_arg
|
101
|
+
ARGV.push("-ID")
|
102
|
+
assert_raises(Std::Error){ Std.getopts("I:D") }
|
103
|
+
|
104
|
+
ARGV.push("-ID")
|
105
|
+
assert_raises(Std::Error){ Std.getopts("ID:") }
|
106
|
+
end
|
107
|
+
|
108
|
+
def test_getopts_expected_errors_extra_arg
|
109
|
+
ARGV.push("-I", "-D", "-X")
|
110
|
+
assert_raises(Std::Error){ Std.getopts("ID") }
|
111
|
+
|
112
|
+
ARGV.push("-IDX")
|
113
|
+
assert_raises(Std::Error){ Std.getopts("ID") }
|
114
|
+
|
115
|
+
ARGV.push("-IDX")
|
116
|
+
assert_raise_message("invalid option 'X'"){ Std.getopts("ID") }
|
117
|
+
end
|
118
|
+
|
119
|
+
def test_getopts_expected_errors_basic
|
120
|
+
assert_raises(ArgumentError){ Std.getopts }
|
121
|
+
assert_raises(NoMethodError){ Std.getopts(0) }
|
122
|
+
assert_raises(NoMethodError){ Std.getopts(nil) }
|
123
|
+
end
|
124
|
+
|
125
|
+
def teardown
|
126
|
+
ARGV.clear
|
127
|
+
end
|
128
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: getopt
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.3.
|
4
|
+
version: 1.3.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel J. Berger
|
@@ -9,10 +9,19 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date:
|
12
|
+
date: 2009-01-06 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
|
-
dependencies:
|
15
|
-
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: test-unit
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 2.0.2
|
24
|
+
version:
|
16
25
|
description: Getopt::Std and Getopt::Long option parsers for Ruby
|
17
26
|
email: djberg96@gmail.com
|
18
27
|
executables: []
|
@@ -27,13 +36,9 @@ files:
|
|
27
36
|
- lib/getopt/long.rb
|
28
37
|
- lib/getopt/std.rb
|
29
38
|
- CHANGES
|
30
|
-
- examples
|
31
|
-
- getopt.gemspec
|
32
|
-
- lib
|
33
39
|
- MANIFEST
|
34
40
|
- Rakefile
|
35
41
|
- README
|
36
|
-
- test
|
37
42
|
- test/test_getopt_long.rb
|
38
43
|
- test/test_getopt_std.rb
|
39
44
|
- examples/example_long.rb
|
data/getopt.gemspec
DELETED
@@ -1,24 +0,0 @@
|
|
1
|
-
require "rubygems"
|
2
|
-
|
3
|
-
spec = Gem::Specification.new do |gem|
|
4
|
-
gem.name = "getopt"
|
5
|
-
gem.version = "1.3.7"
|
6
|
-
gem.author = "Daniel J. Berger"
|
7
|
-
gem.email = "djberg96@gmail.com"
|
8
|
-
gem.homepage = "http://www.rubyforge.org/projects/shards"
|
9
|
-
gem.platform = Gem::Platform::RUBY
|
10
|
-
gem.summary = "Getopt::Std and Getopt::Long option parsers for Ruby"
|
11
|
-
gem.description = "Getopt::Std and Getopt::Long option parsers for Ruby"
|
12
|
-
gem.test_files = Dir["test/*.rb"]
|
13
|
-
gem.has_rdoc = true
|
14
|
-
gem.files = Dir['lib/**/*.rb'] + Dir['[A-Z]*'] + Dir['test/*'] + Dir['examples/*.rb']
|
15
|
-
gem.files.reject! { |fn| fn.include? "CVS" }
|
16
|
-
gem.require_path = "lib"
|
17
|
-
gem.extra_rdoc_files = ["README", "CHANGES", "MANIFEST"]
|
18
|
-
gem.rubyforge_project = 'shards'
|
19
|
-
end
|
20
|
-
|
21
|
-
if $0 == __FILE__
|
22
|
-
Gem.manage_gems
|
23
|
-
Gem::Builder.new(spec).build
|
24
|
-
end
|