gli 2.19.1 → 2.21.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.circleci/config.yml +28 -0
- data/.gitignore +1 -3
- data/CONTRIBUTING.md +1 -3
- data/Gemfile +0 -6
- data/README.rdoc +7 -17
- data/Rakefile +22 -38
- data/bin/ci +29 -0
- data/bin/gli +25 -64
- data/bin/rake +29 -0
- data/bin/setup +5 -0
- data/exe/gli +68 -0
- data/gli.gemspec +19 -21
- data/gli.rdoc +2 -2
- data/lib/gli/app_support.rb +3 -1
- data/lib/gli/command_support.rb +2 -6
- data/lib/gli/commands/help_modules/command_help_format.rb +1 -1
- data/lib/gli/commands/help_modules/global_help_format.rb +1 -1
- data/lib/gli/commands/scaffold.rb +9 -93
- data/lib/gli/dsl.rb +5 -0
- data/lib/gli/gli_option_parser.rb +19 -4
- data/lib/gli/options.rb +2 -2
- data/lib/gli/version.rb +1 -1
- data/object-model.dot +29 -0
- data/object-model.png +0 -0
- data/test/apps/todo/Gemfile +1 -1
- data/test/apps/todo/bin/todo +1 -1
- data/test/integration/gli_cli_test.rb +69 -0
- data/test/integration/gli_powered_app_test.rb +52 -0
- data/test/integration/scaffold_test.rb +30 -0
- data/test/integration/test_helper.rb +52 -0
- data/test/{tc_command_finder.rb → unit/command_finder_test.rb} +6 -6
- data/test/{tc_command.rb → unit/command_test.rb} +4 -4
- data/test/unit/compound_command_test.rb +17 -0
- data/test/{tc_doc.rb → unit/doc_test.rb} +38 -51
- data/test/{tc_flag.rb → unit/flag_test.rb} +19 -25
- data/test/{tc_gli.rb → unit/gli_test.rb} +58 -47
- data/test/{tc_help.rb → unit/help_test.rb} +48 -107
- data/test/{init_simplecov.rb → unit/init_simplecov.rb} +0 -0
- data/test/{tc_options.rb → unit/options_test.rb} +4 -4
- data/test/unit/subcommand_parsing_test.rb +263 -0
- data/test/unit/subcommands_test.rb +245 -0
- data/test/{fake_std_out.rb → unit/support/fake_std_out.rb} +0 -0
- data/test/{config.yaml → unit/support/gli_test_config.yml} +0 -0
- data/test/unit/switch_test.rb +49 -0
- data/test/{tc_terminal.rb → unit/terminal_test.rb} +4 -3
- data/test/unit/test_helper.rb +13 -0
- data/test/unit/verbatim_wrapper_test.rb +24 -0
- metadata +73 -140
- data/.ruby-gemset +0 -1
- data/.ruby-version +0 -1
- data/.travis.yml +0 -11
- data/ObjectModel.graffle +0 -1191
- data/bin/report_on_rake_results +0 -10
- data/bin/test_all_rubies.sh +0 -6
- data/features/gli_executable.feature +0 -90
- data/features/gli_init.feature +0 -236
- data/features/step_definitions/gli_executable_steps.rb +0 -18
- data/features/step_definitions/gli_init_steps.rb +0 -11
- data/features/step_definitions/todo_steps.rb +0 -100
- data/features/support/env.rb +0 -54
- data/features/support/hooks.rb +0 -5
- data/features/todo.feature +0 -579
- data/features/todo_legacy.feature +0 -130
- data/test/option_test_helper.rb +0 -13
- data/test/tc_compound_command.rb +0 -22
- data/test/tc_subcommand_parsing.rb +0 -280
- data/test/tc_subcommands.rb +0 -259
- data/test/tc_switch.rb +0 -55
- data/test/tc_verbatim_wrapper.rb +0 -36
- data/test/test_helper.rb +0 -21
@@ -70,10 +70,10 @@ spec = Gem::Specification.new do |s|
|
|
70
70
|
s.rdoc_options << '--title' << '#{project_name}' << '--main' << 'README.rdoc' << '-ri'
|
71
71
|
s.bindir = 'bin'
|
72
72
|
s.executables << '#{project_name}'
|
73
|
-
s.add_development_dependency('rake')
|
74
|
-
s.add_development_dependency('rdoc')
|
75
|
-
s.add_development_dependency('
|
76
|
-
s.add_runtime_dependency('gli','#{GLI::VERSION}')
|
73
|
+
s.add_development_dependency('rake','~> 0.9.2')
|
74
|
+
s.add_development_dependency('rdoc', '~> 4.3')
|
75
|
+
s.add_development_dependency('minitest', '~> 5.14')
|
76
|
+
s.add_runtime_dependency('gli','~> #{GLI::VERSION}')
|
77
77
|
end
|
78
78
|
EOS
|
79
79
|
end
|
@@ -114,12 +114,6 @@ require 'rubygems'
|
|
114
114
|
require 'rubygems/package_task'
|
115
115
|
require 'rdoc/task'
|
116
116
|
EOS
|
117
|
-
if create_test_dir
|
118
|
-
file.puts <<EOS
|
119
|
-
require 'cucumber'
|
120
|
-
require 'cucumber/rake/task'
|
121
|
-
EOS
|
122
|
-
end
|
123
117
|
file.puts <<EOS
|
124
118
|
Rake::RDocTask.new do |rd|
|
125
119
|
rd.main = "README.rdoc"
|
@@ -134,44 +128,19 @@ end
|
|
134
128
|
EOS
|
135
129
|
if create_test_dir
|
136
130
|
file.puts <<EOS
|
137
|
-
CUKE_RESULTS = 'results.html'
|
138
|
-
CLEAN << CUKE_RESULTS
|
139
|
-
desc 'Run features'
|
140
|
-
Cucumber::Rake::Task.new(:features) do |t|
|
141
|
-
opts = "features --format html -o \#{CUKE_RESULTS} --format progress -x"
|
142
|
-
opts += " --tags \#{ENV['TAGS']}" if ENV['TAGS']
|
143
|
-
t.cucumber_opts = opts
|
144
|
-
t.fork = false
|
145
|
-
end
|
146
|
-
|
147
|
-
desc 'Run features tagged as work-in-progress (@wip)'
|
148
|
-
Cucumber::Rake::Task.new('features:wip') do |t|
|
149
|
-
tag_opts = ' --tags ~@pending'
|
150
|
-
tag_opts = ' --tags @wip'
|
151
|
-
t.cucumber_opts = "features --format html -o \#{CUKE_RESULTS} --format pretty -x -s\#{tag_opts}"
|
152
|
-
t.fork = false
|
153
|
-
end
|
154
|
-
|
155
|
-
task :cucumber => :features
|
156
|
-
task 'cucumber:wip' => 'features:wip'
|
157
|
-
task :wip => 'features:wip'
|
158
|
-
EOS
|
159
|
-
end
|
160
|
-
if create_test_dir
|
161
|
-
file.puts <<EOS
|
162
131
|
require 'rake/testtask'
|
163
132
|
Rake::TestTask.new do |t|
|
164
133
|
t.libs << "test"
|
165
134
|
t.test_files = FileList['test/*_test.rb']
|
166
135
|
end
|
167
136
|
|
168
|
-
task :default =>
|
137
|
+
task :default => :test
|
169
138
|
EOS
|
170
139
|
File.open("#{root_dir}/#{project_name}/test/default_test.rb",'w') do |test_file|
|
171
140
|
test_file.puts <<EOS
|
172
|
-
|
141
|
+
require_relative "test_helper"
|
173
142
|
|
174
|
-
class DefaultTest < Test
|
143
|
+
class DefaultTest < Minitest::Test
|
175
144
|
|
176
145
|
def setup
|
177
146
|
end
|
@@ -188,15 +157,10 @@ EOS
|
|
188
157
|
puts "Created #{root_dir}/#{project_name}/test/default_test.rb"
|
189
158
|
File.open("#{root_dir}/#{project_name}/test/test_helper.rb",'w') do |test_file|
|
190
159
|
test_file.puts <<EOS
|
191
|
-
require
|
160
|
+
require "minitest/autorun"
|
192
161
|
|
193
162
|
# Add test libraries you want to use here, e.g. mocha
|
194
|
-
|
195
|
-
class Test::Unit::TestCase
|
196
|
-
|
197
|
-
# Add global extensions to the test case class here
|
198
|
-
|
199
|
-
end
|
163
|
+
# Add helper classes or methods here, too
|
200
164
|
EOS
|
201
165
|
end
|
202
166
|
puts "Created #{root_dir}/#{project_name}/test/test_helper.rb"
|
@@ -210,54 +174,6 @@ EOS
|
|
210
174
|
bundler_file.puts "gemspec"
|
211
175
|
end
|
212
176
|
puts "Created #{root_dir}/#{project_name}/Gemfile"
|
213
|
-
if create_test_dir
|
214
|
-
features_dir = File.join(root_dir,project_name,'features')
|
215
|
-
FileUtils.mkdir features_dir
|
216
|
-
FileUtils.mkdir File.join(features_dir,"step_definitions")
|
217
|
-
FileUtils.mkdir File.join(features_dir,"support")
|
218
|
-
File.open(File.join(features_dir,"#{project_name}.feature"),'w') do |file|
|
219
|
-
file.puts <<EOS
|
220
|
-
Feature: My bootstrapped app kinda works
|
221
|
-
In order to get going on coding my awesome app
|
222
|
-
I want to have aruba and cucumber setup
|
223
|
-
So I don't have to do it myself
|
224
|
-
|
225
|
-
Scenario: App just runs
|
226
|
-
When I get help for "#{project_name}"
|
227
|
-
Then the exit status should be 0
|
228
|
-
EOS
|
229
|
-
end
|
230
|
-
File.open(File.join(features_dir,"step_definitions","#{project_name}_steps.rb"),'w') do |file|
|
231
|
-
file.puts <<EOS
|
232
|
-
When /^I get help for "([^"]*)"$/ do |app_name|
|
233
|
-
@app_name = app_name
|
234
|
-
step %(I run `\#{app_name} help`)
|
235
|
-
end
|
236
|
-
|
237
|
-
# Add more step definitions here
|
238
|
-
EOS
|
239
|
-
end
|
240
|
-
File.open(File.join(features_dir,"support","env.rb"),'w') do |file|
|
241
|
-
file.puts <<EOS
|
242
|
-
require 'aruba/cucumber'
|
243
|
-
|
244
|
-
ENV['PATH'] = "\#{File.expand_path(File.dirname(__FILE__) + '/../../bin')}\#{File::PATH_SEPARATOR}\#{ENV['PATH']}"
|
245
|
-
LIB_DIR = File.join(File.expand_path(File.dirname(__FILE__)),'..','..','lib')
|
246
|
-
|
247
|
-
Before do
|
248
|
-
# Using "announce" causes massive warnings on 1.9.2
|
249
|
-
@puts = true
|
250
|
-
@original_rubylib = ENV['RUBYLIB']
|
251
|
-
ENV['RUBYLIB'] = LIB_DIR + File::PATH_SEPARATOR + ENV['RUBYLIB'].to_s
|
252
|
-
end
|
253
|
-
|
254
|
-
After do
|
255
|
-
ENV['RUBYLIB'] = @original_rubylib
|
256
|
-
end
|
257
|
-
EOS
|
258
|
-
end
|
259
|
-
puts "Created #{features_dir}"
|
260
|
-
end
|
261
177
|
end
|
262
178
|
|
263
179
|
def self.mk_binfile(root_dir,create_ext_dir,force,dry_run,project_name,commands)
|
data/lib/gli/dsl.rb
CHANGED
@@ -201,9 +201,14 @@ module GLI
|
|
201
201
|
end
|
202
202
|
clear_nexts
|
203
203
|
@next_arguments = []
|
204
|
+
command
|
204
205
|
end
|
205
206
|
alias :c :command
|
206
207
|
|
208
|
+
def command_missing(&block)
|
209
|
+
@command_missing_block = block
|
210
|
+
end
|
211
|
+
|
207
212
|
def flags_declaration_order # :nodoc:
|
208
213
|
@flags_declaration_order ||= []
|
209
214
|
end
|
@@ -16,7 +16,7 @@ module GLI
|
|
16
16
|
command_finder = CommandFinder.new(commands,
|
17
17
|
:default_command => (options[:default_command] || :help),
|
18
18
|
:autocomplete => options[:autocomplete])
|
19
|
-
@global_option_parser = GlobalOptionParser.new(OptionParserFactory.new(flags,switches,accepts),command_finder,flags)
|
19
|
+
@global_option_parser = GlobalOptionParser.new(OptionParserFactory.new(flags,switches,accepts),command_finder,flags, :command_missing_block => options[:command_missing_block])
|
20
20
|
@accepts = accepts
|
21
21
|
if options[:argument_handling_strategy] == :strict && options[:subcommand_option_handling_strategy] != :normal
|
22
22
|
raise ArgumentError, "To use strict argument handling, you must enable normal subcommand_option_handling, e.g. subcommand_option_handling :normal"
|
@@ -36,10 +36,11 @@ module GLI
|
|
36
36
|
private
|
37
37
|
|
38
38
|
class GlobalOptionParser
|
39
|
-
def initialize(option_parser_factory,command_finder,flags)
|
39
|
+
def initialize(option_parser_factory,command_finder,flags,options={})
|
40
40
|
@option_parser_factory = option_parser_factory
|
41
41
|
@command_finder = command_finder
|
42
42
|
@flags = flags
|
43
|
+
@options = options
|
43
44
|
end
|
44
45
|
|
45
46
|
def parse!(parsing_result)
|
@@ -50,7 +51,21 @@ module GLI
|
|
50
51
|
else
|
51
52
|
parsing_result.arguments.shift
|
52
53
|
end
|
53
|
-
parsing_result.command =
|
54
|
+
parsing_result.command = begin
|
55
|
+
@command_finder.find_command(command_name)
|
56
|
+
rescue UnknownCommand => e
|
57
|
+
raise e unless @options[:command_missing_block]
|
58
|
+
command = @options[:command_missing_block].call(command_name.to_sym,parsing_result.global_options)
|
59
|
+
if command
|
60
|
+
unless command.is_a?(Command)
|
61
|
+
raise UnknownCommand.new("Expected the `command_missing` block to return a GLI::Command object, got a #{command.class.name} instead.")
|
62
|
+
end
|
63
|
+
else
|
64
|
+
raise e
|
65
|
+
end
|
66
|
+
command
|
67
|
+
end
|
68
|
+
|
54
69
|
unless command_name == 'help'
|
55
70
|
verify_required_options!(@flags, parsing_result.command, parsing_result.global_options)
|
56
71
|
end
|
@@ -143,7 +158,7 @@ module GLI
|
|
143
158
|
break
|
144
159
|
rescue UnknownCommand
|
145
160
|
arguments.unshift(next_command_name)
|
146
|
-
# Although command finder could
|
161
|
+
# Although command finder could certainly know if it should use
|
147
162
|
# the default command, it has no way to put the "unknown command"
|
148
163
|
# back into the argument stack. UGH.
|
149
164
|
unless command.get_default_command.nil?
|
data/lib/gli/options.rb
CHANGED
@@ -7,12 +7,12 @@ module GLI
|
|
7
7
|
|
8
8
|
# Return the value of an attribute
|
9
9
|
def[](k)
|
10
|
-
|
10
|
+
self.send(k.to_sym)
|
11
11
|
end
|
12
12
|
|
13
13
|
# Set the value of an attribute
|
14
14
|
def[]=(k, v)
|
15
|
-
|
15
|
+
self.send("#{k.to_sym}=",v)
|
16
16
|
end
|
17
17
|
|
18
18
|
def map(&block)
|
data/lib/gli/version.rb
CHANGED
data/object-model.dot
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
digraph G {
|
2
|
+
|
3
|
+
rankdir="BT"
|
4
|
+
nodesep=0.5
|
5
|
+
|
6
|
+
node[shape=record fontname=courier fontsize=18]
|
7
|
+
edge[fontname=avenir fontsize=12]
|
8
|
+
|
9
|
+
CommandLineToken [ label="{ CommandLineToken | #name\l | #description\l | #long_description\l | #aliases\l}"]
|
10
|
+
CommandLineOption [ label="{ CommandLineOption | #default_value \l }"]
|
11
|
+
DSL
|
12
|
+
Command
|
13
|
+
Flag [ label="{ Flag | #argument_name\l }"]
|
14
|
+
Switch
|
15
|
+
App
|
16
|
+
TopLevel [ label="top level?" shape=diamond fontname=avenir fontsize=12]
|
17
|
+
|
18
|
+
Command -> DSL [ arrowhead=oarrow label=" includes" minlen=3]
|
19
|
+
Command -> CommandLineToken [ arrowhead=oarrow label="inherits"]
|
20
|
+
CommandLineOption -> CommandLineToken [ arrowhead=oarrow label="inherits"]
|
21
|
+
Flag -> CommandLineOption [ arrowhead=oarrow label="inherits"]
|
22
|
+
Switch -> CommandLineOption [ arrowhead=oarrow label="inherits"]
|
23
|
+
Command -> TopLevel [ arrowhead=none label="parent" style=dotted]
|
24
|
+
TopLevel -> App [ arrowhead=odiamond label="YES" style=dotted ]
|
25
|
+
TopLevel -> Command [ arrowhead=odiamond label="NO" style=dotted ]
|
26
|
+
CommandLineOption -> Command [ arrowhead=odiamond style=dotted label="associated_command"]
|
27
|
+
|
28
|
+
{ rank=same; DSL; App }
|
29
|
+
}
|
data/object-model.png
ADDED
Binary file
|
data/test/apps/todo/Gemfile
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
source
|
1
|
+
source 'https://rubygems.org'
|
2
2
|
gemspec
|
data/test/apps/todo/bin/todo
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
3
|
# These would not be in a real GLI app; we do this so we can easily run this on the command line
|
4
|
-
$: << File.expand_path(File.join(File.dirname(__FILE__),'..','..','..','lib'))
|
4
|
+
$: << File.expand_path(File.join(File.dirname(__FILE__),'..','..','..','..','lib'))
|
5
5
|
$: << File.expand_path(File.join(File.dirname(__FILE__),'..','lib'))
|
6
6
|
|
7
7
|
require 'gli'
|
@@ -0,0 +1,69 @@
|
|
1
|
+
require_relative "test_helper"
|
2
|
+
require "open3"
|
3
|
+
|
4
|
+
class GLICLITest < MiniTest::Test
|
5
|
+
include TestHelper
|
6
|
+
|
7
|
+
class AppHelp < GLICLITest
|
8
|
+
def test_running_with_no_options_produces_help
|
9
|
+
out = run_gli
|
10
|
+
assert_output_looks_like_help out
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_running_with_help_command_produces_help
|
14
|
+
out = run_gli("help")
|
15
|
+
assert_output_looks_like_help out
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_running_with_help_switch_produces_help
|
19
|
+
out = run_gli("--help")
|
20
|
+
assert_output_looks_like_help out
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def assert_output_looks_like_help(out)
|
26
|
+
assert_match /gli - create scaffolding for a GLI-powered application/,out
|
27
|
+
assert_match /SYNOPSIS/,out
|
28
|
+
assert_match /GLOBAL OPTIONS/,out
|
29
|
+
assert_match /COMMANDS/,out
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
class Scaffolding < GLICLITest
|
35
|
+
def test_help_on_scaffold_command
|
36
|
+
out = run_gli("help scaffold")
|
37
|
+
assert_output_looks_like_help(out)
|
38
|
+
end
|
39
|
+
def test_help_on_scaffold_command_as_init
|
40
|
+
out = run_gli("help init")
|
41
|
+
assert_output_looks_like_help(out)
|
42
|
+
end
|
43
|
+
|
44
|
+
private
|
45
|
+
|
46
|
+
def assert_output_looks_like_help(out)
|
47
|
+
assert_match /init - Create a new GLI-based project/,out
|
48
|
+
assert_match /SYNOPSIS/,out
|
49
|
+
assert_match /COMMAND OPTIONS/,out
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
private
|
54
|
+
|
55
|
+
def run_gli(args="", return_err_and_status: false, expect_failure: false)
|
56
|
+
command_line_invocation = "bin/gli #{args}"
|
57
|
+
stdout_string, stderr_string, status = Open3.capture3(command_line_invocation)
|
58
|
+
if expect_failure
|
59
|
+
refute_equal 0,status.exitstatus,"Expected failure for '#{command_line_invocation}' but it succeeded"
|
60
|
+
else
|
61
|
+
assert_equal 0,status.exitstatus,"Expected success for '#{command_line_invocation}' but it failed"
|
62
|
+
end
|
63
|
+
if return_err_and_status
|
64
|
+
[ stdout_string, stderr_string, status ]
|
65
|
+
else
|
66
|
+
stdout_string
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require_relative "test_helper"
|
2
|
+
require "open3"
|
3
|
+
|
4
|
+
class GLIPoweredAppTest < MiniTest::Test
|
5
|
+
include TestHelper
|
6
|
+
|
7
|
+
def teardown
|
8
|
+
FileUtils.rm_f("todo.rdoc")
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_help_works
|
12
|
+
out = run_app("help")
|
13
|
+
assert_top_level_help(out)
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_unknown_command_exits_nonzero
|
17
|
+
out, err, status = run_app("asdfasdfasdf", expect_failure: true, return_err_and_status: true)
|
18
|
+
assert_match /Unknown command 'asdfasdfasdf'/,err
|
19
|
+
assert_equal 64, status.exitstatus
|
20
|
+
assert_top_level_help(out)
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_unknown_switch_exits_nonzero
|
24
|
+
out, err, status = run_app("list --foo", expect_failure: true, return_err_and_status: true)
|
25
|
+
assert_match /Unknown option \-\-foo/,err
|
26
|
+
assert_equal 64, status.exitstatus
|
27
|
+
assert_match /COMMAND OPTIONS/, out
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_missing_args_exits_nonzero
|
31
|
+
out, err, status = run_app("list", expect_failure: true, return_err_and_status: true)
|
32
|
+
assert_match /required_flag is required, required_flag2 is required/,err
|
33
|
+
assert_equal 64, status.exitstatus
|
34
|
+
assert_match /COMMAND OPTIONS/, out
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_doc_generation
|
38
|
+
out, err, status = run_app("_doc", return_err_and_status: true)
|
39
|
+
assert File.exists?("todo.rdoc")
|
40
|
+
end
|
41
|
+
|
42
|
+
private
|
43
|
+
def assert_top_level_help(out)
|
44
|
+
assert_match /SYNOPSIS/, out
|
45
|
+
assert_match /GLOBAL OPTIONS/, out
|
46
|
+
assert_match /COMMANDS/, out
|
47
|
+
end
|
48
|
+
|
49
|
+
def run_app(args="", return_err_and_status: false, expect_failure: false)
|
50
|
+
run_command("test/apps/todo/bin/todo",args,return_err_and_status:return_err_and_status,expect_failure:expect_failure)
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require_relative "test_helper"
|
2
|
+
require "open3"
|
3
|
+
|
4
|
+
class ScaffoldCommandTest < MiniTest::Test
|
5
|
+
include TestHelper
|
6
|
+
|
7
|
+
def test_scaffolded_app_has_reasonable_setup
|
8
|
+
FileUtils.rm_rf "scaffold_test"
|
9
|
+
run_gli("init scaffold_test")
|
10
|
+
assert Dir.exist? "scaffold_test"
|
11
|
+
FileUtils.chdir "scaffold_test" do
|
12
|
+
run_command("bundle install", "", return_err_and_status: false, expect_failure: false)
|
13
|
+
|
14
|
+
scaffold_lib = "lib:../lib"
|
15
|
+
|
16
|
+
# help works
|
17
|
+
out = run_command("bin/scaffold_test","--help", return_err_and_status: false, expect_failure: false, rubylib: scaffold_lib)
|
18
|
+
assert_match /SYNOPSIS/,out
|
19
|
+
assert_match /GLOBAL OPTIONS/,out
|
20
|
+
assert_match /COMMANDS/,out
|
21
|
+
|
22
|
+
# can run unit tests
|
23
|
+
out = run_command("bundle exec ","rake test", return_err_and_status: false, expect_failure: false, rubylib: scaffold_lib)
|
24
|
+
assert_match /0 failures/,out
|
25
|
+
assert_match /0 errors/,out
|
26
|
+
assert_match /0 skips/,out
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require "minitest/autorun"
|
2
|
+
require "pathname"
|
3
|
+
require "fileutils"
|
4
|
+
|
5
|
+
# Copied from https://github.com/splattael/minitest-around
|
6
|
+
# so as to avoid an explicit dependency
|
7
|
+
Minitest::Test.class_eval do
|
8
|
+
alias_method :run_without_around, :run
|
9
|
+
def run(*args)
|
10
|
+
if defined?(around)
|
11
|
+
result = nil
|
12
|
+
around { result = run_without_around(*args) }
|
13
|
+
result
|
14
|
+
else
|
15
|
+
run_without_around(*args)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
module TestHelper
|
21
|
+
def around(&block)
|
22
|
+
Bundler.with_original_env do
|
23
|
+
root = Pathname(__FILE__).dirname / ".." / ".."
|
24
|
+
FileUtils.chdir root do
|
25
|
+
block.()
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def run_gli(args="", return_err_and_status: false, expect_failure: false)
|
31
|
+
run_command("bin/gli",args,return_err_and_status:return_err_and_status,expect_failure:expect_failure)
|
32
|
+
end
|
33
|
+
|
34
|
+
def run_command(command,args,return_err_and_status:,expect_failure:,rubylib:nil)
|
35
|
+
command_line_invocation = "#{command} #{args}"
|
36
|
+
env = {}
|
37
|
+
if !rubylib.nil?
|
38
|
+
env["RUBYLIB"] = rubylib
|
39
|
+
end
|
40
|
+
stdout_string, stderr_string, status = Open3.capture3(env,command_line_invocation)
|
41
|
+
if expect_failure
|
42
|
+
refute_equal 0,status.exitstatus,"Expected failure for '#{command_line_invocation}' but it succeeded"
|
43
|
+
else
|
44
|
+
assert_equal 0,status.exitstatus,"Expected success for '#{command_line_invocation}' but it failed:\n#{stdout_string}\n\n#{stderr_string}\n\n"
|
45
|
+
end
|
46
|
+
if return_err_and_status
|
47
|
+
[ stdout_string, stderr_string, status ]
|
48
|
+
else
|
49
|
+
stdout_string
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -1,6 +1,6 @@
|
|
1
|
-
|
1
|
+
require_relative "test_helper"
|
2
2
|
|
3
|
-
class
|
3
|
+
class CommandFinderTest < MiniTest::Test
|
4
4
|
include TestHelper
|
5
5
|
|
6
6
|
def setup
|
@@ -14,13 +14,13 @@ class TC_testCommandFinder < Clean::Test::TestCase
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def test_unknown_command_name
|
17
|
-
|
17
|
+
assert_raises(GLI::UnknownCommand) do
|
18
18
|
GLI::CommandFinder.new(@app.commands, :default_command => :status).find_command(:unfindable_command)
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
22
22
|
def test_no_command_name_without_default
|
23
|
-
|
23
|
+
assert_raises(GLI::UnknownCommand) do
|
24
24
|
GLI::CommandFinder.new(@app.commands).find_command(nil)
|
25
25
|
end
|
26
26
|
end
|
@@ -33,7 +33,7 @@ class TC_testCommandFinder < Clean::Test::TestCase
|
|
33
33
|
end
|
34
34
|
|
35
35
|
def test_ambigous_command
|
36
|
-
|
36
|
+
assert_raises(GLI::AmbiguousCommand) do
|
37
37
|
GLI::CommandFinder.new(@app.commands, :default_command => :status).find_command(:some)
|
38
38
|
end
|
39
39
|
end
|
@@ -46,7 +46,7 @@ class TC_testCommandFinder < Clean::Test::TestCase
|
|
46
46
|
end
|
47
47
|
|
48
48
|
def test_partial_name_with_autocorrect_disabled
|
49
|
-
|
49
|
+
assert_raises(GLI::UnknownCommand) do
|
50
50
|
GLI::CommandFinder.new(@app.commands, :default_command => :status, :autocomplete => false)
|
51
51
|
.find_command(:deploy)
|
52
52
|
end
|
@@ -1,7 +1,7 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
require_relative "test_helper"
|
2
|
+
require_relative "support/fake_std_out"
|
3
3
|
|
4
|
-
class
|
4
|
+
class CommandTest < MiniTest::Test
|
5
5
|
include TestHelper
|
6
6
|
def setup
|
7
7
|
@fake_stdout = FakeStdOut.new
|
@@ -436,7 +436,7 @@ class TC_testCommand < Clean::Test::TestCase
|
|
436
436
|
private
|
437
437
|
|
438
438
|
def assert_contained(output,regexp)
|
439
|
-
|
439
|
+
refute_nil output.contained?(regexp),
|
440
440
|
"Expected output to contain #{regexp.inspect}, output was:\n#{output}"
|
441
441
|
end
|
442
442
|
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require_relative "test_helper"
|
2
|
+
|
3
|
+
class CompoundCommandFinderTest < MiniTest::Test
|
4
|
+
include TestHelper
|
5
|
+
|
6
|
+
def test_exception_for_missing_commands
|
7
|
+
@name = "new"
|
8
|
+
@unknown_name = "create"
|
9
|
+
@existing_command = OpenStruct.new(:name => @name)
|
10
|
+
@base = OpenStruct.new( :commands => { @name => @existing_command })
|
11
|
+
|
12
|
+
@code = lambda { GLI::Commands::CompoundCommand.new(@base,{:foo => [@name,@unknown_name]}) }
|
13
|
+
|
14
|
+
ex = assert_raises(RuntimeError,&@code)
|
15
|
+
assert_match /#{Regexp.escape(@unknown_name)}/,ex.message
|
16
|
+
end
|
17
|
+
end
|