execute_shell 0.0.5 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/license/lgpl ADDED
@@ -0,0 +1,157 @@
1
+ This version of the GNU Lesser General Public License incorporates
2
+ the terms and conditions of version 3 of the GNU General Public
3
+ License, supplemented by the additional permissions listed below.
4
+
5
+ 0. Additional Definitions.
6
+
7
+ As used herein, "this License" refers to version 3 of the GNU Lesser
8
+ General Public License, and the "GNU GPL" refers to version 3 of the GNU
9
+ General Public License.
10
+
11
+ "The Library" refers to a covered work governed by this License,
12
+ other than an Application or a Combined Work as defined below.
13
+
14
+ An "Application" is any work that makes use of an interface provided
15
+ by the Library, but which is not otherwise based on the Library.
16
+ Defining a subclass of a class defined by the Library is deemed a mode
17
+ of using an interface provided by the Library.
18
+
19
+ A "Combined Work" is a work produced by combining or linking an
20
+ Application with the Library. The particular version of the Library
21
+ with which the Combined Work was made is also called the "Linked
22
+ Version".
23
+
24
+ The "Minimal Corresponding Source" for a Combined Work means the
25
+ Corresponding Source for the Combined Work, excluding any source code
26
+ for portions of the Combined Work that, considered in isolation, are
27
+ based on the Application, and not on the Linked Version.
28
+
29
+ The "Corresponding Application Code" for a Combined Work means the
30
+ object code and/or source code for the Application, including any data
31
+ and utility programs needed for reproducing the Combined Work from the
32
+ Application, but excluding the System Libraries of the Combined Work.
33
+
34
+ 1. Exception to Section 3 of the GNU GPL.
35
+
36
+ You may convey a covered work under sections 3 and 4 of this License
37
+ without being bound by section 3 of the GNU GPL.
38
+
39
+ 2. Conveying Modified Versions.
40
+
41
+ If you modify a copy of the Library, and, in your modifications, a
42
+ facility refers to a function or data to be supplied by an Application
43
+ that uses the facility (other than as an argument passed when the
44
+ facility is invoked), then you may convey a copy of the modified
45
+ version:
46
+
47
+ a) under this License, provided that you make a good faith effort to
48
+ ensure that, in the event an Application does not supply the
49
+ function or data, the facility still operates, and performs
50
+ whatever part of its purpose remains meaningful, or
51
+
52
+ b) under the GNU GPL, with none of the additional permissions of
53
+ this License applicable to that copy.
54
+
55
+ 3. Object Code Incorporating Material from Library Header Files.
56
+
57
+ The object code form of an Application may incorporate material from
58
+ a header file that is part of the Library. You may convey such object
59
+ code under terms of your choice, provided that, if the incorporated
60
+ material is not limited to numerical parameters, data structure
61
+ layouts and accessors, or small macros, inline functions and templates
62
+ (ten or fewer lines in length), you do both of the following:
63
+
64
+ a) Give prominent notice with each copy of the object code that the
65
+ Library is used in it and that the Library and its use are
66
+ covered by this License.
67
+
68
+ b) Accompany the object code with a copy of the GNU GPL and this license
69
+ document.
70
+
71
+ 4. Combined Works.
72
+
73
+ You may convey a Combined Work under terms of your choice that,
74
+ taken together, effectively do not restrict modification of the
75
+ portions of the Library contained in the Combined Work and reverse
76
+ engineering for debugging such modifications, if you also do each of
77
+ the following:
78
+
79
+ a) Give prominent notice with each copy of the Combined Work that
80
+ the Library is used in it and that the Library and its use are
81
+ covered by this License.
82
+
83
+ b) Accompany the Combined Work with a copy of the GNU GPL and this license
84
+ document.
85
+
86
+ c) For a Combined Work that displays copyright notices during
87
+ execution, include the copyright notice for the Library among
88
+ these notices, as well as a reference directing the user to the
89
+ copies of the GNU GPL and this license document.
90
+
91
+ d) Do one of the following:
92
+
93
+ 0) Convey the Minimal Corresponding Source under the terms of this
94
+ License, and the Corresponding Application Code in a form
95
+ suitable for, and under terms that permit, the user to
96
+ recombine or relink the Application with a modified version of
97
+ the Linked Version to produce a modified Combined Work, in the
98
+ manner specified by section 6 of the GNU GPL for conveying
99
+ Corresponding Source.
100
+
101
+ 1) Use a suitable shared library mechanism for linking with the
102
+ Library. A suitable mechanism is one that (a) uses at run time
103
+ a copy of the Library already present on the user's computer
104
+ system, and (b) will operate properly with a modified version
105
+ of the Library that is interface-compatible with the Linked
106
+ Version.
107
+
108
+ e) Provide Installation Information, but only if you would otherwise
109
+ be required to provide such information under section 6 of the
110
+ GNU GPL, and only to the extent that such information is
111
+ necessary to install and execute a modified version of the
112
+ Combined Work produced by recombining or relinking the
113
+ Application with a modified version of the Linked Version. (If
114
+ you use option 4d0, the Installation Information must accompany
115
+ the Minimal Corresponding Source and Corresponding Application
116
+ Code. If you use option 4d1, you must provide the Installation
117
+ Information in the manner specified by section 6 of the GNU GPL
118
+ for conveying Corresponding Source.)
119
+
120
+ 5. Combined Libraries.
121
+
122
+ You may place library facilities that are a work based on the
123
+ Library side by side in a single library together with other library
124
+ facilities that are not Applications and are not covered by this
125
+ License, and convey such a combined library under terms of your
126
+ choice, if you do both of the following:
127
+
128
+ a) Accompany the combined library with a copy of the same work based
129
+ on the Library, uncombined with any other library facilities,
130
+ conveyed under the terms of this License.
131
+
132
+ b) Give prominent notice with the combined library that part of it
133
+ is a work based on the Library, and explaining where to find the
134
+ accompanying uncombined form of the same work.
135
+
136
+ 6. Revised Versions of the GNU Lesser General Public License.
137
+
138
+ The Free Software Foundation may publish revised and/or new versions
139
+ of the GNU Lesser General Public License from time to time. Such new
140
+ versions will be similar in spirit to the present version, but may
141
+ differ in detail to address new problems or concerns.
142
+
143
+ Each version is given a distinguishing version number. If the
144
+ Library as you received it specifies that a certain numbered version
145
+ of the GNU Lesser General Public License "or any later version"
146
+ applies to it, you have the option of following the terms and
147
+ conditions either of that published version or of any later version
148
+ published by the Free Software Foundation. If the Library as you
149
+ received it does not specify a version number of the GNU Lesser
150
+ General Public License, you may choose any version of the GNU Lesser
151
+ General Public License ever published by the Free Software Foundation.
152
+
153
+ If the Library as you received it specifies that a proxy can decide
154
+ whether future versions of the GNU Lesser General Public License shall
155
+ apply, that proxy's public statement of acceptance of any version is
156
+ permanent authorization for you to choose that version for the
157
+ Library.
Binary file
data/rakefile CHANGED
@@ -1,2 +1 @@
1
- require 'bundler'
2
- Bundler.require :rake
1
+ require 'rake_tasks'
data/test/helper.rb ADDED
@@ -0,0 +1,37 @@
1
+ #--
2
+ ################################################################################
3
+ # Copyright (C) 2011 Travis Herrick #
4
+ ################################################################################
5
+ # #
6
+ # \v^V,^!v\^/ #
7
+ # ~% %~ #
8
+ # { _ _ } #
9
+ # ( * - ) #
10
+ # | / | #
11
+ # \ _, / #
12
+ # \__.__/ #
13
+ # #
14
+ ################################################################################
15
+ # This program is free software: you can redistribute it #
16
+ # and/or modify it under the terms of the GNU Lesser General Public License #
17
+ # as published by the Free Software Foundation, #
18
+ # either version 3 of the License, or (at your option) any later version. #
19
+ ################################################################################
20
+ # This program is distributed in the hope that it will be useful, #
21
+ # but WITHOUT ANY WARRANTY; #
22
+ # without even the implied warranty of MERCHANTABILITY #
23
+ # or FITNESS FOR A PARTICULAR PURPOSE. #
24
+ # See the GNU Lesser General Public License for more details. #
25
+ # #
26
+ # You should have received a copy of the GNU Lesser General Public License #
27
+ # along with this program. If not, see <http://www.gnu.org/licenses/>. #
28
+ ################################################################################
29
+ #++
30
+
31
+ root_path = File.join(File.dirname(File.expand_path(__FILE__)), '..')
32
+ root_path = File.expand_path(root_path)
33
+
34
+ require 'test/unit'
35
+ require 'test_unit_helper'
36
+
37
+ require_relative '../lib/execute_shell'
@@ -0,0 +1,152 @@
1
+ #--
2
+ ################################################################################
3
+ # Copyright (C) 2011 Travis Herrick #
4
+ ################################################################################
5
+ # #
6
+ # \v^V,^!v\^/ #
7
+ # ~% %~ #
8
+ # { _ _ } #
9
+ # ( * - ) #
10
+ # | / | #
11
+ # \ _, / #
12
+ # \__.__/ #
13
+ # #
14
+ ################################################################################
15
+ # This program is free software: you can redistribute it #
16
+ # and/or modify it under the terms of the GNU Lesser General Public License #
17
+ # as published by the Free Software Foundation, #
18
+ # either version 3 of the License, or (at your option) any later version. #
19
+ ################################################################################
20
+ # This program is distributed in the hope that it will be useful, #
21
+ # but WITHOUT ANY WARRANTY; #
22
+ # without even the implied warranty of MERCHANTABILITY #
23
+ # or FITNESS FOR A PARTICULAR PURPOSE. #
24
+ # See the GNU Lesser General Public License for more details. #
25
+ # #
26
+ # You should have received a copy of the GNU Lesser General Public License #
27
+ # along with this program. If not, see <http://www.gnu.org/licenses/>. #
28
+ ################################################################################
29
+ #++
30
+
31
+ require_relative '../helper'
32
+
33
+ class ExecuteShellTest < Test::Unit::TestCase
34
+ Command = {
35
+ :ls => {
36
+ :linux => 'ls',
37
+ :mingw => 'dir',
38
+ }
39
+ }
40
+
41
+ def setup
42
+ @obj = @class.new
43
+ @working_path = Dir.getwd
44
+ @home_path = File.expand_path(File.join('~', '..'))
45
+ @user = File.basename(File.expand_path('~'))
46
+ end
47
+
48
+ def test_supported_systems
49
+ assert_equal [:linux, :mingw], @class.supported_systems
50
+ end
51
+
52
+ def test_supported_flag
53
+ assert_equal true, @class.supported?
54
+ assert_equal true, @class.supported?(:linux)
55
+ assert_equal true, @class.supported?('linux')
56
+ assert_equal true, @class.supported?(:mingw)
57
+ assert_equal true, @class.supported?('mingw')
58
+ assert_equal false, @class.supported?(:my_os)
59
+ assert_equal false, @class.supported?('my_os')
60
+ end
61
+
62
+ def test_raise_not_implemented_error
63
+ assert_raise(NotImplementedError) { @class.raise_not_implemented('method') }
64
+ end
65
+
66
+ def test_basic_run
67
+ shell_result = @class.run("echo 'hello world'")
68
+ assert_equal ShellResult, shell_result.class
69
+ check_all 'hello world', '', true, shell_result
70
+ end
71
+
72
+ def test_bad_command
73
+ result = @class.run('my_bad_command')
74
+
75
+ case Platform::IMPL
76
+ when :linux
77
+ check_all '',
78
+ 'bash: line 1: my_bad_command: command not found',
79
+ false, result
80
+ when :mingw
81
+ ExecuteShell.raise_not_implemented __method__
82
+ end
83
+ end
84
+
85
+ def test_change_directory_parameter
86
+ command = get_command(:ls)
87
+
88
+ result = @class.run(command, @home_path)
89
+
90
+ assert File.expand_path(Dir.getwd) != @home_path
91
+
92
+ assert_equal true, result.success?
93
+ assert_equal '', result.err
94
+
95
+ assert result.out.index(@user),
96
+ "'#{command}' does not appear to include " +
97
+ "the current user's folder (#{@user}), " +
98
+ "which implies that the path was not changed prior to execution."
99
+ end
100
+
101
+ def test_run_success
102
+ assert_equal true, @class.run_success?("echo 'hello world'")
103
+ assert_equal false, @class.run_success?('my_bad_command')
104
+ end
105
+
106
+ def test_run_out
107
+ assert_equal 'hello world', @class.run_out("echo 'hello world'")
108
+ assert_equal '', @class.run_out('my_bad_command')
109
+ end
110
+
111
+ def test_run_to_s
112
+ assert_equal 'hello world', @class.run_to_s("echo 'hello world'")
113
+ assert_equal 'bash: line 1: my_bad_command: command not found',
114
+ @class.run_to_s('my_bad_command')
115
+ end
116
+
117
+ def test_run_success_err
118
+ assert_equal [true, ''], @class.run_success_err("echo 'hello world'")
119
+ assert_equal [false, 'bash: line 1: my_bad_command: command not found'],
120
+ @class.run_success_err('my_bad_command')
121
+ end
122
+
123
+ def test_run_success_err_out
124
+ assert_equal [true, '', 'hello world'],
125
+ @class.run_success_err_out("echo 'hello world'")
126
+ assert_equal [false, 'bash: line 1: my_bad_command: command not found', ''],
127
+ @class.run_success_err_out('my_bad_command')
128
+ end
129
+
130
+ def test_respond_to
131
+ assert_respond_to @class, :run_success?
132
+ assert_respond_to @class, :run_success
133
+ assert_respond_to @class, :run_success_err_out
134
+ assert_respond_to @class, :run_err_out_success
135
+ assert_respond_to @class, :run_success_to_s
136
+ assert_equal false, @class.respond_to?(:run_success_blah)
137
+ end
138
+
139
+ ############################################################################
140
+ private
141
+ ############################################################################
142
+
143
+ def get_command(cmd)
144
+ return Command[cmd][Platform::IMPL]
145
+ end
146
+
147
+ def check_all(out, err, success, result)
148
+ assert_equal out, result.out
149
+ assert_equal err, result.err
150
+ assert_equal success, result.success?
151
+ end
152
+ end
@@ -0,0 +1,63 @@
1
+ #--
2
+ ################################################################################
3
+ # Copyright (C) 2011 Travis Herrick #
4
+ ################################################################################
5
+ # #
6
+ # \v^V,^!v\^/ #
7
+ # ~% %~ #
8
+ # { _ _ } #
9
+ # ( * - ) #
10
+ # | / | #
11
+ # \ _, / #
12
+ # \__.__/ #
13
+ # #
14
+ ################################################################################
15
+ # This program is free software: you can redistribute it #
16
+ # and/or modify it under the terms of the GNU Lesser General Public License #
17
+ # as published by the Free Software Foundation, #
18
+ # either version 3 of the License, or (at your option) any later version. #
19
+ ################################################################################
20
+ # This program is distributed in the hope that it will be useful, #
21
+ # but WITHOUT ANY WARRANTY; #
22
+ # without even the implied warranty of MERCHANTABILITY #
23
+ # or FITNESS FOR A PARTICULAR PURPOSE. #
24
+ # See the GNU Lesser General Public License for more details. #
25
+ # #
26
+ # You should have received a copy of the GNU Lesser General Public License #
27
+ # along with this program. If not, see <http://www.gnu.org/licenses/>. #
28
+ ################################################################################
29
+ #++
30
+
31
+ require_relative '../helper'
32
+
33
+ class ShellResultTest < Test::Unit::TestCase
34
+ def setup
35
+ @obj = @class.new('Std Out', 'Std Err')
36
+ end
37
+
38
+ def test_readonly_attributes
39
+ assert_raise(NoMethodError) { @obj.out = 'blah' }
40
+ assert_raise(NoMethodError) { @obj.err = 'blah' }
41
+ end
42
+
43
+ def test_output_text
44
+ assert_equal 'Std Out', @obj.out
45
+ end
46
+
47
+ def test_error_text
48
+ assert_equal 'Std Err', @obj.err
49
+ end
50
+
51
+ def test_success
52
+ result = @class.new('output', nil)
53
+ assert_equal true, result.success?
54
+ result = @class.new('output', '')
55
+ assert_equal true, result.success?
56
+ result = @class.new('output', ' ')
57
+ assert_equal false, result.success?
58
+ end
59
+
60
+ def test_to_string
61
+ assert_equal "Std Out\nStd Err", @obj.to_s
62
+ end
63
+ end
metadata CHANGED
@@ -1,151 +1,125 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: execute_shell
3
- version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 0
7
- - 0
8
- - 5
9
- version: 0.0.5
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ prerelease:
10
6
  platform: ruby
