subprocess 0.1.6 → 0.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. data/README.md +72 -0
  2. data/lib/subprocess.rb +529 -20
  3. metadata +55 -121
  4. data/History.txt +0 -4
  5. data/Manifest.txt +0 -46
  6. data/PostInstall.txt +0 -7
  7. data/README.rdoc +0 -77
  8. data/Rakefile +0 -20
  9. data/TODO.rdoc +0 -1
  10. data/examples/simple.irb +0 -22
  11. data/examples/simple_timeout.irb +0 -22
  12. data/features/multiple_popens_sequence.feature +0 -23
  13. data/features/popen.feature +0 -45
  14. data/features/popen_over_ssh.feature +0 -44
  15. data/features/popen_over_ssh_without_blocking.feature +0 -16
  16. data/features/popen_remote_fails_with_invalid_auth_data.feature +0 -13
  17. data/features/popen_reports_runtime.feature +0 -11
  18. data/features/popen_running.feature +0 -11
  19. data/features/popen_with_timeout.feature +0 -19
  20. data/features/popen_without_blocking.feature +0 -16
  21. data/features/step_definitions/common_steps.rb +0 -168
  22. data/features/step_definitions/multiple_popens_sequence_steps.rb +0 -73
  23. data/features/step_definitions/popen_over_ssh_steps.rb +0 -29
  24. data/features/step_definitions/popen_over_ssh_without_blocking_steps.rb +0 -30
  25. data/features/step_definitions/popen_remote_fails_with_invalid_auth_dat_steps.rb +0 -19
  26. data/features/step_definitions/popen_reports_runtime_steps.rb +0 -13
  27. data/features/step_definitions/popen_running_steps.rb +0 -12
  28. data/features/step_definitions/popen_steps.rb +0 -34
  29. data/features/step_definitions/popen_with_timeout_steps.rb +0 -24
  30. data/features/step_definitions/popen_without_blocking_steps.rb +0 -33
  31. data/features/support/common.rb +0 -29
  32. data/features/support/env.rb +0 -15
  33. data/features/support/matchers.rb +0 -11
  34. data/lib/core_ext/hash.rb +0 -14
  35. data/lib/core_ext/process_status.rb +0 -14
  36. data/lib/subprocess/popen.rb +0 -188
  37. data/lib/subprocess/popen_factory.rb +0 -63
  38. data/lib/subprocess/popen_remote.rb +0 -64
  39. data/lib/subprocess/popen_sequence.rb +0 -57
  40. data/script/console +0 -10
  41. data/script/destroy +0 -14
  42. data/script/generate +0 -14
  43. data/spec/spec.opts +0 -1
  44. data/spec/spec_helper.rb +0 -10
  45. data/spec/subprocess/popen_spec.rb +0 -32
  46. data/spec/subprocess_spec.rb +0 -2
  47. data/subprocess.gemspec +0 -36
  48. data/tasks/rspec.rake +0 -21
