methadone-rehab 1.9.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (75) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +15 -0
  3. data/.ruby-gemset +1 -0
  4. data/.ruby-version +1 -0
  5. data/.travis.yml +11 -0
  6. data/CHANGES.md +66 -0
  7. data/Gemfile +6 -0
  8. data/LICENSE.txt +201 -0
  9. data/README.rdoc +179 -0
  10. data/Rakefile +98 -0
  11. data/TODO.md +3 -0
  12. data/bin/methadone +157 -0
  13. data/features/bootstrap.feature +169 -0
  14. data/features/license.feature +43 -0
  15. data/features/multilevel_commands.feature +125 -0
  16. data/features/readme.feature +26 -0
  17. data/features/rspec_support.feature +27 -0
  18. data/features/step_definitions/bootstrap_steps.rb +47 -0
  19. data/features/step_definitions/license_steps.rb +30 -0
  20. data/features/step_definitions/readme_steps.rb +26 -0
  21. data/features/step_definitions/version_steps.rb +4 -0
  22. data/features/support/env.rb +26 -0
  23. data/features/version.feature +17 -0
  24. data/lib/methadone.rb +15 -0
  25. data/lib/methadone/argv_parser.rb +50 -0
  26. data/lib/methadone/cli.rb +124 -0
  27. data/lib/methadone/cli_logger.rb +133 -0
  28. data/lib/methadone/cli_logging.rb +138 -0
  29. data/lib/methadone/cucumber.rb +174 -0
  30. data/lib/methadone/error.rb +32 -0
  31. data/lib/methadone/execution_strategy/base.rb +34 -0
  32. data/lib/methadone/execution_strategy/jvm.rb +37 -0
  33. data/lib/methadone/execution_strategy/mri.rb +16 -0
  34. data/lib/methadone/execution_strategy/open_3.rb +16 -0
  35. data/lib/methadone/execution_strategy/open_4.rb +22 -0
  36. data/lib/methadone/execution_strategy/rbx_open_4.rb +12 -0
  37. data/lib/methadone/exit_now.rb +40 -0
  38. data/lib/methadone/main.rb +1039 -0
  39. data/lib/methadone/process_status.rb +45 -0
  40. data/lib/methadone/sh.rb +223 -0
  41. data/lib/methadone/version.rb +3 -0
  42. data/methadone-rehab.gemspec +32 -0
  43. data/templates/full/.gitignore.erb +4 -0
  44. data/templates/full/README.rdoc.erb +25 -0
  45. data/templates/full/Rakefile.erb +74 -0
  46. data/templates/full/_license_head.txt.erb +2 -0
  47. data/templates/full/apache_LICENSE.txt.erb +203 -0
  48. data/templates/full/bin/executable.erb +47 -0
  49. data/templates/full/custom_LICENSE.txt.erb +0 -0
  50. data/templates/full/features/executable.feature.erb +13 -0
  51. data/templates/full/features/step_definitions/executable_steps.rb.erb +1 -0
  52. data/templates/full/features/support/env.rb.erb +16 -0
  53. data/templates/full/gplv2_LICENSE.txt.erb +14 -0
  54. data/templates/full/gplv3_LICENSE.txt.erb +15 -0
  55. data/templates/full/mit_LICENSE.txt.erb +7 -0
  56. data/templates/multicommand/bin/executable.erb +52 -0
  57. data/templates/multicommand/lib/command.rb.erb +40 -0
  58. data/templates/multicommand/lib/commands.rb.erb +7 -0
  59. data/templates/rspec/spec/something_spec.rb.erb +5 -0
  60. data/templates/test_unit/test/tc_something.rb.erb +7 -0
  61. data/test/base_test.rb +20 -0
  62. data/test/command_for_tests.sh +7 -0
  63. data/test/execution_strategy/test_base.rb +24 -0
  64. data/test/execution_strategy/test_jvm.rb +77 -0
  65. data/test/execution_strategy/test_mri.rb +32 -0
  66. data/test/execution_strategy/test_open_3.rb +70 -0
  67. data/test/execution_strategy/test_open_4.rb +86 -0
  68. data/test/execution_strategy/test_rbx_open_4.rb +25 -0
  69. data/test/test_cli_logger.rb +219 -0
  70. data/test/test_cli_logging.rb +243 -0
  71. data/test/test_exit_now.rb +37 -0
  72. data/test/test_main.rb +1213 -0
  73. data/test/test_multi.rb +405 -0
  74. data/test/test_sh.rb +404 -0
  75. metadata +321 -0