11
- authors:
7
+ authors:
12
8
  - Travis Herrick
13
9
  autorequire:
14
10
  bindir: bin
15
11
  cert_chain: []
16
-
17
- date: 2011-08-10 00:00:00 -04:00
18
- default_executable:
19
- dependencies:
20
- - !ruby/object:Gem::Dependency
12
+ date: 2012-03-07 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
21
15
  name: Platform
22
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: &14839660 !ruby/object:Gem::Requirement
23
17
  none: false
24
- requirements:
18
+ requirements:
25
19
  - - ~>
26
- - !ruby/object:Gem::Version
27
- segments:
28
- - 0
29
- - 4
30
- - 0
20
+ - !ruby/object:Gem::Version
31
21
  version: 0.4.0
32
22
  type: :runtime
33
23
  prerelease: false
34
- version_requirements: *id001
35
- - !ruby/object:Gem::Dependency
24
+ version_requirements: *14839660
25
+ - !ruby/object:Gem::Dependency
36
26
  name: open4
37
- requirement: &id002 !ruby/object:Gem::Requirement
27
+ requirement: &14839060 !ruby/object:Gem::Requirement
38
28
  none: false
39
- requirements:
29
+ requirements:
40
30
  - - ~>
41
- - !ruby/object:Gem::Version
42
- segments:
43
- - 1
44
- - 0
45
- - 1
31
+ - !ruby/object:Gem::Version
46
32
  version: 1.0.1
