win32-process 0.7.2 → 0.7.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,144 +1,159 @@
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
+ =begin
136
+ test "kill(0) can't tell if the process ended, use get_exitcode instead" do
137
+ pid = Process.create(
138
+ :app_name => 'cmd /c exit 0',
139
+ :creation_flags => Process::DETACHED_PROCESS
140
+ ).process_id
141
+ 10.times do
142
+ sleep(0.1)
143
+ assert_nothing_raised do
144
+ assert_equal 1, Process.kill(0, pid)
145
+ end
146
+ end
147
+ end
148
+ =end
149
+
150
+ def teardown
151
+ @cmd = nil
152
+ @ruby = nil
153
+ Process.kill(9, @pid) if @pid rescue nil
154
+ end
155
+
156
+ def self.teardown
157
+ @@signals = nil
158
+ end
159
+ 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.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
-
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.3'
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,8 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: win32-process
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.2
5
- prerelease:
4
+ version: 0.7.3
6
5
  platform: ruby
7
6
  authors:
8
7
  - Daniel Berger
@@ -10,43 +9,41 @@ authors:
10
9
  autorequire:
11
10
  bindir: bin
12
11
  cert_chain: []
13
- date: 2013-04-08 00:00:00.000000000 Z
12
+ date: 2013-09-25 00:00:00.000000000 Z
14
13
  dependencies:
15
14
  - !ruby/object:Gem::Dependency
16
15
  name: ffi
17
16
  requirement: !ruby/object:Gem::Requirement
18
- none: false
19
17
  requirements:
20
- - - ! '>='
18
+ - - '>='
21
19
  - !ruby/object:Gem::Version
22
20
  version: 1.0.0
23
21
  type: :runtime
24
22
  prerelease: false
25
23
  version_requirements: !ruby/object:Gem::Requirement
26
- none: false
27
24
  requirements:
28
- - - ! '>='
25
+ - - '>='
29
26
  - !ruby/object:Gem::Version
30
27
  version: 1.0.0
31
28
  - !ruby/object:Gem::Dependency
32
29
  name: test-unit
33
30
  requirement: !ruby/object:Gem::Requirement
34
- none: false
35
31
  requirements:
36
- - - ! '>='
32
+ - - '>='
37
33
  - !ruby/object:Gem::Version
38
34
  version: 2.4.0
39
35
  type: :development
40
36
  prerelease: false
41
37
  version_requirements: !ruby/object:Gem::Requirement
42
- none: false
43
38
  requirements:
44
- - - ! '>='
39
+ - - '>='
45
40
  - !ruby/object:Gem::Version
46
41
  version: 2.4.0
47
- description: ! " The win32-process library implements several Process methods that
48
- are\n either unimplemented or dysfunctional in some way in the default Ruby\n
49
- \ implementation. Examples include Process.kill, Process.uid and\n Process.create.\n"
42
+ description: |2
43
+ The win32-process library implements several Process methods that are
44
+ either unimplemented or dysfunctional in some way in the default Ruby
45
+ implementation. Examples include Process.kill, Process.uid and
46
+ Process.create.
50
47
  email: djberg96@gmail.com
51
48
  executables: []
52
49
  extensions: []
@@ -72,27 +69,26 @@ files:
72
69
  homepage: https://github.com/djberg96/win32-process
73
70
  licenses:
74
71
  - Artistic 2.0
72
+ metadata: {}
75
73
  post_install_message:
76
74
  rdoc_options: []
77
75
  require_paths:
78
76
  - lib
79
77
  required_ruby_version: !ruby/object:Gem::Requirement
80
- none: false
81
78
  requirements:
82
- - - ! '>'
79
+ - - '>'
83
80
  - !ruby/object:Gem::Version
84
81
  version: 1.9.0
85
82
  required_rubygems_version: !ruby/object:Gem::Requirement
86
- none: false
87
83
  requirements:
88
- - - ! '>='
84
+ - - '>='
89
85
  - !ruby/object:Gem::Version
90
86
  version: '0'
91
87
  requirements: []
92
88
  rubyforge_project: win32utils
93
- rubygems_version: 1.8.24
89
+ rubygems_version: 2.0.3
94
90
  signing_key:
95
- specification_version: 3
91
+ specification_version: 4
96
92
  summary: Adds and redefines several Process methods for MS Windows
97
93
  test_files:
98
94
  - test/test_win32_process.rb