gli 2.18.1 → 2.20.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/.tool-versions +1 -1
- data/Gemfile +0 -6
- data/README.rdoc +28 -18
- data/Rakefile +15 -37
- 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 -22
- data/gli.rdoc +2 -2
- data/lib/gli/command_support.rb +2 -6
- data/lib/gli/commands/help_modules/arg_name_formatter.rb +2 -2
- 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 +18 -93
- data/lib/gli/dsl.rb +1 -1
- 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} +28 -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 +61 -126
- 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 -234
- 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/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
@@ -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
|
@@ -1,5 +1,4 @@
|
|
1
|
-
|
2
|
-
require 'pp'
|
1
|
+
require_relative "test_helper"
|
3
2
|
|
4
3
|
class String
|
5
4
|
def blank?
|
@@ -19,7 +18,7 @@ class Object
|
|
19
18
|
end
|
20
19
|
end
|
21
20
|
|
22
|
-
class
|
21
|
+
class DocTest < MiniTest::Test
|
23
22
|
include TestHelper
|
24
23
|
|
25
24
|
class TestApp
|
@@ -112,42 +111,30 @@ class TC_testDoc < Clean::Test::TestCase
|
|
112
111
|
@@counter = -1 # we pre-increment so this makes 0 first
|
113
112
|
end
|
114
113
|
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
lines_expected = @string.split(/\n/)
|
127
|
-
lines_got = @listener.to_s.split(/\n/)
|
128
|
-
lines_expected.zip(lines_got).each_with_index do |(expected,got),index|
|
129
|
-
assert_equal expected,got,"At index #{index}"
|
130
|
-
end
|
131
|
-
}
|
114
|
+
def test_app_without_docs_gets_callbacks_for_each_element
|
115
|
+
setup_test_app
|
116
|
+
construct_expected_output
|
117
|
+
@documenter = GLI::Commands::Doc.new(@app)
|
118
|
+
@listener = TestListener.new
|
119
|
+
@documenter.document(@listener)
|
120
|
+
lines_expected = @string.split(/\n/)
|
121
|
+
lines_got = @listener.to_s.split(/\n/)
|
122
|
+
lines_expected.zip(lines_got).each_with_index do |(expected,got),index|
|
123
|
+
assert_equal expected,got,"At index #{index}"
|
124
|
+
end
|
132
125
|
end
|
133
126
|
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
lines_expected = @string.split(/\n/)
|
146
|
-
lines_got = TestListener.last.to_s.split(/\n/)
|
147
|
-
lines_expected.zip(lines_got).each_with_index do |(expected,got),index|
|
148
|
-
assert_equal expected,got,"At index #{index}"
|
149
|
-
end
|
150
|
-
}
|
127
|
+
def test_doc_command_works_as_GLI_command
|
128
|
+
setup_test_app
|
129
|
+
construct_expected_output
|
130
|
+
@documenter = GLI::Commands::Doc.new(@app)
|
131
|
+
@listener = TestListener.new
|
132
|
+
@documenter.execute({},{:format => "DocTest::TestListener"},[])
|
133
|
+
lines_expected = @string.split(/\n/)
|
134
|
+
lines_got = TestListener.last.to_s.split(/\n/)
|
135
|
+
lines_expected.zip(lines_got).each_with_index do |(expected,got),index|
|
136
|
+
assert_equal expected,got,"At index #{index}"
|
137
|
+
end
|
151
138
|
end
|
152
139
|
|
153
140
|
private
|
@@ -158,36 +145,36 @@ private
|
|
158
145
|
@@counter
|
159
146
|
end
|
160
147
|
|
161
|
-
def
|
148
|
+
def setup_test_app
|
162
149
|
@app = TestApp.new
|
163
150
|
@app.instance_eval do
|
164
151
|
program_desc "program desc"
|
165
152
|
program_long_desc "program long desc"
|
166
153
|
version "1.3.4"
|
167
154
|
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
155
|
+
DocTest.flag_with_everything_specified(self)
|
156
|
+
DocTest.flag_with_everything_omitted(self)
|
157
|
+
DocTest.switch_with_everything_specified(self)
|
158
|
+
DocTest.switch_with_everything_omitted(self)
|
172
159
|
|
173
160
|
desc "command desc"
|
174
161
|
long_desc "command long desc"
|
175
162
|
arg_name "cmd_arg_name"
|
176
163
|
command [:command1,:com1] do |c|
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
164
|
+
DocTest.flag_with_everything_specified(c)
|
165
|
+
DocTest.flag_with_everything_omitted(c)
|
166
|
+
DocTest.switch_with_everything_specified(c)
|
167
|
+
DocTest.switch_with_everything_omitted(c)
|
181
168
|
|
182
169
|
c.desc "subcommand desc"
|
183
170
|
c.long_desc "subcommand long desc"
|
184
171
|
c.arg_name "subcmd_arg_name"
|
185
172
|
c.action { |g,o,a| }
|
186
173
|
c.command [:sub,:subcommand] do |sub|
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
174
|
+
DocTest.flag_with_everything_specified(sub,:subflag)
|
175
|
+
DocTest.flag_with_everything_omitted(sub,:subflag2)
|
176
|
+
DocTest.switch_with_everything_specified(sub,:subswitch)
|
177
|
+
DocTest.switch_with_everything_omitted(sub,:subswitch2)
|
191
178
|
sub.action { |g,o,a| }
|
192
179
|
end
|
193
180
|
c.command [:default] do |sub|
|
@@ -227,7 +214,7 @@ private
|
|
227
214
|
def self.switch_with_everything_omitted(on,name=[:S,:switch2])
|
228
215
|
on.switch name
|
229
216
|
end
|
230
|
-
def
|
217
|
+
def construct_expected_output
|
231
218
|
# Oh yeah. Creating a string representing the structure of the calls.
|
232
219
|
@string =<<EOS
|
233
220
|
BEGIN
|
@@ -1,39 +1,36 @@
|
|
1
|
-
|
1
|
+
require_relative "test_helper"
|
2
2
|
|
3
|
-
class
|
3
|
+
class FlagTest < MiniTest::Test
|
4
4
|
include TestHelper
|
5
5
|
|
6
6
|
def test_basics_simple
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
7
|
+
setup_for_flag_with_names(:f)
|
8
|
+
assert_attributes_set
|
9
|
+
assert_equal(:f,@cli_option.name)
|
10
|
+
assert_nil @cli_option.aliases
|
11
11
|
end
|
12
12
|
|
13
13
|
def test_basics_kinda_complex
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
14
|
+
setup_for_flag_with_names([:f])
|
15
|
+
assert_attributes_set
|
16
|
+
assert_equal(:f,@cli_option.name)
|
17
|
+
assert_nil @cli_option.aliases
|
18
18
|
end
|
19
19
|
|
20
20
|
def test_basics_complex
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
assert_equal ["-f VAL","--file VAL","--filename VAL",/foobar/,Float],@flag.arguments_for_option_parser
|
27
|
-
}
|
21
|
+
setup_for_flag_with_names([:f,:file,:filename])
|
22
|
+
assert_attributes_set
|
23
|
+
assert_equal(:f,@cli_option.name)
|
24
|
+
assert_equal [:file,:filename], @cli_option.aliases
|
25
|
+
assert_equal ["-f VAL","--file VAL","--filename VAL",/foobar/,Float],@flag.arguments_for_option_parser
|
28
26
|
end
|
29
27
|
|
30
28
|
def test_flag_can_mask_its_value
|
31
|
-
|
32
|
-
|
29
|
+
setup_for_flag_with_names(:password, :mask => true)
|
30
|
+
assert_attributes_set(:safe_default_value => "********")
|
33
31
|
end
|
34
32
|
|
35
|
-
def
|
36
|
-
lambda do
|
33
|
+
def setup_for_flag_with_names(names,options = {})
|
37
34
|
@options = {
|
38
35
|
:desc => 'Filename',
|
39
36
|
:long_desc => 'The Filename',
|
@@ -45,11 +42,9 @@ class TC_testFlag < Clean::Test::TestCase
|
|
45
42
|
}.merge(options)
|
46
43
|
@flag = GLI::Flag.new(names,@options)
|
47
44
|
@cli_option = @flag
|
48
|
-
end
|
49
45
|
end
|
50
46
|
|
51
|
-
def
|
52
|
-
lambda {
|
47
|
+
def assert_attributes_set(override={})
|
53
48
|
expected = @options.merge(override)
|
54
49
|
assert_equal(expected[:desc],@flag.description)
|
55
50
|
assert_equal(expected[:long_desc],@flag.long_description)
|
@@ -57,6 +52,5 @@ class TC_testFlag < Clean::Test::TestCase
|
|
57
52
|
assert_equal(expected[:safe_default_value],@flag.safe_default_value)
|
58
53
|
assert_equal(expected[:must_match],@flag.must_match)
|
59
54
|
assert_equal(expected[:type],@flag.type)
|
60
|
-
}
|
61
55
|
end
|
62
56
|
end
|
@@ -1,18 +1,7 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
# and compatibility
|
4
|
-
unless File.respond_to? :realpath
|
5
|
-
class File
|
6
|
-
def self.realpath path
|
7
|
-
return realpath(File.readlink(path)) if symlink?(path)
|
8
|
-
path
|
9
|
-
end
|
10
|
-
end
|
11
|
-
end
|
1
|
+
require_relative "test_helper"
|
2
|
+
require_relative "support/fake_std_out"
|
12
3
|
|
13
|
-
|
14
|
-
|
15
|
-
class TC_testGLI < Clean::Test::TestCase
|
4
|
+
class GLITest < MiniTest::Test
|
16
5
|
include TestHelper
|
17
6
|
|
18
7
|
def setup
|
@@ -24,7 +13,7 @@ class TC_testGLI < Clean::Test::TestCase
|
|
24
13
|
$stderr = @fake_stderr
|
25
14
|
@app = CLIApp.new
|
26
15
|
|
27
|
-
@config_file = File.expand_path(File.dirname(File.realpath(__FILE__)) + '/new_config.
|
16
|
+
@config_file = File.expand_path(File.dirname(File.realpath(__FILE__)) + '/support/new_config.yml')
|
28
17
|
@gli_debug = ENV['GLI_DEBUG']
|
29
18
|
@app.error_device=@fake_stderr
|
30
19
|
ENV.delete('GLI_DEBUG')
|
@@ -141,7 +130,7 @@ class TC_testGLI < Clean::Test::TestCase
|
|
141
130
|
def test_init_from_config
|
142
131
|
failure = nil
|
143
132
|
@app.reset
|
144
|
-
@app.config_file(File.expand_path(File.dirname(File.realpath(__FILE__)) + '/
|
133
|
+
@app.config_file(File.expand_path(File.dirname(File.realpath(__FILE__)) + '/support/gli_test_config.yml'))
|
145
134
|
@app.flag :f
|
146
135
|
@app.switch :s
|
147
136
|
@app.flag :g
|
@@ -175,7 +164,7 @@ class TC_testGLI < Clean::Test::TestCase
|
|
175
164
|
def test_command_line_overrides_config
|
176
165
|
failure = nil
|
177
166
|
@app.reset
|
178
|
-
@app.config_file(File.expand_path(File.dirname(File.realpath(__FILE__)) + '/
|
167
|
+
@app.config_file(File.expand_path(File.dirname(File.realpath(__FILE__)) + '/support/gli_test_config.yml'))
|
179
168
|
@app.flag :f
|
180
169
|
@app.switch :s
|
181
170
|
@app.flag :g
|
@@ -207,7 +196,7 @@ class TC_testGLI < Clean::Test::TestCase
|
|
207
196
|
end
|
208
197
|
|
209
198
|
def test_no_overwrite_config
|
210
|
-
config_file = File.expand_path(File.dirname(File.realpath(__FILE__)) + '/
|
199
|
+
config_file = File.expand_path(File.dirname(File.realpath(__FILE__)) + '/support/gli_test_config.yml')
|
211
200
|
config_file_contents = File.read(config_file)
|
212
201
|
@app.reset
|
213
202
|
@app.config_file(config_file)
|
@@ -680,7 +669,11 @@ class TC_testGLI < Clean::Test::TestCase
|
|
680
669
|
end
|
681
670
|
end
|
682
671
|
|
683
|
-
|
672
|
+
begin
|
673
|
+
@app.run(['multiply', '--help'])
|
674
|
+
rescue GLI::CustomExit
|
675
|
+
assert false, "Expected no exception"
|
676
|
+
end
|
684
677
|
end
|
685
678
|
|
686
679
|
class ConvertMe
|
@@ -810,38 +803,26 @@ class TC_testGLI < Clean::Test::TestCase
|
|
810
803
|
do_test_switch_create_compact(object)
|
811
804
|
end
|
812
805
|
|
813
|
-
def some_descriptions
|
814
|
-
lambda {
|
815
|
-
@description = 'this is a description'
|
816
|
-
@long_description = 'this is a very long description'
|
817
|
-
}
|
818
|
-
end
|
819
|
-
|
820
|
-
def assert_switch_was_made(object,switch)
|
821
|
-
lambda {
|
822
|
-
assert object.switches[switch]
|
823
|
-
assert_equal @description,object.switches[switch].description,"For switch #{switch}"
|
824
|
-
assert_equal @long_description,object.switches[switch].long_description,"For switch #{switch}"
|
825
|
-
assert(object.usage != nil) if object.respond_to? :usage
|
826
|
-
}
|
827
|
-
end
|
828
|
-
|
829
806
|
def do_test_switch_create_classic(object)
|
830
|
-
|
831
|
-
|
832
|
-
|
833
|
-
|
834
|
-
|
835
|
-
|
836
|
-
|
807
|
+
@description = 'this is a description'
|
808
|
+
@long_description = 'this is a very long description'
|
809
|
+
object.desc @description
|
810
|
+
object.long_desc @long_description
|
811
|
+
object.switch :f
|
812
|
+
assert object.switches[:f]
|
813
|
+
assert_equal @description,object.switches[:f].description,"For switch #{:f}"
|
814
|
+
assert_equal @long_description,object.switches[:f].long_description,"For switch #{:f}"
|
815
|
+
assert(object.usage != nil) if object.respond_to? :usage
|
837
816
|
end
|
838
817
|
|
839
818
|
def do_test_switch_create_compact(object)
|
840
|
-
|
841
|
-
|
842
|
-
|
843
|
-
|
844
|
-
|
819
|
+
@description = 'this is a description'
|
820
|
+
@long_description = 'this is a very long description'
|
821
|
+
object.switch :g, :desc => @description, :long_desc => @long_description
|
822
|
+
assert object.switches[:g]
|
823
|
+
assert_equal @description,object.switches[:g].description,"For switch #{:g}"
|
824
|
+
assert_equal @long_description,object.switches[:g].long_description,"For switch #{:g}"
|
825
|
+
assert(object.usage != nil) if object.respond_to? :usage
|
845
826
|
end
|
846
827
|
|
847
828
|
def do_test_switch_create_twice(object)
|