47
33
  type: :runtime
48
34
  prerelease: false
49
- version_requirements: *id002
50
- - !ruby/object:Gem::Dependency
35
+ version_requirements: *14839060
36
+ - !ruby/object:Gem::Dependency
51
37
  name: win32-open3-19
52
- requirement: &id003 !ruby/object:Gem::Requirement
38
+ requirement: &14853660 !ruby/object:Gem::Requirement
53
39
  none: false
54
- requirements:
40
+ requirements:
55
41
  - - ~>
56
- - !ruby/object:Gem::Version
57
- segments:
58
- - 0
59
- - 0
60
- - 1
42
+ - !ruby/object:Gem::Version
61
43
  version: 0.0.1
62
44
  type: :runtime
63
45
  prerelease: false
64
- version_requirements: *id003
65
- - !ruby/object:Gem::Dependency
66
- name: app_mode
67
- requirement: &id004 !ruby/object:Gem::Requirement
46
+ version_requirements: *14853660
47
+ - !ruby/object:Gem::Dependency
48
+ name: rake_tasks
49
+ requirement: &14851340 !ruby/object:Gem::Requirement
68
50
  none: false
69
- requirements:
51
+ requirements:
70
52
  - - ~>
71
- - !ruby/object:Gem::Version
72
- segments:
73
- - 1
74
- - 0
75
- - 0
76
- version: 1.0.0
77
- type: :runtime
53
+ - !ruby/object:Gem::Version
54
+ version: 2.0.5
55
+ type: :development
78
56
  prerelease: false
