scmd 2.1.1 → 2.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +2 -0
- data/LICENSE.txt +1 -1
- data/Rakefile +1 -1
- data/bench/results.txt +80 -0
- data/bench/runner.rb +29 -0
- data/lib/scmd.rb +9 -0
- data/lib/scmd/command.rb +120 -56
- data/lib/scmd/version.rb +1 -1
- data/log/.gitkeep +0 -0
- data/scmd.gemspec +2 -1
- data/script/bench.rb +47 -0
- data/test/helper.rb +6 -2
- data/test/support/bigger-than-64k.txt +704 -0
- data/test/support/smaller-than-64k.txt +1 -0
- data/test/unit/command_tests.rb +43 -20
- data/test/unit/scmd_tests.rb +49 -6
- metadata +23 -13
@@ -0,0 +1 @@
|
|
1
|
+
01234556789
|
data/test/unit/command_tests.rb
CHANGED
@@ -1,21 +1,20 @@
|
|
1
1
|
require "assert"
|
2
2
|
require 'scmd/command'
|
3
3
|
|
4
|
-
|
4
|
+
class Scmd::Command
|
5
5
|
|
6
|
-
class
|
7
|
-
desc "
|
6
|
+
class UnitTests < Assert::Context
|
7
|
+
desc "Scmd::Command"
|
8
8
|
setup do
|
9
|
-
@success_cmd = Command.new("echo hi")
|
10
|
-
@failure_cmd = Command.new("cd /path/that/does/not/exist")
|
9
|
+
@success_cmd = Scmd::Command.new("echo hi")
|
10
|
+
@failure_cmd = Scmd::Command.new("cd /path/that/does/not/exist")
|
11
11
|
end
|
12
12
|
subject { @success_cmd }
|
13
13
|
|
14
14
|
should have_readers :cmd_str, :pid, :exitstatus, :stdout, :stderr
|
15
|
-
should
|
16
|
-
should
|
17
|
-
should
|
18
|
-
|
15
|
+
should have_imeths :run, :run!
|
16
|
+
should have_imeths :start, :wait, :stop, :kill
|
17
|
+
should have_imeths :running?, :success?
|
19
18
|
|
20
19
|
should "know and return its cmd string" do
|
21
20
|
assert_equal "echo hi", subject.cmd_str
|
@@ -35,7 +34,7 @@ module Scmd
|
|
35
34
|
assert_not_nil @success_cmd.pid
|
36
35
|
assert_equal 0, @success_cmd.exitstatus
|
37
36
|
assert @success_cmd.success?
|
38
|
-
assert_equal
|
37
|
+
assert_equal "hi\n", @success_cmd.stdout
|
39
38
|
assert_equal '', @success_cmd.stderr
|
40
39
|
|
41
40
|
@failure_cmd.run
|
@@ -66,7 +65,7 @@ module Scmd
|
|
66
65
|
end
|
67
66
|
|
68
67
|
should "start and be running until `wait` is called and the cmd exits" do
|
69
|
-
cmd = Command.new("sleep .1")
|
68
|
+
cmd = Scmd::Command.new("sleep .1")
|
70
69
|
assert_not cmd.running?
|
71
70
|
|
72
71
|
cmd.start
|
@@ -103,10 +102,10 @@ module Scmd
|
|
103
102
|
|
104
103
|
end
|
105
104
|
|
106
|
-
class InputTests <
|
105
|
+
class InputTests < UnitTests
|
107
106
|
desc "that takes input on stdin"
|
108
107
|
setup do
|
109
|
-
@cmd = Command.new("sh")
|
108
|
+
@cmd = Scmd::Command.new("sh")
|
110
109
|
end
|
111
110
|
subject { @cmd }
|
112
111
|
|
@@ -114,23 +113,23 @@ module Scmd
|
|
114
113
|
subject.run "echo hi"
|
115
114
|
|
116
115
|
assert @cmd.success?
|
117
|
-
assert_equal
|
116
|
+
assert_equal "hi\n", @cmd.stdout
|
118
117
|
end
|
119
118
|
|
120
119
|
should "run the command given multiple lines of input" do
|
121
120
|
subject.run ["echo hi", "echo err 1>&2"]
|
122
121
|
|
123
122
|
assert @cmd.success?
|
124
|
-
assert_equal
|
125
|
-
assert_equal
|
123
|
+
assert_equal "hi\n", @cmd.stdout
|
124
|
+
assert_equal "err\n", @cmd.stderr
|
126
125
|
end
|
127
126
|
|
128
127
|
end
|
129
128
|
|
130
|
-
class LongRunningTests <
|
129
|
+
class LongRunningTests < UnitTests
|
131
130
|
desc "that is long running"
|
132
131
|
setup do
|
133
|
-
@long_cmd = Command.new("sleep .3 && echo hi")
|
132
|
+
@long_cmd = Scmd::Command.new("sleep .3 && echo hi")
|
134
133
|
end
|
135
134
|
|
136
135
|
should "not timeout if wait timeout is longer than cmd time" do
|
@@ -139,11 +138,11 @@ module Scmd
|
|
139
138
|
@long_cmd.wait(1)
|
140
139
|
end
|
141
140
|
assert @long_cmd.success?
|
142
|
-
assert_equal
|
141
|
+
assert_equal "hi\n", @long_cmd.stdout
|
143
142
|
end
|
144
143
|
|
145
144
|
should "timeout if wait timeout is shorter than cmd time" do
|
146
|
-
assert_raises(TimeoutError) do
|
145
|
+
assert_raises(Scmd::TimeoutError) do
|
147
146
|
@long_cmd.start
|
148
147
|
@long_cmd.wait(0.1)
|
149
148
|
end
|
@@ -167,4 +166,28 @@ module Scmd
|
|
167
166
|
|
168
167
|
end
|
169
168
|
|
169
|
+
class BufferDeadlockTests < UnitTests
|
170
|
+
desc "when capturing data from an output buffer"
|
171
|
+
setup do
|
172
|
+
@small_path = File.join(ROOT_PATH, 'test/support/smaller-than-64k.txt')
|
173
|
+
@small_data = File.read(@small_path)
|
174
|
+
@small_cmd = Scmd::Command.new("cat #{@small_path}")
|
175
|
+
|
176
|
+
@big_path = File.join(ROOT_PATH, 'test/support/bigger-than-64k.txt')
|
177
|
+
@big_data = File.read(@big_path)
|
178
|
+
@big_cmd = Scmd::Command.new("cat #{@big_path}")
|
179
|
+
end
|
180
|
+
|
181
|
+
should "not deadlock, just stream the data from the buffer" do
|
182
|
+
@small_cmd.start
|
183
|
+
assert_nothing_raised{ @small_cmd.wait(1) }
|
184
|
+
assert_equal @small_data, @small_cmd.stdout
|
185
|
+
|
186
|
+
@big_cmd.start
|
187
|
+
assert_nothing_raised{ @big_cmd.wait(1) }
|
188
|
+
assert_equal @big_data, @big_cmd.stdout
|
189
|
+
end
|
190
|
+
|
191
|
+
end
|
192
|
+
|
170
193
|
end
|
data/test/unit/scmd_tests.rb
CHANGED
@@ -1,14 +1,57 @@
|
|
1
1
|
require "assert"
|
2
2
|
require 'scmd'
|
3
3
|
|
4
|
-
|
5
|
-
desc "Scmd"
|
6
|
-
subject { Scmd }
|
4
|
+
require 'scmd/command'
|
7
5
|
|
8
|
-
|
6
|
+
module Scmd
|
7
|
+
|
8
|
+
class UnitTests < Assert::Context
|
9
|
+
desc "Scmd"
|
10
|
+
subject{ Scmd }
|
11
|
+
|
12
|
+
should have_instance_method :new
|
13
|
+
|
14
|
+
should "build a `Command` with the `new` method" do
|
15
|
+
assert_kind_of Scmd::Command, subject.new('echo hi')
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
|
20
|
+
class TimeoutErrorTests < UnitTests
|
21
|
+
desc "TimeoutError"
|
22
|
+
setup do
|
23
|
+
@error = Scmd::TimeoutError.new('test')
|
24
|
+
end
|
25
|
+
subject{ @error }
|
26
|
+
|
27
|
+
should "be a RuntimeError" do
|
28
|
+
assert_kind_of ::RuntimeError, subject
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
class RunErrorTests < UnitTests
|
34
|
+
desc "RunError"
|
35
|
+
setup do
|
36
|
+
@error = Scmd::RunError.new('test')
|
37
|
+
end
|
38
|
+
subject{ @error }
|
39
|
+
|
40
|
+
should "be a RuntimeError" do
|
41
|
+
assert_kind_of ::RuntimeError, subject
|
42
|
+
end
|
43
|
+
|
44
|
+
should "set its backtrace to the caller by default" do
|
45
|
+
assert_match /scmd_tests.rb:.*$/, subject.backtrace.first
|
46
|
+
end
|
47
|
+
|
48
|
+
should "allow passing a custom backtrace" do
|
49
|
+
called_from = caller
|
50
|
+
error = Scmd::RunError.new('test', called_from)
|
51
|
+
|
52
|
+
assert_equal called_from, error.backtrace
|
53
|
+
end
|
9
54
|
|
10
|
-
should "build a `Command` with the `new` method" do
|
11
|
-
assert_kind_of Scmd::Command, subject.new('echo hi')
|
12
55
|
end
|
13
56
|
|
14
57
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: scmd
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 15
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 2
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 2.1.
|
9
|
+
- 2
|
10
|
+
version: 2.1.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Kelly Redding
|
@@ -16,26 +16,26 @@ autorequire:
|
|
16
16
|
bindir: bin
|
17
17
|
cert_chain: []
|
18
18
|
|
19
|
-
date: 2013-
|
19
|
+
date: 2013-11-11 00:00:00 Z
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
22
22
|
name: assert
|
23
23
|
prerelease: false
|
24
|
-
type: :development
|
25
24
|
requirement: &id001 !ruby/object:Gem::Requirement
|
26
25
|
none: false
|
27
26
|
requirements:
|
28
|
-
- -
|
27
|
+
- - ~>
|
29
28
|
- !ruby/object:Gem::Version
|
30
|
-
hash:
|
29
|
+
hash: 5
|
31
30
|
segments:
|
32
|
-
-
|
33
|
-
|
31
|
+
- 2
|
32
|
+
- 3
|
33
|
+
version: "2.3"
|
34
|
+
type: :development
|
34
35
|
version_requirements: *id001
|
35
36
|
- !ruby/object:Gem::Dependency
|
36
37
|
name: posix-spawn
|
37
38
|
prerelease: false
|
38
|
-
type: :runtime
|
39
39
|
requirement: &id002 !ruby/object:Gem::Requirement
|
40
40
|
none: false
|
41
41
|
requirements:
|
@@ -45,6 +45,7 @@ dependencies:
|
|
45
45
|
segments:
|
46
46
|
- 0
|
47
47
|
version: "0"
|
48
|
+
type: :runtime
|
48
49
|
version_requirements: *id002
|
49
50
|
description: Build and run system commands.
|
50
51
|
email:
|
@@ -62,16 +63,23 @@ files:
|
|
62
63
|
- LICENSE.txt
|
63
64
|
- README.md
|
64
65
|
- Rakefile
|
66
|
+
- bench/results.txt
|
67
|
+
- bench/runner.rb
|
65
68
|
- lib/scmd.rb
|
66
69
|
- lib/scmd/command.rb
|
67
70
|
- lib/scmd/version.rb
|
71
|
+
- log/.gitkeep
|
68
72
|
- scmd.gemspec
|
73
|
+
- script/bench.rb
|
69
74
|
- test/helper.rb
|
75
|
+
- test/support/bigger-than-64k.txt
|
76
|
+
- test/support/smaller-than-64k.txt
|
70
77
|
- test/unit/command_tests.rb
|
71
78
|
- test/unit/scmd_tests.rb
|
79
|
+
- tmp/.gitkeep
|
72
80
|
homepage: http://github.com/redding/scmd
|
73
|
-
licenses:
|
74
|
-
|
81
|
+
licenses:
|
82
|
+
- MIT
|
75
83
|
post_install_message:
|
76
84
|
rdoc_options: []
|
77
85
|
|
@@ -98,11 +106,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
98
106
|
requirements: []
|
99
107
|
|
100
108
|
rubyforge_project:
|
101
|
-
rubygems_version: 1.8.
|
109
|
+
rubygems_version: 1.8.24
|
102
110
|
signing_key:
|
103
111
|
specification_version: 3
|
104
112
|
summary: Build and run system commands.
|
105
113
|
test_files:
|
106
114
|
- test/helper.rb
|
115
|
+
- test/support/bigger-than-64k.txt
|
116
|
+
- test/support/smaller-than-64k.txt
|
107
117
|
- test/unit/command_tests.rb
|
108
118
|
- test/unit/scmd_tests.rb
|