@@ -1,44 +0,0 @@
1
- Feature: Run simple remote subprocesses over ssh in ruby
2
-
3
- As a ruby hacker
4
- I want to run remote system subprocesses over ssh
5
- And I want to have them presented as objects
6
- So that I can get more data about said subprocesses
7
- And so that I can have more fine grained control of said subprocesses
8
-
9
- Scenario Outline: run simple remote subprocesses
10
- Given I have a new remote Subprocess instance initialized with "<command>"
11
- When I invoke the run method of said remote subprocess
12
- And I invoke the wait method of said remote subprocess
13
- Then the remote instances exit status is "<exitstatus>"
14
- And the remote instances stdout matches "<stdout>"
15
- And the remote instances stderr matches "<stderr>"
16
- And the remote instance should have a numerical pid
17
-
18
- Scenarios: zero exit code remote subprocesses with stdout
19
- | command | exitstatus | stdout | stderr |
20
- | echo 1 | 0 | 1 | |
21
-
22
- Scenarios: zero exit code remote subprocesses with stderr
23
- | command | exitstatus | stdout | stderr |
24
- | echo 1 1>&2 | 0 | | 1 |
25
-
26
- Scenarios: zero exit code remote subprocesses with stdout and stderr
27
- | command | exitstatus | stdout | stderr |
28
- | echo 1 && echo 1 1>&2 | 0 | 1 | 1 |
29
-
30
- Scenarios: nonzero exit code remote subprocesses with stdout
31
- | command | exitstatus | stdout | stderr |
32
- | echo 1 && exit 1 | 1 | 1 | |
33
- | echo 1 && exit 2 | 2 | 1 | |
34
- | echo 1 && exit 99 | 99 | 1 | |
35
-
36
- Scenarios: nonzero exit code remote subprocesses with stderr
37
- | command | exitstatus | stdout | stderr |
38
- | echo 1 1>&2 && exit 1 | 1 | | 1 |
39
-
40
- Scenarios: nonzero exit code remote subprocesses with stdout and stderr
41
- | command | exitstatus | stdout | stderr |
42
- | echo 1 && echo 1 1>&2 && exit 1 | 1 | 1 | 1 |
43
-
44
-
@@ -1,16 +0,0 @@
1
- Feature: Run simple remote subprocesses without blocking and over ssh in ruby
2
-
3
- As a ruby hacker
4
- I want to run remote system subprocesses that do not block over ssh
5
- And I want to have them presented as objects
6
- So that I can get more data about said subprocesses
7
- And so that I can have more fine grained control of said subprocesses
8
-
9
- Scenario: run simple remote nonblocking subprocess
10
- Given I have a new remote nonblocking subprocess that takes a long time to run
11
- When I invoke the run method of said nonblocking remote subprocess
12
- Then the remote nonblocking subprocess should not block
13
- And the remote nonblocking subprocess should report its run status
14
- And the remote nonblocking subprocess should support being waited on till complete
15
- And the remote nonblocking subprocess should have status info
16
-
@@ -1,13 +0,0 @@
1
- Feature: Run simple remote subprocesses that has bad auth data
2
-
3
- As a ruby hacker
4
- I want to run system remote subprocesses that require auth data
5
- So they can be secure
6
- And actually remote :)
7
-
8
- Scenario: run simple remote subprocess with bad auth data
9
- Given I have a new remote subproces with invalid username
10
- And invalid password
11
- When I run the remote subprocess
12
- Then the remote subprocess should return an error
13
-
@@ -1,11 +0,0 @@
1
- Feature: Run simple subprocesses that report run time
2
-
3
- As a ruby hacker
4
- I want to run system subprocesses that report their run time
5
- So that I know how long it took to run
6
-
7
- Scenario: run simple subprocess that takes 3 seconds
8
- Given I have a new subprocess that takes 3 seconds
9
- When I wait on said 3 second process to complete
10
- Then the subprocess should report a run time of around 3 seconds
11
-
@@ -1,11 +0,0 @@
1
- Feature: Run simple subprocesses that report running
2
-
3
- As a ruby hacker
4
- I want to run system subprocesses that report their running status
5
- So that I know when said subprocess is finished without waiting
6
-
7
- Scenario: run simple subprocess that finishes fast
8
- Given I have a new subprocess that runs fast
9
- When I invoke the run method of said fast subprocess
10
- Then the subprocess should report running as false without waiting
11
-
@@ -1,19 +0,0 @@
1
- Feature: Run simple subprocesses stopping them at timeout if not complete
2
-
3
- As a ruby hacker
4
- I want to run system subprocesses
5
- And I want them to terminate by a set timeout
6
- So that I don't end up with a bunch of zombies
7
-
8
- Scenario: run simple subprocess that goes past timeout
9
- Given I have a new subprocess that takes more than 5 seconds to run
10
- And I set a timeout of 5 seconds
11
- When I invoke the run method of said subprocess with timeout
12
- Then the subprocess should exit with exitcode 1
13
-
14
- Scenario: run simple subprocess that does not go past timeout
15
- Given I have a new subprocess that takes less than 5 seconds to run
16
- And I set a timeout of 5 seconds
17
- When I invoke the run method of said subprocess with timeout
18
- Then the subprocess should complete fine
19
-
@@ -1,16 +0,0 @@
1
- Feature: Run simple subprocesses without blocking in ruby
2
-
3
- As a ruby hacker
4
- I want to run system subprocesses that do not block
5
- And I want to have them presented as objects
6
- So that I can get more data about said subprocesses
7
- And so that I can have more fine grained control of said subprocesses
8
-
9
- Scenario: run simple subprocess without blocking
10
- Given I have a new subprocess that takes a long time to run
11
- When I invoke the run method of said nonblocking subprocess
12
- Then the subprocess should not block
13
- And the subprocess should report its run status
14
- And the subprocess should support being waited on till complete
15
- And the subprocess should have status info
16
-
@@ -1,168 +0,0 @@
1
- Given /^this project is active project folder/ do
2
- @active_project_folder = File.expand_path(File.dirname(__FILE__) + "/../..")
3
- end
4
-
5
- Given /^env variable \$([\w_]+) set to "(.*)"/ do |env_var, value|
6
- ENV[env_var] = value
7
- end
8
-
9
- Given /"(.*)" folder is deleted/ do |folder|
10
- in_project_folder { FileUtils.rm_rf folder }
11
- end
12
-
13
- When /^I invoke "(.*)" generator with arguments "(.*)"$/ do |generator, arguments|
14
- @stdout = StringIO.new
15
- in_project_folder do
16
- if Object.const_defined?("APP_ROOT")
17
- APP_ROOT.replace(FileUtils.pwd)
18
- else
19
- APP_ROOT = FileUtils.pwd
20
- end
21
- run_generator(generator, arguments.split(' '), SOURCES, :stdout => @stdout)
22
- end
23
- File.open(File.join(@tmp_root, "generator.out"), "w") do |f|
24
- @stdout.rewind
25
- f << @stdout.read
26
- end
27
- end
28
-
29
- When /^I run executable "(.*)" with arguments "(.*)"/ do |executable, arguments|
30
- @stdout = File.expand_path(File.join(@tmp_root, "executable.out"))
31
- in_project_folder do
32
- system "#{executable} #{arguments} > #{@stdout} 2> #{@stdout}"
33
- end
34
- end
35
-
36
- When /^I run project executable "(.*)" with arguments "(.*)"/ do |executable, arguments|
37
- @stdout = File.expand_path(File.join(@tmp_root, "executable.out"))
38
- in_project_folder do
39
- system "ruby #{executable} #{arguments} > #{@stdout} 2> #{@stdout}"
40
- end
41
- end
42
-
43
- When /^I run local executable "(.*)" with arguments "(.*)"/ do |executable, arguments|
44
- @stdout = File.expand_path(File.join(@tmp_root, "executable.out"))
45
- executable = File.expand_path(File.join(File.dirname(__FILE__), "/../../bin", executable))
46
- in_project_folder do
47
- system "ruby #{executable} #{arguments} > #{@stdout} 2> #{@stdout}"
48
- end
49
- end
50
-
51
- When /^I invoke task "rake (.*)"/ do |task|
52
- @stdout = File.expand_path(File.join(@tmp_root, "tests.out"))
53
- in_project_folder do
54
- system "rake #{task} --trace > #{@stdout} 2> #{@stdout}"
55
- end
56
- end
57
-
58
- Then /^folder "(.*)" (is|is not) created/ do |folder, is|
59
- in_project_folder do
60
- File.exists?(folder).should(is == 'is' ? be_true : be_false)
61
- end
62
- end
63
-
64
- Then /^file "(.*)" (is|is not) created/ do |file, is|
65
- in_project_folder do
66
- File.exists?(file).should(is == 'is' ? be_true : be_false)
67
- end
68
- end
69
-
70
- Then /^file with name matching "(.*)" is created/ do |pattern|
71
- in_project_folder do
72
- Dir[pattern].should_not be_empty
73
- end
74
- end
75
-
76
- Then /^file "(.*)" contents (does|does not) match \/(.*)\// do |file, does, regex|
77
- in_project_folder do
78
- actual_output = File.read(file)
79
- (does == 'does') ?
80
- actual_output.should(match(/#{regex}/)) :
81
- actual_output.should_not(match(/#{regex}/))
82
- end
83
- end
84
-
85
- Then /gem file "(.*)" and generated file "(.*)" should be the same/ do |gem_file, project_file|
86
- File.exists?(gem_file).should be_true
87
- File.exists?(project_file).should be_true
88
- gem_file_contents = File.read(File.dirname(__FILE__) + "/../../#{gem_file}")
89
- project_file_contents = File.read(File.join(@active_project_folder, project_file))
90
- project_file_contents.should == gem_file_contents
91
- end
92
-
93
- Then /^(does|does not) invoke generator "(.*)"$/ do |does_invoke, generator|
94
- actual_output = File.read(@stdout)
95
- does_invoke == "does" ?
96
- actual_output.should(match(/dependency\s+#{generator}/)) :
97
- actual_output.should_not(match(/dependency\s+#{generator}/))
98
- end
99
-
100
- Then /help options "(.*)" and "(.*)" are displayed/ do |opt1, opt2|
101
- actual_output = File.read(@stdout)
102
- actual_output.should match(/#{opt1}/)
103
- actual_output.should match(/#{opt2}/)
104
- end
105
-
106
- Then /^I should see "([^\"]*)"$/ do |text|
107
- actual_output = File.read(@stdout)
108
- actual_output.should contain(text)
109
- end
110
-
111
- Then /^I should see$/ do |text|
112
- actual_output = File.read(@stdout)
113
- actual_output.should contain(text)
114
- end
115
-
116
- Then /^I should not see$/ do |text|
117
- actual_output = File.read(@stdout)
118
- actual_output.should_not contain(text)
119
- end
120
-
121
- Then /^I should see exactly$/ do |text|
122
- actual_output = File.read(@stdout)
123
- actual_output.should == text
124
- end
125
-
126
- Then /^I should see all (\d+) tests pass/ do |expected_test_count|
127
- expected = %r{^#{expected_test_count} tests, \d+ assertions, 0 failures, 0 errors}
128
- actual_output = File.read(@stdout)
129
- actual_output.should match(expected)
130
- end
131
-
132
- Then /^I should see all (\d+) examples pass/ do |expected_test_count|
133
- expected = %r{^#{expected_test_count} examples?, 0 failures}
134
- actual_output = File.read(@stdout)
135
- actual_output.should match(expected)
136
- end
137
-
138
- Then /^yaml file "(.*)" contains (\{.*\})/ do |file, yaml|
139
- in_project_folder do
140
- yaml = eval yaml
141
- YAML.load(File.read(file)).should == yaml
142
- end
143
- end
144
-
145
- Then /^Rakefile can display tasks successfully/ do
146
- @stdout = File.expand_path(File.join(@tmp_root, "rakefile.out"))
147
- in_project_folder do
148
- system "rake -T > #{@stdout} 2> #{@stdout}"
149
- end
150
- actual_output = File.read(@stdout)
151
- actual_output.should match(/^rake\s+\w+\s+#\s.*/)
152
- end
153
-
154
- Then /^task "rake (.*)" is executed successfully/ do |task|
155
- @stdout.should_not be_nil
156
- actual_output = File.read(@stdout)
157
- actual_output.should_not match(/^Don't know how to build task '#{task}'/)
158
- actual_output.should_not match(/Error/i)
159
- end
160
-
161
- Then /^gem spec key "(.*)" contains \/(.*)\// do |key, regex|
162
- in_project_folder do
163
- gem_file = Dir["pkg/*.gem"].first
164
- gem_spec = Gem::Specification.from_yaml(`gem spec #{gem_file}`)
165
- spec_value = gem_spec.send(key.to_sym)
166
- spec_value.to_s.should match(/#{regex}/)
167
- end
168
- end
@@ -1,73 +0,0 @@
1
- Given /^I have a subprocess sequence with 2 subprocesses to run$/ do
2
- @seq = Subprocess::PopenSequence.new
3
- @seq.add_popen(Subprocess::Popen.new('echo "popen 1"'))
4
- @seq.add_popen(Subprocess::Popen.new('echo "popen 2"'))
5
- end
6
-
7
- When /^I run the subprocesses sequence$/ do
8
- @seq.perform
9
- end
10
-
11
- Then /^the subprocess sequence completes with success$/ do
12
- @seq.status[:exitstatus].should == 0
13
- @seq.completed?.should be_true
14
- @seq.complete.length.should == 2
15
- @seq.incomplete.length.should == 0
16
- @seq.failed.length.should == 0
17
- end
18
-
19
- Then /^the subprocess sequence has stdout for each subprocess$/ do
20
- @seq.complete.each do |popen|
21
- popen.stdout.should_not == ""
22
- end
23
- end
24
-
25
- Then /^the subprocess sequence has stderr for each subprocess$/ do
26
- @seq.complete.each do |popen|
27
- popen.stderr.should == ""
28
- end
29
- end
30
-
31
- Then /^the subprocess sequence has status for each subprocess$/ do
32
- @seq.complete.each do |popen|
33
- popen.status.should be_kind_of Hash
34
- end
35
- end
36
-
37
- Given /^I have a subprocess sequence with 2 subprocesses to run with a bad one first$/ do
38
- @seq = Subprocess::PopenSequence.new
39
- @seq.add_popen(Subprocess::Popen.new('exit 1'))
40
- @seq.add_popen(Subprocess::Popen.new('echo "popen 2"'))
41
- end
42
-
43
- Then /^the subprocess sequence completes with failure$/ do
44
- @seq.incomplete.length.should == 1
45
- @seq.failed.length.should == 1
46
- @seq.complete.length.should == 0
47
- @seq.status[:exitstatus].should_not == 0
48
- end
49
-
50
- Given /^I have a subprocess sequence with 2 subprocesses sequences$/ do
51
- seq1 = Subprocess::PopenSequence.new
52
- seq1 << Subprocess::Popen.new('echo "seq 1 - popen 1"')
53
- seq1 << Subprocess::Popen.new('echo "seq 1 - popen 2"')
54
- seq2 = Subprocess::PopenSequence.new
55
- seq2 << Subprocess::Popen.new('echo "seq 2 - popen 1"')
56
- seq2 << Subprocess::Popen.new('echo "seq 2 - popen 2"')
57
- @seq = Subprocess::PopenSequence.new
58
- @seq << seq1
59
- @seq << seq2
60
- end
61
-
62
- When /^I run the sequence$/ do
63
- @seq.perform
64
- end
65
-
66
- Then /^the sequences run just like any other subprocess$/ do
67
- @seq.status[:exitstatus].should == 0
68
- @seq.completed?.should be_true
69
- @seq.complete.length.should == 2
70
- @seq.incomplete.length.should == 0
71
- @seq.failed.length.should == 0
72
- end
73
-
@@ -1,29 +0,0 @@
1
-
2
- Given /^I have a new remote Subprocess instance initialized with "([^\"]*)"$/ do |command|
3
- @popen_remote = Subprocess::PopenRemote.new(command, 'localhost', 'popen', 10, :password => 'popen')
4
- end
5
-
6
- When /^I invoke the run method of said remote subprocess$/ do
7
- @popen_remote.run
8
- end
9
-
10
- When /^I invoke the wait method of said remote subprocess$/ do
11
- @popen_remote.wait
12
- end
13
-
14
- Then /^the remote instances exit status is "([^\"]*)"$/ do |exitstatus|
15
- @popen_remote.status[:exitstatus].should == exitstatus.to_i
16
- end
17
-
18
- Then /^the remote instances stdout matches "([^\"]*)"$/ do |stdout|
19
- @popen_remote.stdout.should match(stdout)
20
- end
21
-
22
- Then /^the remote instances stderr matches "([^\"]*)"$/ do |stderr|
23
- @popen_remote.stderr.should match(stderr)
24
- end
25
-
26
- Then /^the remote instance should have a numerical pid$/ do
27
- @popen_remote.pid.should be_a_kind_of Fixnum
28
- end
29
-
@@ -1,30 +0,0 @@
1
-
2
- Given /^I have a new remote nonblocking subprocess that takes a long time to run$/ do
3
- @popen = Subprocess::PopenRemote.new('sleep 3 && exit 1', 'localhost', nil, 10, 'popen', :password => 'popen')
4
- @popen.should_not be_nil
5
- end
6
-
7
- When /^I invoke the run method of said nonblocking remote subprocess$/ do
8
- start_time = Time.now.to_i
9
- @popen.run
10
- @total_time = Time.now.to_i - start_time
11
- end
12
-
13
- Then /^the remote nonblocking subprocess should not block$/ do
14
- @total_time.should be_close(0, 2)
15
- end
16
-
17
- Then /^the remote nonblocking subprocess should report its run status$/ do
18
- @popen.should respond_to(:running?)
19
- end
20
-
21
- Then /^the remote nonblocking subprocess should support being waited on till complete$/ do
22
- @popen.wait
23
- end
24
-
25
- Then /^the remote nonblocking subprocess should have status info$/ do
26
- @popen.status[:exitstatus].should be_kind_of Numeric
27
- @popen.status.should be_a_kind_of Hash
28
- end
29
-
30
-