79
- version_requirements: *id004
80
- - !ruby/object:Gem::Dependency
81
- name: rake_tasks
82
- requirement: &id005 !ruby/object:Gem::Requirement
57
+ version_requirements: *14851340
58
+ - !ruby/object:Gem::Dependency
59
+ name: test_unit_helper
60
+ requirement: &14850100 !ruby/object:Gem::Requirement
83
61
  none: false
84
- requirements:
62
+ requirements:
85
63
  - - ~>
86
- - !ruby/object:Gem::Version
87
- segments:
88
- - 0
89
- - 0
90
- - 1
64
+ - !ruby/object:Gem::Version
91
65
  version: 0.0.1
92
66
  type: :development
93
67
  prerelease: false
94
- version_requirements: *id005
95
- description: |-
96
- ExecuteShell provides cross-platform shell command execution.
68
+ version_requirements: *14850100
69
+ description: ! 'ExecuteShell provides cross-platform shell command execution.
70
+
97
71
  In other words, it lays the smack down like a hungry t-rex
98
- in the octagon with a pig.
72
+
73
+ in the octagon with a pig.'
99
74
  email: tthetoad@gmail.com
100
75
  executables: []
101
-
102
76
  extensions: []
103
-
104
- extra_rdoc_files:
77
+ extra_rdoc_files:
105
78
  - README
