gemma 4.1.0 → 5.0.0
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 +5 -13
- data/README.rdoc +14 -13
- data/bin/gemma +24 -19
- data/lib/gemma.rb +13 -12
- data/lib/gemma/conventions.rb +5 -5
- data/lib/gemma/gem_from_template.rb +23 -22
- data/lib/gemma/options.rb +25 -22
- data/lib/gemma/rake_tasks.rb +20 -11
- data/lib/gemma/rake_tasks/gem_tasks.rb +4 -4
- data/lib/gemma/rake_tasks/minitest_tasks.rb +15 -15
- data/lib/gemma/rake_tasks/plugin.rb +3 -2
- data/lib/gemma/rake_tasks/rdoc_tasks.rb +21 -20
- data/lib/gemma/rake_tasks/yard_tasks.rb +22 -21
- data/lib/gemma/utility.rb +13 -7
- data/lib/gemma/version.rb +3 -2
- data/template/base/.rubocop.yml.erb +6 -0
- data/template/base/Gemfile +3 -2
- data/template/base/{README.rdoc.erb → README.md.erb} +13 -10
- data/template/base/{Rakefile.rb.erb → Rakefile.erb} +3 -1
- data/template/base/gem_name.gemspec.erb +19 -21
- data/template/base/lib/gem_name.rb.erb +7 -2
- data/template/base/lib/gem_name/version.rb.erb +2 -0
- data/template/executable/bin/gem_name.erb +2 -2
- data/template/minitest/test/gem_name/gem_name_test.rb.erb +3 -2
- data/test/gemma/gem_from_template_test.rb +20 -18
- data/test/gemma/gemma_new_test.rb +30 -28
- data/test/gemma/gemma_test.rb +41 -30
- data/test/gemma/options_test.rb +47 -24
- metadata +39 -30
@@ -1,29 +1,27 @@
|
|
1
|
-
#
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
require '<%= gem_name %>/version'
|
6
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'lib/<%= gem_name %>/version'
|
4
|
+
|
7
5
|
Gem::Specification.new do |s|
|
8
|
-
s.name
|
9
|
-
s.version
|
10
|
-
s.platform
|
11
|
-
s.authors
|
12
|
-
s.email
|
13
|
-
s.homepage
|
14
|
-
s.summary
|
15
|
-
s.description
|
6
|
+
s.name = '<%= gem_name %>'
|
7
|
+
s.version = <%= module_name %>::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ['TODO write your name']
|
10
|
+
s.email = ['TODO write your e-mail address']
|
11
|
+
s.homepage = 'TODO homepage'
|
12
|
+
s.summary = %(TODO write short gem summary)
|
13
|
+
s.description = %(TODO write longer gem description)
|
16
14
|
|
17
|
-
#s.add_runtime_dependency '...', '~> x.y.z'
|
15
|
+
# s.add_runtime_dependency '...', '~> x.y.z'
|
18
16
|
s.add_development_dependency 'gemma', '~> <%= Gemma::VERSION %>'
|
19
17
|
|
20
|
-
s.files = Dir.glob('{lib,bin}/**/*.rb') + %w(README.
|
18
|
+
s.files = Dir.glob('{lib,bin}/**/*.rb') + %w(README.md)
|
21
19
|
s.test_files = Dir.glob('test/<%= gem_name %>/*_test.rb')
|
22
|
-
s.executables = Dir.glob('bin/*').map{|f| File.basename(f)}
|
20
|
+
s.executables = Dir.glob('bin/*').map { |f| File.basename(f) }
|
23
21
|
|
24
22
|
s.rdoc_options = [
|
25
|
-
|
26
|
-
|
27
|
-
|
23
|
+
'--main', 'README.md',
|
24
|
+
'--title', "#{s.full_name} Documentation"
|
25
|
+
]
|
26
|
+
s.extra_rdoc_files << 'README.md'
|
28
27
|
end
|
29
|
-
|
@@ -1,9 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require '<%= gem_name %>'
|
2
4
|
require 'minitest/autorun'
|
3
5
|
|
4
6
|
class Test<%= module_name %> < MiniTest::Test
|
5
7
|
def test_<%= gem_name %>
|
6
|
-
assert_equal 3, 1 + 1,
|
8
|
+
assert_equal 3, 1 + 1, 'TODO write tests'
|
7
9
|
end
|
8
10
|
end
|
9
|
-
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'gemma/test_helper'
|
2
3
|
require 'tmpdir'
|
3
4
|
|
@@ -18,29 +19,30 @@ class Gemma::GemFromTemplateTest < MiniTest::Test
|
|
18
19
|
# basic create-from-template tests
|
19
20
|
#
|
20
21
|
gt = Gemma::GemFromTemplate.new
|
21
|
-
gt.gem_name =
|
22
|
+
gt.gem_name = 'my_new_gem'
|
22
23
|
assert gt.good_gem_name?
|
23
24
|
|
24
|
-
assert_equal
|
25
|
-
gt.module_name =
|
26
|
-
assert_equal
|
25
|
+
assert_equal 'MyNewGem', gt.module_name
|
26
|
+
gt.module_name = 'Foo' # override default
|
27
|
+
assert_equal 'Foo', gt.module_name
|
27
28
|
gt.module_name = nil # revert back to default
|
28
|
-
assert_equal
|
29
|
+
assert_equal 'MyNewGem', gt.module_name
|
29
30
|
|
30
|
-
assert_equal
|
31
|
-
gt.dir_name =
|
32
|
-
assert_equal
|
31
|
+
assert_equal 'my_new_gem', gt.dir_name
|
32
|
+
gt.dir_name = 'bar' # override default
|
33
|
+
assert_equal 'bar', gt.dir_name
|
33
34
|
gt.dir_name = nil # revert back to default
|
34
|
-
assert_equal
|
35
|
+
assert_equal 'my_new_gem', gt.dir_name
|
35
36
|
|
36
|
-
template_paths = Gemma::GemFromTemplate::BUILTIN_TEMPLATES.map
|
37
|
-
File.join(Gemma::GemFromTemplate::TEMPLATE_ROOT,path)
|
37
|
+
template_paths = Gemma::GemFromTemplate::BUILTIN_TEMPLATES.map do |path|
|
38
|
+
File.join(Gemma::GemFromTemplate::TEMPLATE_ROOT, path)
|
39
|
+
end
|
38
40
|
assert_equal 'base', File.basename(template_paths.first)
|
39
41
|
|
40
|
-
gt.dir_name =
|
42
|
+
gt.dir_name = 'my_new_gem_base'
|
41
43
|
gt.create_gem template_paths[0..0] # just base
|
42
44
|
|
43
|
-
gt.dir_name =
|
45
|
+
gt.dir_name = 'my_new_gem_full'
|
44
46
|
gt.create_gem template_paths # expand all templates
|
45
47
|
end
|
46
48
|
|
@@ -49,16 +51,16 @@ class Gemma::GemFromTemplateTest < MiniTest::Test
|
|
49
51
|
# we should be able to find the to-do markers in a newly created gem
|
50
52
|
#
|
51
53
|
gt = Gemma::GemFromTemplate.new
|
52
|
-
gt.gem_name =
|
54
|
+
gt.gem_name = 'test_gem'
|
53
55
|
|
54
|
-
template_paths = Gemma::GemFromTemplate::BUILTIN_TEMPLATES.map
|
55
|
-
File.join(Gemma::GemFromTemplate::TEMPLATE_ROOT,path)
|
56
|
+
template_paths = Gemma::GemFromTemplate::BUILTIN_TEMPLATES.map do |path|
|
57
|
+
File.join(Gemma::GemFromTemplate::TEMPLATE_ROOT, path)
|
58
|
+
end
|
56
59
|
gt.create_gem template_paths
|
57
60
|
|
58
61
|
# look for some to-do markers
|
59
62
|
io = StringIO.new
|
60
63
|
Gemma::Utility.rgrep(/TODO/, gt.destination_path, io)
|
61
|
-
assert io.string =~ /README\.
|
64
|
+
assert io.string =~ /README\.md/
|
62
65
|
end
|
63
66
|
end
|
64
|
-
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'gemma/test_helper'
|
2
3
|
require 'tmpdir'
|
3
4
|
require 'open4'
|
@@ -20,13 +21,9 @@ class Gemma::GemmaNewTest < MiniTest::Test
|
|
20
21
|
# stdout and stderr using Open4. (On 1.9.2, we can use <tt>Open3.popen2e</tt>,
|
21
22
|
# which is nicer, but Open3 on ruby 1.8.7 doesn't let us get exitstatus.)
|
22
23
|
#
|
23
|
-
def run_cmd
|
24
|
-
Bundler.with_clean_env
|
25
|
-
#
|
26
|
-
# https://github.com/carlhuda/bundler/issues/1133
|
27
|
-
ENV.delete_if { |k,_| k[0,7] == 'BUNDLE_' }
|
28
|
-
|
29
|
-
# We also have to clear RUBYOPT, because Bundler::ORIGINAL_ENV in the test
|
24
|
+
def run_cmd(*args)
|
25
|
+
Bundler.with_clean_env do
|
26
|
+
# We have to clear RUBYOPT, because Bundler::ORIGINAL_ENV in the test
|
30
27
|
# runner's process still contains some bundler stuff from rake's process.
|
31
28
|
# This suggests that we might have to stop using rake's built-in TestTask,
|
32
29
|
# and instead use one that runs the tests in a Bundler.with_clean_env
|
@@ -35,12 +32,12 @@ class Gemma::GemmaNewTest < MiniTest::Test
|
|
35
32
|
ENV.delete('RUBYOPT')
|
36
33
|
|
37
34
|
output = nil
|
38
|
-
status = Open4.popen4(*args)
|
35
|
+
status = Open4.popen4(*args) do |_pid, i, o, e|
|
39
36
|
i.close
|
40
37
|
output = o.read + e.read
|
41
|
-
|
38
|
+
end
|
42
39
|
[status, output]
|
43
|
-
|
40
|
+
end
|
44
41
|
end
|
45
42
|
|
46
43
|
def setup
|
@@ -52,32 +49,39 @@ class Gemma::GemmaNewTest < MiniTest::Test
|
|
52
49
|
# create a test gem; note that here we DO want the gemma bundler
|
53
50
|
# environment, because it puts our gemma executable on the bin path
|
54
51
|
output = `gemma new --name="test_gem"`
|
55
|
-
raise "gemma new failed:\n#{output}" unless
|
52
|
+
raise "gemma new failed:\n#{output}" unless $CHILD_STATUS.exitstatus
|
56
53
|
|
57
54
|
# we should get some TODOs from the template in the output
|
58
|
-
assert_match
|
55
|
+
assert_match(/TODO write your name/, output)
|
59
56
|
|
60
57
|
Dir.chdir('test_gem')
|
61
58
|
|
62
59
|
# edit the test gem's Gemfile to point to this gemma
|
63
|
-
raise
|
60
|
+
raise 'no Gemfile in test gem' unless File.exist?('Gemfile')
|
64
61
|
File.open('Gemfile', 'a') do |f|
|
65
62
|
f.puts "gem 'gemma', :path => #{@old_pwd.dump}"
|
66
63
|
end
|
67
64
|
|
65
|
+
# bundler will complain if we don't fill in the TODOs
|
66
|
+
gemspec_name = 'test_gem.gemspec'
|
67
|
+
gemspec = File.read(gemspec_name)
|
68
|
+
gemspec.gsub!(/TODO\s*/, '')
|
69
|
+
gemspec.gsub!(/'homepage'/, "'http://example.com'")
|
70
|
+
File.open(gemspec_name, 'w') { |f| f.puts gemspec }
|
71
|
+
|
68
72
|
# run bundler on the test gem; it should find the same gems that we're using
|
69
73
|
# in the gemma bundle
|
70
74
|
status, output = run_cmd('bundle', 'install', '--local')
|
71
|
-
raise "bundle failed:\n#{output}" unless status.exitstatus
|
75
|
+
raise "bundle failed:\n#{output}" unless status.exitstatus.zero?
|
72
76
|
|
73
77
|
# it should say that it has loaded two things from source: gemma and the
|
74
78
|
# test_gem itself; if it doesn't it indicates that something strange
|
75
79
|
# happened with bundler's environment (or it may just break on future
|
76
80
|
# versions of bundler)
|
77
|
-
raise
|
81
|
+
raise 'did not load from source' unless output =~ /from source at/
|
78
82
|
|
79
83
|
# bundler should produce a lock file
|
80
|
-
raise
|
84
|
+
raise 'no Gemfile.lock in test gem' unless File.exist?('Gemfile.lock')
|
81
85
|
end
|
82
86
|
|
83
87
|
def teardown
|
@@ -89,27 +93,25 @@ class Gemma::GemmaNewTest < MiniTest::Test
|
|
89
93
|
# list the rake tasks; this ensures that gemma loaded
|
90
94
|
status, output = run_cmd('rake -T')
|
91
95
|
assert_equal 0, status.exitstatus
|
92
|
-
assert_match
|
93
|
-
assert_match
|
94
|
-
assert_match
|
96
|
+
assert_match(/rake test/, output)
|
97
|
+
assert_match(/rake rdoc/, output)
|
98
|
+
assert_match(/rake yard/, output)
|
95
99
|
|
96
100
|
# run the tests; they should fail initially
|
97
101
|
status, output = run_cmd('rake')
|
98
|
-
assert status.exitstatus
|
99
|
-
assert_match
|
102
|
+
assert status.exitstatus.nonzero?
|
103
|
+
assert_match(/TODO write tests/, output)
|
100
104
|
|
101
105
|
# generate rdoc output
|
102
|
-
status,
|
106
|
+
status, _output = run_cmd('rake rdoc')
|
103
107
|
assert_equal 0, status.exitstatus
|
104
108
|
|
105
109
|
# generate yard output
|
106
|
-
status,
|
110
|
+
status, _output = run_cmd('rake yard')
|
107
111
|
assert_equal 0, status.exitstatus
|
108
112
|
|
109
|
-
# build the gem
|
110
|
-
status,
|
111
|
-
|
112
|
-
assert_equal 1, status.exitstatus
|
113
|
+
# build the gem
|
114
|
+
status, _output = run_cmd('rake build')
|
115
|
+
assert_equal 0, status.exitstatus
|
113
116
|
end
|
114
117
|
end
|
115
|
-
|
data/test/gemma/gemma_test.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'gemma/test_helper'
|
2
3
|
require 'set'
|
3
4
|
|
@@ -19,7 +20,7 @@ class Gemma::GemmaTest < MiniTest::Test
|
|
19
20
|
assert_equal %w(lib FAQ README.md).to_set, g.rdoc.files.to_set
|
20
21
|
assert_equal [], g.rdoc.options
|
21
22
|
assert_equal 'README.md', g.rdoc.main
|
22
|
-
|
23
|
+
assert_nil g.rdoc.title
|
23
24
|
|
24
25
|
g.rdoc.with_rdoc_task do |rd|
|
25
26
|
assert_equal rd.rdoc_files, g.rdoc.files
|
@@ -44,14 +45,16 @@ class Gemma::GemmaTest < MiniTest::Test
|
|
44
45
|
assert_equal [], g.yard.options
|
45
46
|
assert_equal 'yard', g.yard.output
|
46
47
|
assert_equal :yard, g.yard.task_name
|
47
|
-
|
48
|
+
assert_nil g.yard.title
|
48
49
|
|
49
50
|
g.yard.with_yardoc_task do |yd|
|
50
51
|
assert_equal %w(lib), yd.files
|
51
52
|
assert_equal 4, yd.options.size
|
52
|
-
assert_equal
|
53
|
+
assert_equal \
|
54
|
+
'README.rdoc',
|
53
55
|
Gemma::Options.extract(%w(--main), yd.options).argument
|
54
|
-
assert_equal
|
56
|
+
assert_equal \
|
57
|
+
'yard',
|
55
58
|
Gemma::Options.extract(%w(--output), yd.options).argument
|
56
59
|
end
|
57
60
|
end
|
@@ -83,8 +86,10 @@ class Gemma::GemmaTest < MiniTest::Test
|
|
83
86
|
|
84
87
|
# Some more complicated options.
|
85
88
|
# Note that we ignore things that could be files ('bat').
|
86
|
-
s.rdoc_options = [
|
87
|
-
'--
|
89
|
+
s.rdoc_options = [
|
90
|
+
'foo bar', '--baz', 'bat', '--title', 'a b c', '--diagram', '--main',
|
91
|
+
'README.rdoc', 'ABCD'
|
92
|
+
]
|
88
93
|
Gemma::RakeTasks.new(s) do |g|
|
89
94
|
assert_equal 'a b c', g.yard.title
|
90
95
|
assert_equal [], g.yard.options
|
@@ -92,11 +97,14 @@ class Gemma::GemmaTest < MiniTest::Test
|
|
92
97
|
g.yard.with_yardoc_task do |yd|
|
93
98
|
assert_equal %w(lib - FAQ), yd.files
|
94
99
|
assert_equal 6, yd.options.size
|
95
|
-
assert_equal
|
100
|
+
assert_equal \
|
101
|
+
'README.rdoc',
|
96
102
|
Gemma::Options.extract(%w(--main), yd.options).argument
|
97
|
-
assert_equal
|
103
|
+
assert_equal \
|
104
|
+
'yard',
|
98
105
|
Gemma::Options.extract(%w(--output), yd.options).argument
|
99
|
-
assert_equal
|
106
|
+
assert_equal \
|
107
|
+
'a b c',
|
100
108
|
Gemma::Options.extract(%w(--title), yd.options).argument
|
101
109
|
end
|
102
110
|
end
|
@@ -115,33 +123,37 @@ class Gemma::GemmaTest < MiniTest::Test
|
|
115
123
|
Gemma::RakeTasks.new(s) do |g|
|
116
124
|
g.test.with_test_task do |tt|
|
117
125
|
assert_equal %w(lib foo test).to_set, tt.libs.to_set
|
118
|
-
assert_equal
|
126
|
+
assert_equal \
|
127
|
+
%w(test/test_a.rb test/test_b.rb).to_set,
|
119
128
|
tt.file_list.to_a.to_set
|
120
129
|
end
|
121
130
|
end
|
122
131
|
end
|
123
132
|
|
124
133
|
def test_conventions_good_gem_name
|
125
|
-
assert Gemma::Conventions.good_gem_name?(
|
126
|
-
assert Gemma::Conventions.good_gem_name?(
|
127
|
-
assert Gemma::Conventions.good_gem_name?(
|
128
|
-
assert Gemma::Conventions.good_gem_name?(
|
129
|
-
assert Gemma::Conventions.good_gem_name?(
|
130
|
-
assert !Gemma::Conventions.good_gem_name?(
|
131
|
-
assert !Gemma::Conventions.good_gem_name?(
|
132
|
-
assert !Gemma::Conventions.good_gem_name?(
|
133
|
-
assert !Gemma::Conventions.good_gem_name?(
|
134
|
+
assert Gemma::Conventions.good_gem_name?('my_gem_name')
|
135
|
+
assert Gemma::Conventions.good_gem_name?('my-gem-name')
|
136
|
+
assert Gemma::Conventions.good_gem_name?('foo')
|
137
|
+
assert Gemma::Conventions.good_gem_name?('foo1')
|
138
|
+
assert Gemma::Conventions.good_gem_name?('foo_4_bar')
|
139
|
+
assert !Gemma::Conventions.good_gem_name?('Foo')
|
140
|
+
assert !Gemma::Conventions.good_gem_name?('FooBar')
|
141
|
+
assert !Gemma::Conventions.good_gem_name?('Foo_Bar')
|
142
|
+
assert !Gemma::Conventions.good_gem_name?('Foo-Bar')
|
134
143
|
end
|
135
144
|
|
136
145
|
def test_conventions_gem_name_to_module_name
|
137
|
-
assert_equal
|
138
|
-
Gemma::Conventions.gem_name_to_module_name(
|
139
|
-
assert_equal
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
Gemma::Conventions.gem_name_to_module_name(
|
146
|
+
assert_equal \
|
147
|
+
'MyGem', Gemma::Conventions.gem_name_to_module_name('my_gem')
|
148
|
+
assert_equal \
|
149
|
+
'MyGem3',
|
150
|
+
Gemma::Conventions.gem_name_to_module_name('my_gem3')
|
151
|
+
assert_equal \
|
152
|
+
'A4B',
|
153
|
+
Gemma::Conventions.gem_name_to_module_name('a_4_b')
|
154
|
+
assert_equal \
|
155
|
+
'A4b',
|
156
|
+
Gemma::Conventions.gem_name_to_module_name('a4b')
|
145
157
|
end
|
146
158
|
|
147
159
|
#
|
@@ -157,9 +169,8 @@ class Gemma::GemmaTest < MiniTest::Test
|
|
157
169
|
def test_plugin_abstract
|
158
170
|
s = Gem::Specification.new
|
159
171
|
plugin = Gemma::RakeTasks::Plugin.new(s)
|
160
|
-
assert_raises(NotImplementedError)
|
172
|
+
assert_raises(NotImplementedError) do
|
161
173
|
plugin.create_rake_tasks # abstract method
|
162
|
-
|
174
|
+
end
|
163
175
|
end
|
164
176
|
end
|
165
|
-
|
data/test/gemma/options_test.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'gemma/test_helper'
|
2
3
|
|
3
4
|
class OptionsTest < MiniTest::Test
|
@@ -5,7 +6,8 @@ class OptionsTest < MiniTest::Test
|
|
5
6
|
|
6
7
|
def test_empty
|
7
8
|
# empty input
|
8
|
-
assert_equal
|
9
|
+
assert_equal \
|
10
|
+
Options::ExtractResult.new(nil, []),
|
9
11
|
Options.extract(%w(--a), [])
|
10
12
|
end
|
11
13
|
|
@@ -13,87 +15,108 @@ class OptionsTest < MiniTest::Test
|
|
13
15
|
input = %w(--a av --b --c=cv)
|
14
16
|
|
15
17
|
# option a has an argument
|
16
|
-
assert_equal
|
18
|
+
assert_equal \
|
19
|
+
Options::ExtractResult.new('av', %w(--b --c=cv)),
|
17
20
|
Options.extract(%w(--a), input)
|
18
21
|
|
19
22
|
# option b has no argument; result is ''
|
20
|
-
assert_equal
|
23
|
+
assert_equal \
|
24
|
+
Options::ExtractResult.new('', %w(--a av --c=cv)),
|
21
25
|
Options.extract(%w(--b), input)
|
22
26
|
|
23
27
|
# option c also has argument
|
24
|
-
assert_equal
|
28
|
+
assert_equal \
|
29
|
+
Options::ExtractResult.new('cv', %w(--a av --b)),
|
25
30
|
Options.extract(%w(--c), input)
|
26
31
|
|
27
32
|
# there is no option d; result is nil
|
28
|
-
assert_equal
|
33
|
+
assert_equal \
|
34
|
+
Options::ExtractResult.new(nil, input),
|
29
35
|
Options.extract(%w(--d), input)
|
30
36
|
end
|
31
37
|
|
32
38
|
def test_terminator
|
33
39
|
# just the -- terminator
|
34
|
-
assert_equal
|
40
|
+
assert_equal \
|
41
|
+
Options::ExtractResult.new(nil, ['--']),
|
35
42
|
Options.extract(%w(--a), ['--'])
|
36
43
|
|
37
44
|
# should keep content before and after the -- terminator
|
38
|
-
assert_equal
|
45
|
+
assert_equal \
|
46
|
+
Options::ExtractResult.new(nil, %w(a -- b)),
|
39
47
|
Options.extract(%w(--a), %w(a -- b))
|
40
48
|
end
|
41
49
|
|
42
50
|
def test_terminator_2
|
43
|
-
input = %w(foo --a av
|
51
|
+
input = %w(foo --a av -- --b bv)
|
44
52
|
|
45
53
|
# should not be able to find options after the -- terminator
|
46
|
-
assert_equal
|
54
|
+
assert_equal \
|
55
|
+
Options::ExtractResult.new('av', %w(foo -- --b bv)),
|
47
56
|
Options.extract(%w(--a), input)
|
48
|
-
assert_equal
|
57
|
+
assert_equal \
|
58
|
+
Options::ExtractResult.new(nil, input),
|
49
59
|
Options.extract(%w(--b), input)
|
50
|
-
assert_equal
|
60
|
+
assert_equal \
|
61
|
+
Options::ExtractResult.new('', %w(-- --b)),
|
51
62
|
Options.extract(%w(--a), %w(--a -- --b))
|
52
|
-
assert_equal
|
63
|
+
assert_equal \
|
64
|
+
Options::ExtractResult.new(nil, %w(--a -- --b)),
|
53
65
|
Options.extract(%w(--b), %w(--a -- --b))
|
54
66
|
end
|
55
67
|
|
56
68
|
def test_short_form
|
57
69
|
# should be able to find -a but not -b
|
58
|
-
input = %w(foo -a av
|
59
|
-
assert_equal
|
70
|
+
input = %w(foo -a av -- -b bv)
|
71
|
+
assert_equal \
|
72
|
+
Options::ExtractResult.new('av', %w(foo -- -b bv)),
|
60
73
|
Options.extract(%w(-a), input)
|
61
|
-
assert_equal
|
74
|
+
assert_equal \
|
75
|
+
Options::ExtractResult.new(nil, input),
|
62
76
|
Options.extract(%w(-b), input)
|
63
77
|
|
64
78
|
# the -aav and -b bv forms
|
65
79
|
input = %w(-aav -b bv)
|
66
|
-
assert_equal
|
80
|
+
assert_equal \
|
81
|
+
Options::ExtractResult.new('av', %w(-b bv)),
|
67
82
|
Options.extract(%w(-a), input)
|
68
|
-
assert_equal
|
83
|
+
assert_equal \
|
84
|
+
Options::ExtractResult.new('bv', %w(-aav)),
|
69
85
|
Options.extract(%w(-b), input)
|
70
86
|
|
71
87
|
# short form with no argument
|
72
|
-
assert_equal
|
88
|
+
assert_equal \
|
89
|
+
Options::ExtractResult.new('', %w(-a av)),
|
73
90
|
Options.extract(%w(-b), %w(-a av -b))
|
74
91
|
|
75
92
|
# missing short form argument
|
76
|
-
assert_equal
|
93
|
+
assert_equal \
|
94
|
+
Options::ExtractResult.new(nil, %w(-a av -b foo bar.txt)),
|
77
95
|
Options.extract(%w(-c), %w(-a av -b foo bar.txt))
|
78
96
|
end
|
79
97
|
|
80
98
|
def test_multiple_options
|
81
99
|
# single -a means we pick up a1
|
82
|
-
assert_equal
|
100
|
+
assert_equal \
|
101
|
+
Options::ExtractResult.new('a1', []),
|
83
102
|
Options.extract(%w(-a), %w(-a a1))
|
84
103
|
|
85
104
|
# the second -a means that we pick up a2
|
86
|
-
assert_equal
|
105
|
+
assert_equal \
|
106
|
+
Options::ExtractResult.new('a2', []),
|
87
107
|
Options.extract(%w(-a), %w(-a a1 -a a2))
|
88
|
-
assert_equal
|
108
|
+
assert_equal \
|
109
|
+
Options::ExtractResult.new('a2', %w(hi -bfoo)),
|
89
110
|
Options.extract(%w(-a), %w(hi -a a1 -a a2 -bfoo))
|
90
111
|
|
91
112
|
# mixing long and short forms doesn't affect this
|
92
|
-
assert_equal
|
113
|
+
assert_equal \
|
114
|
+
Options::ExtractResult.new('a2', []),
|
93
115
|
Options.extract(%w(-a --a), %w(-a a1 --a a2))
|
94
116
|
|
95
117
|
# a duplicate option after the -- terminator makes no difference
|
96
|
-
assert_equal
|
118
|
+
assert_equal \
|
119
|
+
Options::ExtractResult.new('a1', %w(-- -aa2)),
|
97
120
|
Options.extract(%w(-a), %w(-a a1 -- -aa2))
|
98
121
|
end
|
99
122
|
end
|