win32-process 0.7.0 → 0.7.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,144 +1,144 @@
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
- # We break from the spec here.
78
- #test "an EINVAL error is raised if the pid is the current process and it's not a 0 or SIGKILL" do
79
- # assert_raise(Errno::EINVAL){ Process.kill(1, Process.pid) }
80
- #end
81
-
82
- test "kill requires at least two arguments" do
83
- assert_raise(ArgumentError){ Process.kill }
84
- assert_raise(ArgumentError){ Process.kill(@pid) }
85
- end
86
-
87
- test "the first argument to kill must be an integer or string" do
88
- assert_raise(ArgumentError){ Process.kill([], 0) }
89
- end
90
-
91
- test "kill raises an ArgumentError if the signal name is invalid" do
92
- assert_raise(ArgumentError){ Process.kill("BOGUS", 0) }
93
- end
94
-
95
- test "kill does not accept lowercase signal names" do
96
- assert_raise(ArgumentError){ Process.kill("kill", 0) }
97
- end
98
-
99
- test "kill raises an EINVAL error if the signal number is invalid" do
100
- assert_raise(Errno::EINVAL){ Process.kill(999999, 0) }
101
- end
102
-
103
- test "kill raises an TypeError if the pid value is not an integer" do
104
- assert_raise(TypeError){ Process.kill(0, "BOGUS") }
105
- end
106
-
107
- # TODO: Fix this
108
- #test "kill raises an EPERM if user does not have proper privileges" do
109
- # omit_if(Process.uid == 0)
110
- # assert_raise(Errno::EPERM){ Process.kill(9, 1) }
111
- #end
112
-
113
- test "kill raises a SecurityError if $SAFE level is 2 or greater" do
114
- omit_if(@ruby == 'jruby')
115
- assert_raise(SecurityError){
116
- proc do
117
- $SAFE = 2
118
- @pid = Process.spawn(@cmd)
119
- Process.kill(9, @pid)
120
- end.call
121
- }
122
- end
123
-
124
- test "kill works if the $SAFE level is 1 or lower" do
125
- omit_if(@ruby == 'jruby')
126
- assert_nothing_raised{
127
- proc do
128
- $SAFE = 1
129
- @pid = Process.spawn(@cmd)
130
- Process.kill(9, @pid)
131
- end.call
132
- }
133
- end
134
-
135
- def teardown
136
- @cmd = nil
137
- @ruby = nil
138
- Process.kill(9, @pid) if @pid rescue nil
139
- end
140
-
141
- def self.teardown
142
- @@signals = nil
143
- end
144
- 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
+ # We break from the spec here.
78
+ #test "an EINVAL error is raised if the pid is the current process and it's not a 0 or SIGKILL" do
79
+ # assert_raise(Errno::EINVAL){ Process.kill(1, Process.pid) }
80
+ #end
81
+
82
+ test "kill requires at least two arguments" do
83
+ assert_raise(ArgumentError){ Process.kill }
84
+ assert_raise(ArgumentError){ Process.kill(@pid) }
85
+ end
86
+
87
+ test "the first argument to kill must be an integer or string" do
88
+ assert_raise(ArgumentError){ Process.kill([], 0) }
89
+ end
90
+
91
+ test "kill raises an ArgumentError if the signal name is invalid" do
92
+ assert_raise(ArgumentError){ Process.kill("BOGUS", 0) }
93
+ end
94
+
95
+ test "kill does not accept lowercase signal names" do
96
+ assert_raise(ArgumentError){ Process.kill("kill", 0) }
97
+ end
98
+
99
+ test "kill raises an EINVAL error if the signal number is invalid" do
100
+ assert_raise(Errno::EINVAL){ Process.kill(999999, 0) }
101
+ end
102
+
103
+ test "kill raises an TypeError if the pid value is not an integer" do
104
+ assert_raise(TypeError){ Process.kill(0, "BOGUS") }
105
+ end
106
+
107
+ # TODO: Fix this
108
+ #test "kill raises an EPERM if user does not have proper privileges" do
109
+ # omit_if(Process.uid == 0)
110
+ # assert_raise(Errno::EPERM){ Process.kill(9, 1) }
111
+ #end
112
+
113
+ test "kill raises a SecurityError if $SAFE level is 2 or greater" do
114
+ omit_if(@ruby == 'jruby')
115
+ assert_raise(SecurityError){
116
+ proc do
117
+ $SAFE = 2
118
+ @pid = Process.spawn(@cmd)
119
+ Process.kill(9, @pid)
120
+ end.call
121
+ }
122
+ end
123
+
124
+ test "kill works if the $SAFE level is 1 or lower" do
125
+ omit_if(@ruby == 'jruby')
126
+ assert_nothing_raised{
127
+ proc do
128
+ $SAFE = 1
129
+ @pid = Process.spawn(@cmd)
130
+ Process.kill(9, @pid)
131
+ end.call
132
+ }
133
+ end
134
+
135
+ def teardown
136
+ @cmd = nil
137
+ @ruby = nil
138
+ Process.kill(9, @pid) if @pid rescue nil
139
+ end
140
+
141
+ def self.teardown
142
+ @@signals = nil
143
+ end
144
+ end
@@ -1,27 +1,27 @@
1
- require 'rubygems'
2
-
3
- Gem::Specification.new do |spec|
4
- spec.name = 'win32-process'
5
- spec.version = '0.7.0'
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
-
14
- spec.rubyforge_project = 'win32utils'
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
- spec.add_development_dependency('test-unit', '>= 2.4.0')
20
-
21
- spec.description = <<-EOF
22
- The win32-process library implements several Process methods that are
23
- either unimplemented or dysfunctional in some way in the default Ruby
24
- implementation. Examples include Process.kill, Process.uid and
25
- Process.create.
26
- EOF
27
- end
1
+ require 'rubygems'
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = 'win32-process'
5
+ spec.version = '0.7.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
+
14
+ spec.rubyforge_project = 'win32utils'
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
+ spec.add_development_dependency('test-unit', '>= 2.4.0')
20
+
21
+ spec.description = <<-EOF
22
+ The win32-process library implements several Process methods that are
23
+ either unimplemented or dysfunctional in some way in the default Ruby
24
+ implementation. Examples include Process.kill, Process.uid and
25
+ Process.create.
26
+ EOF
27
+ 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.7.0
4
+ version: 0.7.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-08-22 00:00:00.000000000 Z
13
+ date: 2013-01-03 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: ffi