106
- files:
107
- - lib/execute_shell/execute_shell.rb
108
- - lib/execute_shell.rb
79
+ - license/gpl
80
+ - license/lgpl
81
+ - license/lgplv3-88x31.png
82
+ files:
109
83
  - Gemfile.lock
110
84
  - README
85
+ - execute_shell.gemspec
111
86
  - Gemfile
112
87
  - rakefile
113
- - execute_shell.gemspec
114
- - test/require.rb
115
- - test/execute_shell_test.rb
116
- has_rdoc: true
88
+ - lib/execute_shell.rb
89
+ - lib/execute_shell/execute_shell.rb
90
+ - lib/execute_shell/shell_result.rb
91
+ - license/gpl
92
+ - license/lgpl
93
+ - license/lgplv3-88x31.png
94
+ - test/helper.rb
95
+ - test/unit/execute_shell_test.rb
96
+ - test/unit/shell_result_test.rb
117
97
  homepage: http://www.bitbucket.org/ToadJamb/gems_execute_shell
118
- licenses:
119
- - GPLv3
98
+ licenses:
99
+ - LGPLv3
120
100
  post_install_message:
121
101
  rdoc_options: []
122
-
123
- require_paths:
102
+ require_paths:
124
103
  - lib
125
- required_ruby_version: !ruby/object:Gem::Requirement
104
+ required_ruby_version: !ruby/object:Gem::Requirement
126
105
  none: false
127
- requirements:
128
- - - ">="
129
- - !ruby/object:Gem::Version
130
- hash: -1239307810502746702
131
- segments:
132
- - 0
133
- version: "0"
134
- required_rubygems_version: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ required_rubygems_version: !ruby/object:Gem::Requirement
135
111
  none: false
136
- requirements:
137
- - - ">="
138
- - !ruby/object:Gem::Version
139
- segments:
140
- - 0
141
- version: "0"
112
+ requirements:
113
+ - - ! '>='
114
+ - !ruby/object:Gem::Version
115
+ version: '0'
142
116
  requirements: []
143
-
144
117
  rubyforge_project:
145
- rubygems_version: 1.3.7
118
+ rubygems_version: 1.8.17
146
119
  signing_key:
147
120
  specification_version: 3
148
121
  summary: Cross-platform shell commands.
149
- test_files:
150
- - test/require.rb
151
- - test/execute_shell_test.rb
122
+ test_files:
123
+ - test/helper.rb
124
+ - test/unit/execute_shell_test.rb
125
+ - test/unit/shell_result_test.rb