win32-process 0.8.1 → 0.8.2

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.
@@ -1,165 +1,165 @@
1
- ########################################################################
2
- # test_win32_process_kill.rb
3
- #
4
- # Tests for the custom Process.kill method
5
- ########################################################################
6
- require 'win32/process'
7
- require 'test-unit'
8
-
9
- class TC_Win32_Process_Kill < Test::Unit::TestCase
10
- def self.startup
11
- @@signals = Signal.list
12
- end
13
-
14
- def setup
15
- @ruby = RUBY_PLATFORM == 'java' ? 'jruby' : 'ruby'
16
- @cmd = "#{@ruby} -e 'sleep 10'"
17
- @pid = nil
18
- end
19
-
20
- test "kill basic functionality" do
21
- assert_respond_to(Process, :kill)
22
- end
23
-
24
- test "kill with signal 0 does not actually send a signal" do
25
- assert_nothing_raised{ Process.kill(0, Process.pid) }
26
- end
27
-
28
- test "kill with signal 0 returns 1 if the process exists" do
29
- assert_equal(1, Process.kill(0, Process.pid))
30
- end
31
-
32
- test "kill with signal 0 raises an ESRCH error if any process does not exist" do
33
- assert_raise(Errno::ESRCH){ Process.kill(0, 99999999) }
34
- assert_raise(Errno::ESRCH){ Process.kill(0, Process.pid, 99999999) }
35
- end
36
-
37
- test "kill accepts multiple pid values" do
38
- pid = Process.pid
39
- assert_nothing_raised{ Process.kill(0, pid, pid, pid, pid) }
40
- end
41
-
42
- test "kill with any signal returns the number of killed processes" do
43
- pid1 = Process.spawn(@cmd)
44
- pid2 = Process.spawn(@cmd)
45
- assert_equal(2, Process.kill(9, pid1, pid2))
46
- end
47
-
48
- test "kill accepts a string as a signal name" do
49
- pid = Process.spawn(@cmd)
50
- assert_nothing_raised{ Process.kill('SIGKILL', pid) }
51
- end
52
-
53
- test "kill accepts a string without 'SIG' as a signal name" do
54
- pid = Process.spawn(@cmd)
55
- assert_nothing_raised{ Process.kill('KILL', pid) }
56
- end
57
-
58
- test "kill accepts a symbol as a signal name" do
59
- pid = Process.spawn(@cmd)
60
- assert_nothing_raised{ Process.kill(:KILL, pid) }
61
- end
62
-
63
- test "kill coerces the pid to an integer" do
64
- pid = Process.pid.to_f + 0.7
65
- assert_nothing_raised{ Process.kill(0, pid) }
66
- end
67
-
68
- test "an EINVAL error is raised on Windows if the signal is negative" do
69
- @pid = Process.spawn(@cmd)
70
- assert_raise(Errno::EINVAL){ Process.kill(-3, @pid) }
71
- end
72
-
73
- test "an EINVAL error is raised on Windows if the pid is 0 and it's not a SIGINT" do
74
- assert_raise(Errno::EINVAL){ Process.kill(9, 0) }
75
- end
76
-
77
- test "kill accepts BRK or SIGBRK as a signal name" do
78
- pid = Process.spawn(@cmd)
79
- assert_nothing_raised{ Process.kill(:BRK, pid) }
80
- assert_nothing_raised{ Process.kill(:SIGBRK, pid) }
81
- end
82
-
83
- # We break from the spec here.
84
- #test "an EINVAL error is raised if the pid is the current process and it's not a 0 or SIGKILL" do
85
- # assert_raise(Errno::EINVAL){ Process.kill(1, Process.pid) }
86
- #end
87
-
88
- test "kill requires at least two arguments" do
89
- assert_raise(ArgumentError){ Process.kill }
90
- assert_raise(ArgumentError){ Process.kill(@pid) }
91
- end
92
-
93
- test "the first argument to kill must be an integer or string" do
94
- assert_raise(ArgumentError){ Process.kill([], 0) }
95
- end
96
-
97
- test "kill raises an ArgumentError if the signal name is invalid" do
98
- assert_raise(ArgumentError){ Process.kill("BOGUS", 0) }
99
- end
100
-
101
- test "kill does not accept lowercase signal names" do
102
- assert_raise(ArgumentError){ Process.kill("kill", 0) }
103
- end
104
-
105
- test "kill raises an EINVAL error if the signal number is invalid" do
106
- assert_raise(Errno::EINVAL){ Process.kill(999999, 0) }
107
- end
108
-
109
- test "kill raises an TypeError if the pid value is not an integer" do
110
- assert_raise(TypeError){ Process.kill(0, "BOGUS") }
111
- end
112
-
113
- # TODO: Fix this
114
- #test "kill raises an EPERM if user does not have proper privileges" do
115
- # omit_if(Process.uid == 0)
116
- # assert_raise(Errno::EPERM){ Process.kill(9, 1) }
117
- #end
118
-
119
- test "kill raises a SecurityError if $SAFE level is 2 or greater" do
120
- omit_if(@ruby == 'jruby')
121
- assert_raise(SecurityError){
122
- proc do
123
- $SAFE = 2
124
- @pid = Process.spawn(@cmd)
125
- Process.kill(9, @pid)
126
- end.call
127
- }
128
- end
129
-
130
- test "kill works if the $SAFE level is 1 or lower" do
131
- omit_if(@ruby == 'jruby')
132
- assert_nothing_raised{
133
- proc do
134
- $SAFE = 1
135
- @pid = Process.spawn(@cmd)
136
- Process.kill(9, @pid)
137
- end.call
138
- }
139
- end
140
-
141
- =begin
142
- test "kill(0) can't tell if the process ended, use get_exitcode instead" do
143
- pid = Process.create(
144
- :app_name => 'cmd /c exit 0',
145
- :creation_flags => Process::DETACHED_PROCESS
146
- ).process_id
147
- 10.times do
148
- sleep(0.1)
149
- assert_nothing_raised do
150
- assert_equal 1, Process.kill(0, pid)
151
- end
152
- end
153
- end
154
- =end
155
-
156
- def teardown
157
- @cmd = nil
158
- @ruby = nil
159
- Process.kill(9, @pid) if @pid rescue nil
160
- end
161
-
162
- def self.teardown
163
- @@signals = nil
164
- end
165
- end
1
+ ########################################################################
2
+ # test_win32_process_kill.rb
3
+ #
4
+ # Tests for the custom Process.kill method
5
+ ########################################################################
6
+ require 'win32/process'
7
+ require 'test-unit'
8
+
9
+ class TC_Win32_Process_Kill < Test::Unit::TestCase
10
+ def self.startup
11
+ @@signals = Signal.list
12
+ end
13
+
14
+ def setup
15
+ @ruby = RUBY_PLATFORM == 'java' ? 'jruby' : 'ruby'
16
+ @cmd = "#{@ruby} -e 'sleep 10'"
17
+ @pid = nil
18
+ end
19
+
20
+ test "kill basic functionality" do
21
+ assert_respond_to(Process, :kill)
22
+ end
23
+
24
+ test "kill with signal 0 does not actually send a signal" do
25
+ assert_nothing_raised{ Process.kill(0, Process.pid) }
26
+ end
27
+
28
+ test "kill with signal 0 returns 1 if the process exists" do
29
+ assert_equal(1, Process.kill(0, Process.pid))
30
+ end
31
+
32
+ test "kill with signal 0 raises an ESRCH error if any process does not exist" do
33
+ assert_raise(Errno::ESRCH){ Process.kill(0, 99999999) }
34
+ assert_raise(Errno::ESRCH){ Process.kill(0, Process.pid, 99999999) }
35
+ end
36
+
37
+ test "kill accepts multiple pid values" do
38
+ pid = Process.pid
39
+ assert_nothing_raised{ Process.kill(0, pid, pid, pid, pid) }
40
+ end
41
+
42
+ test "kill with any signal returns the number of killed processes" do
43
+ pid1 = Process.spawn(@cmd)
44
+ pid2 = Process.spawn(@cmd)
45
+ assert_equal(2, Process.kill(9, pid1, pid2))
46
+ end
47
+
48
+ test "kill accepts a string as a signal name" do
49
+ pid = Process.spawn(@cmd)
50
+ assert_nothing_raised{ Process.kill('SIGKILL', pid) }
51
+ end
52
+
53
+ test "kill accepts a string without 'SIG' as a signal name" do
54
+ pid = Process.spawn(@cmd)
55
+ assert_nothing_raised{ Process.kill('KILL', pid) }
56
+ end
57
+
58
+ test "kill accepts a symbol as a signal name" do
59
+ pid = Process.spawn(@cmd)
60
+ assert_nothing_raised{ Process.kill(:KILL, pid) }
61
+ end
62
+
63
+ test "kill coerces the pid to an integer" do
64
+ pid = Process.pid.to_f + 0.7
65
+ assert_nothing_raised{ Process.kill(0, pid) }
66
+ end
67
+
68
+ test "an EINVAL error is raised on Windows if the signal is negative" do
69
+ @pid = Process.spawn(@cmd)
70
+ assert_raise(Errno::EINVAL){ Process.kill(-3, @pid) }
71
+ end
72
+
73
+ test "an EINVAL error is raised on Windows if the pid is 0 and it's not a SIGINT" do
74
+ assert_raise(Errno::EINVAL){ Process.kill(9, 0) }
75
+ end
76
+
77
+ test "kill accepts BRK or SIGBRK as a signal name" do
78
+ pid = Process.spawn(@cmd)
79
+ assert_nothing_raised{ Process.kill(:BRK, pid) }
80
+ assert_nothing_raised{ Process.kill(:SIGBRK, pid) }
81
+ end
82
+
83
+ # We break from the spec here.
84
+ #test "an EINVAL error is raised if the pid is the current process and it's not a 0 or SIGKILL" do
85
+ # assert_raise(Errno::EINVAL){ Process.kill(1, Process.pid) }
86
+ #end
87
+
88
+ test "kill requires at least two arguments" do
89
+ assert_raise(ArgumentError){ Process.kill }
90
+ assert_raise(ArgumentError){ Process.kill(@pid) }
91
+ end
92
+
93
+ test "the first argument to kill must be an integer or string" do
94
+ assert_raise(ArgumentError){ Process.kill([], 0) }
95
+ end
96
+
97
+ test "kill raises an ArgumentError if the signal name is invalid" do
98
+ assert_raise(ArgumentError){ Process.kill("BOGUS", 0) }
99
+ end
100
+
101
+ test "kill does not accept lowercase signal names" do
102
+ assert_raise(ArgumentError){ Process.kill("kill", 0) }
103
+ end
104
+
105
+ test "kill raises an EINVAL error if the signal number is invalid" do
106
+ assert_raise(Errno::EINVAL){ Process.kill(999999, 0) }
107
+ end
108
+
109
+ test "kill raises an TypeError if the pid value is not an integer" do
110
+ assert_raise(TypeError){ Process.kill(0, "BOGUS") }
111
+ end
112
+
113
+ # TODO: Fix this
114
+ #test "kill raises an EPERM if user does not have proper privileges" do
115
+ # omit_if(Process.uid == 0)
116
+ # assert_raise(Errno::EPERM){ Process.kill(9, 1) }
117
+ #end
118
+
119
+ test "kill raises a SecurityError if $SAFE level is 2 or greater" do
120
+ omit_if(@ruby == 'jruby')
121
+ assert_raise(SecurityError){
122
+ proc do
123
+ $SAFE = 2
124
+ @pid = Process.spawn(@cmd)
125
+ Process.kill(9, @pid)
126
+ end.call
127
+ }
128
+ end
129
+
130
+ test "kill works if the $SAFE level is 1 or lower" do
131
+ omit_if(@ruby == 'jruby')
132
+ assert_nothing_raised{
133
+ proc do
134
+ $SAFE = 1
135
+ @pid = Process.spawn(@cmd)
136
+ Process.kill(9, @pid)
137
+ end.call
138
+ }
139
+ end
140
+
141
+ =begin
142
+ test "kill(0) can't tell if the process ended, use get_exitcode instead" do
143
+ pid = Process.create(
144
+ :app_name => 'cmd /c exit 0',
145
+ :creation_flags => Process::DETACHED_PROCESS
146
+ ).process_id
147
+ 10.times do
148
+ sleep(0.1)
149
+ assert_nothing_raised do
150
+ assert_equal 1, Process.kill(0, pid)
151
+ end
152
+ end
153
+ end
154
+ =end
155
+
156
+ def teardown
157
+ @cmd = nil
158
+ @ruby = nil
159
+ Process.kill(9, @pid) if @pid rescue nil
160
+ end
161
+
162
+ def self.teardown
163
+ @@signals = nil
164
+ end
165
+ end
@@ -1,29 +1,29 @@
1
- require 'rubygems'
2
-
3
- Gem::Specification.new do |spec|
4
- spec.name = 'win32-process'
5
- spec.version = '0.8.1'
6
- spec.license = 'Artistic 2.0'
7
- spec.authors = ['Daniel Berger', 'Park Heesob']
8
- spec.email = 'djberg96@gmail.com'
9
- spec.homepage = 'https://github.com/djberg96/win32-process'
10
- spec.summary = 'Adds and redefines several Process methods for MS Windows'
11
- spec.test_files = Dir['test/*.rb']
12
- spec.files = Dir['**/*'].reject{ |f| f.include?('git') }
13
- spec.cert_chain = ['certs/djberg96_pub.pem']
14
-
15
- spec.extra_rdoc_files = ['README', 'CHANGES', 'MANIFEST']
16
-
17
- spec.required_ruby_version = '> 1.9.0'
18
- spec.add_dependency('ffi', '>= 1.0.0')
19
-
20
- spec.add_development_dependency('rake')
21
- spec.add_development_dependency('test-unit', '>= 2.4.0')
22
-
23
- spec.description = <<-EOF
24
- The win32-process library implements several Process methods that are
25
- either unimplemented or dysfunctional in some way in the default Ruby
26
- implementation. Examples include Process.kill, Process.uid and
27
- Process.create.
28
- EOF
29
- end
1
+ require 'rubygems'
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = 'win32-process'
5
+ spec.version = '0.8.2'
6
+ spec.license = 'Artistic 2.0'
7
+ spec.authors = ['Daniel Berger', 'Park Heesob']
8
+ spec.email = 'djberg96@gmail.com'
9
+ spec.homepage = 'https://github.com/djberg96/win32-process'
10
+ spec.summary = 'Adds and redefines several Process methods for MS Windows'
11
+ spec.test_files = Dir['test/*.rb']
12
+ spec.files = Dir['**/*'].reject{ |f| f.include?('git') }
13
+ spec.cert_chain = ['certs/djberg96_pub.pem']
14
+
15
+ spec.extra_rdoc_files = ['README', 'CHANGES', 'MANIFEST']
16
+
17
+ spec.required_ruby_version = '> 1.9.0'
18
+ spec.add_dependency('ffi', '>= 1.0.0')
19
+
20
+ spec.add_development_dependency('rake')
21
+ spec.add_development_dependency('test-unit', '>= 2.4.0')
22
+
23
+ spec.description = <<-EOF
24
+ The win32-process library implements several Process methods that are
25
+ either unimplemented or dysfunctional in some way in the default Ruby
26
+ implementation. Examples include Process.kill, Process.uid and
27
+ Process.create.
28
+ EOF
29
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: win32-process
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.1
4
+ version: 0.8.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Berger
@@ -31,7 +31,7 @@ cert_chain:
31
31
  EJYzxdPOrx2n6NYR3Hk+vHP0U7UBSveI6+qx+ndQYaeyCn+GRX2PKS9h66YF/Q1V
32
32
  tGSHgAmcLlkdGgan182qsE/4kKM=
33
33
  -----END CERTIFICATE-----
34
- date: 2015-09-03 00:00:00.000000000 Z
34
+ date: 2015-10-15 00:00:00.000000000 Z
35
35
  dependencies:
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: ffi
@@ -124,7 +124,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
124
124
  version: '0'
125
125
  requirements: []
126
126
  rubyforge_project:
127
- rubygems_version: 2.4.5
127
+ rubygems_version: 2.4.8
128
128
  signing_key:
129
129
  specification_version: 4
130
130
  summary: Adds and redefines several Process methods for MS Windows
metadata.gz.sig CHANGED
Binary file