@@ -0,0 +1,47 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ <% if add_library_to_load_path -%>
4
+ $LOAD_PATH.unshift File.expand_path(File.join(File.dirname(__FILE__), '../lib'))
5
+
6
+ <% end -%>
7
+ require 'optparse'
8
+ require 'methadone'
9
+ require '<%= require_file %>'
10
+
11
+ class App
12
+ include Methadone::Main
13
+ include Methadone::CLILogging
14
+
15
+ main do # Add args you want: |like,so|
16
+ # your program code here
17
+ # You can access CLI options via
18
+ # the options Hash
19
+ end
20
+
21
+ # supplemental methods here
22
+
23
+ # Declare command-line interface here
24
+
25
+ # description "one line description of your app"
26
+ #
27
+ # Accept flags via:
28
+ # on("--flag VAL","Some flag")
29
+ # options[flag] will contain VAL
30
+ #
31
+ # Specify switches via:
32
+ # on("--[no-]switch","Some switch")
33
+ #
34
+ # Or, just call OptionParser methods on opts
35
+ #
36
+ # Require an argument
37
+ # arg :some_arg
38
+ #
39
+ # # Make an argument optional
40
+ # arg :optional_arg, :optional
41
+
42
+ version <%= module_name %>::VERSION
43
+
44
+ use_log_level_option :toggle_debug_on_signal => 'USR1'
45
+
46
+ go!
47
+ end
File without changes
@@ -0,0 +1,13 @@
1
+ Feature: My bootstrapped app kinda works
2
+ In order to get going on coding my awesome app
3
+ I want to have aruba and cucumber setup
4
+ So I don't have to do it myself
5
+
6
+ Scenario: App just runs
7
+ When I get help for "<%= gemname %>"
8
+ Then the exit status should be 0
9
+ And the banner should be present
10
+ And the banner should document that this app takes options
11
+ And the following options should be documented:
12
+ |--version|
13
+ And the banner should document that this app takes no arguments
@@ -0,0 +1 @@
1
+ # Put your step definitions here
@@ -0,0 +1,16 @@
1
+ require 'aruba/cucumber'
2
+ require 'methadone/cucumber'
3
+
4
+ ENV['PATH'] = "#{File.expand_path(File.dirname(__FILE__) + '/../../bin')}#{File::PATH_SEPARATOR}#{ENV['PATH']}"
5
+ LIB_DIR = File.join(File.expand_path(File.dirname(__FILE__)),'..','..','lib')
6
+
7
+ Before do
8
+ # Using "announce" causes massive warnings on 1.9.2
9
+ @puts = true
10
+ @original_rubylib = ENV['RUBYLIB']
11
+ ENV['RUBYLIB'] = LIB_DIR + File::PATH_SEPARATOR + ENV['RUBYLIB'].to_s
12
+ end
13
+
14
+ After do
15
+ ENV['RUBYLIB'] = @original_rubylib
16
+ end
@@ -0,0 +1,14 @@
1
+ <%= render_license_partial('_license_head.txt.erb') %>
2
+
3
+ This program is free software; you can redistribute it and/or modify
4
+ it under the terms of the GNU General Public License as published by
5
+ the Free Software Foundation; either version 2 of the License, or
6
+ (at your option) any later version.
7
+
8
+ This program is distributed in the hope that it will be useful,
9
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
+ GNU General Public License for more details.
12
+
13
+ You should have received a copy of the GNU General Public License
14
+ along with this program; if not, see <http://www.gnu.org/licenses/>.
@@ -0,0 +1,15 @@
1
+ <%= render_license_partial('_license_head.txt.erb') %>
2
+
3
+ This program is free software: you can redistribute it and/or modify
4
+ it under the terms of the GNU General Public License as published by
5
+ the Free Software Foundation, either version 3 of the License, or
6
+ (at your option) any later version.
7
+
8
+ This program is distributed in the hope that it will be useful,
9
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
+ GNU General Public License for more details.
12
+
13
+ You should have received a copy of the GNU General Public License
14
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
15
+
@@ -0,0 +1,7 @@
1
+ <%= render_license_partial('_license_head.txt.erb') %>
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,52 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ <% if add_library_to_load_path -%>
4
+ $LOAD_PATH.unshift File.expand_path(File.join(File.dirname(__FILE__), '../lib'))
5
+
6
+ <% end -%>
7
+ require 'optparse'
8
+ require 'methadone'
9
+ require '<%= require_file %>'
10
+ require '<%= gemname %>/commands'
11
+
12
+ class App
13
+ include Methadone::Main
14
+ include Methadone::CLILogging
15
+
16
+ <% commands.each do |cmd| -%>
17
+ command "<%= cmd %>" => <%= module_name %>::Commands::<%= titlify(normalize_command(cmd)) %>
18
+ <% end -%>
19
+
20
+ main do # Add args you want: |like,so|
21
+ # your program code here
22
+ # You can access CLI options via
23
+ # the options Hash
24
+ end
25
+
26
+ # supplemental methods here
27
+
28
+ # Declare command-line interface here
29
+
30
+ # description "one line description of your app"
31
+ #
32
+ # Accept flags via:
33
+ # on("--flag VAL","Some flag")
34
+ # options[flag] will contain VAL
35
+ #
36
+ # Specify switches via:
37
+ # on("--[no-]switch","Some switch")
38
+ #
39
+ # Or, just call OptionParser methods on opts
40
+ #
41
+ # Require an argument
42
+ # arg :some_arg
43
+ #
44
+ # # Make an argument optional
45
+ # arg :optional_arg, :optional
46
+
47
+ version <%= module_name %>::VERSION
48
+
49
+ use_log_level_option
50
+
51
+ go!
52
+ end
@@ -0,0 +1,40 @@
1
+ require 'optparse'
2
+ require 'methadone'
3
+
4
+ module <%= module_name %>
5
+ module Commands
6
+ class <%= titlify(normalize_command(cmd)) %>
7
+ include Methadone::Main
8
+ include Methadone::CLILogging
9
+
10
+ main do # Add args you want: |like,so|
11
+ # your program code here
12
+ # You can access CLI options via
13
+ # the options Hash
14
+ end
15
+
16
+ # supplemental methods here
17
+
18
+ # Declare command-line interface here
19
+
20
+ # description "one line description of your app"
21
+ description "provides command '<%= cmd -%>'"
22
+
23
+ # Accept flags via:
24
+ # on("--flag VAL","Some flag")
25
+ # options[flag] will contain VAL
26
+ #
27
+ # Specify switches via:
28
+ # on("--[no-]switch","Some switch")
29
+ #
30
+ # Or, just call OptionParser methods on opts
31
+ #
32
+ # Require an argument
33
+ # arg :some_arg
34
+ #
35
+ # # Make an argument optional
36
+ # arg :optional_arg, :optional
37
+ end
38
+ end
39
+ end
40
+
@@ -0,0 +1,7 @@
1
+ Dir[File.dirname(__FILE__) + '/commands/*.rb'].each {|file| require file }
2
+
3
+ module <%= module_name %>
4
+ module Commands
5
+ end
6
+ end
7
+
@@ -0,0 +1,5 @@
1
+ describe "TestSomething" do
2
+ it "should be true" do
3
+ expect(true).to eq(true)
4
+ end
5
+ end
@@ -0,0 +1,7 @@
1
+ require 'test/unit'
2
+
3
+ class TestSomething < Test::Unit::TestCase
4
+ def test_truth
5
+ assert true
6
+ end
7
+ end
@@ -0,0 +1,20 @@
1
+ if RUBY_PLATFORM == 'java'
2
+ puts "Simplecov seems to cause JRuby to barf, so use another ruby if you want to check coverage"
3
+ else
4
+ require 'simplecov'
5
+ SimpleCov.start do
6
+ add_filter "/test"
7
+ end
8
+ end
9
+
10
+ require 'test/unit'
11
+ require 'rspec/expectations'
12
+ require 'clean_test/test_case'
13
+ require 'ostruct'
14
+ require 'pry'
15
+
16
+ RSpec::Matchers.configuration.syntax = :should
17
+
18
+ class BaseTest < Clean::Test::TestCase
19
+ include RSpec::Matchers
20
+ end
@@ -0,0 +1,7 @@
1
+ #!/bin/sh
2
+
3
+ echo "standard output"
4
+ if [ $# -gt 0 ]; then
5
+ echo "standard error" 1>&2
6
+ fi
7
+ exit $#
@@ -0,0 +1,24 @@
1
+ require 'base_test'
2
+
3
+ module ExecutionStrategy
4
+ class TestBase < BaseTest
5
+ include Methadone::ExecutionStrategy
6
+
7
+ [
8
+ [:run_command,["ls"]],
9
+ [:exception_meaning_command_not_found,[]],
10
+ ].each do |(method,args)|
11
+ test_that "#{method} isn't implemented" do
12
+ Given {
13
+ @strategy = Base.new
14
+ }
15
+ When {
16
+ @code = lambda { @strategy.send(method,*args) }
17
+ }
18
+ Then {
19
+ assert_raises(RuntimeError,&@code)
20
+ }
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,77 @@
1
+ require 'base_test'
2
+ require 'mocha/setup'
3
+
4
+ # Defined by JRuby, but this test must pass on any Ruby
5
+ class NativeException
6
+ end
7
+
8
+ module ExecutionStrategy
9
+ class TestJVM < BaseTest
10
+ include Methadone::ExecutionStrategy
11
+
12
+ test_that "run_command proxies to Open3.capture3" do
13
+ Given {
14
+ @process = mock('java.lang.Process')
15
+ @runtime = mock('java.lang.Runtime')
16
+ @command = "ls"
17
+ @stdout = any_string
18
+ @stderr = any_string
19
+ @exitstatus = any_int :min => 1, :max => 127
20
+ }
21
+ When the_test_runs
22
+ Then {
23
+ expects_lang = mock()
24
+ JVM.any_instance.expects(:java).returns(expects_lang)
25
+ expects_Runtime = mock()
26
+ expects_lang.expects(:lang).returns(expects_Runtime)
27
+ runtime_klass = mock()
28
+ expects_Runtime.expects(:Runtime).returns(runtime_klass)
29
+ runtime_klass.expects(:get_runtime).returns(@runtime)
30
+ @runtime.expects(:exec).with(@command).returns(@process)
31
+
32
+ stdin = mock()
33
+ @process.expects(:get_output_stream).returns(stdin)
34
+ stdin.expects(:close)
35
+
36
+ stdout_input_stream = mock('InputStream')
37
+ @process.expects(:get_input_stream).returns(stdout_input_stream)
38
+ stdout_input_stream.expects(:read).times(2).returns(
39
+ @stdout,
40
+ -1)
41
+
42
+ stderr_input_stream = mock('InputStream')
43
+ @process.expects(:get_error_stream).returns(stderr_input_stream)
44
+ stderr_input_stream.expects(:read).times(2).returns(
45
+ @stderr,
46
+ -1)
47
+
48
+ @process.expects(:wait_for).returns(@exitstatus)
49
+ }
50
+
51
+ Given new_jvm_strategy
52
+ When {
53
+ @results = @strategy.run_command(@command)
54
+ }
55
+ Then {
56
+ @results[0].should == @stdout
57
+ @results[1].should == @stderr
58
+ @results[2].exitstatus.should == @exitstatus
59
+ }
60
+ end
61
+
62
+ test_that "exception_meaning_command_not_found returns NativeException" do
63
+ Given new_jvm_strategy
64
+ When {
65
+ @klass = @strategy.exception_meaning_command_not_found
66
+ }
67
+ Then {
68
+ @klass.should == NativeException
69
+ }
70
+ end
71
+
72
+ private
73
+ def new_jvm_strategy
74
+ lambda { @strategy = JVM.new }
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,32 @@
1
+ require 'base_test'
2
+
3
+ module ExecutionStrategy
4
+ class TestMRI < BaseTest
5
+ include Methadone::ExecutionStrategy
6
+
7
+ test_that "run_command isn't implemented" do
8
+ Given new_mri_strategy
9
+ When {
10
+ @code = lambda { @strategy.run_command("ls") }
11
+ }
12
+ Then {
13
+ assert_raises(RuntimeError,&@code)
14
+ }
15
+ end
16
+
17
+ test_that "exception_meaning_command_not_found returns Errno::ENOENT" do
18
+ Given new_mri_strategy
19
+ When {
20
+ @klass = @strategy.exception_meaning_command_not_found
21
+ }
22
+ Then {
23
+ @klass.should == Errno::ENOENT
24
+ }
25
+ end
26
+
27
+ private
28
+ def new_mri_strategy
29
+ lambda { @strategy = MRI.new }
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,70 @@
1
+ require 'base_test'
2
+ require 'mocha/setup'
3
+ require 'open3'
4
+
5
+ module ExecutionStrategy
6
+ class TestOpen_3 < BaseTest
7
+ include Methadone::ExecutionStrategy
8
+
9
+ test_that "run_command proxies to Open3.capture3" do
10
+ Given {
11
+ @command = any_string
12
+ @stdout = any_string
13
+ @stderr = any_string
14
+ @status = stub('Process::Status')
15
+ }
16
+ When the_test_runs
17
+ Then {
18
+ Open3.expects(:capture3).with(@command).returns([@stdout,@stderr,@status])
19
+ }
20
+
21
+ Given new_open_3_strategy
22
+ When {
23
+ @results = @strategy.run_command(@command)
24
+ }
25
+ Then {
26
+ @results[0].should == @stdout
27
+ @results[1].should == @stderr
28
+ @results[2].should be @status
29
+ }
30
+ end
31
+
32
+ test_that "run_command handles array arguments properly" do
33
+ Given {
34
+ @command = [any_string, any_string, any_string]
35
+ @stdout = any_string
36
+ @stderr = any_string
37
+ @status = stub('Process::Status')
38
+ }
39
+ When the_test_runs
40
+ Then {
41
+ Open3.expects(:capture3).with(*@command).returns([@stdout,@stderr,@status])
42
+ }
43
+
44
+ Given new_open_3_strategy
45
+ When {
46
+ @results = @strategy.run_command(@command)
47
+ }
48
+ Then {
49
+ @results[0].should == @stdout
50
+ @results[1].should == @stderr
51
+ @results[2].should be @status
52
+ }
53
+ end
54
+
55
+ test_that "exception_meaning_command_not_found returns Errno::ENOENT" do
56
+ Given new_open_3_strategy
57
+ When {
58
+ @klass = @strategy.exception_meaning_command_not_found
59
+ }
60
+ Then {
61
+ @klass.should == Errno::ENOENT
62
+ }
63
+ end
64
+
65
+ private
66
+ def new_open_3_strategy
67
+ lambda { @strategy = Open_3.new }
68
+ end
69
+ end
70
+ end