win32-process 0.6.2 → 0.6.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,179 +1,207 @@
1
- ###############################################################################
2
- # test_win32_process.rb
3
- #
4
- # Test suite for the win32-process library. This test suite will start
5
- # at least two instances of Notepad on your system, which will then
6
- # be killed. Requires the sys-proctable library.
7
- #
8
- # I haven't added a lot of test cases for fork/wait because it's difficult
9
- # to run such tests without causing havoc with Test::Unit itself. Ideas
10
- # welcome.
11
- #
12
- # You should run this test case via the 'rake test' task.
13
- ###############################################################################
14
- require 'rubygems'
15
- gem 'test-unit'
16
-
17
- require 'test/unit'
18
- require 'win32/process'
19
- require 'sys/proctable'
20
- include Sys
21
-
22
- class TC_Win32Process < Test::Unit::TestCase
23
-
24
- # Start two instances of notepad and give them a chance to fire up
25
- def self.startup
26
- IO.popen('notepad')
27
- IO.popen('notepad')
28
- sleep 1 # Give the notepad instances a second to startup
29
-
30
- @@pids = []
31
-
32
- ProcTable.ps{ |struct|
33
- next unless struct.comm =~ /notepad/i
34
- @@pids << struct.pid
35
- }
36
- end
37
-
38
- def setup
39
- @pid = nil
40
- @pri_class = Process::NORMAL_PRIORITY_CLASS
41
- end
42
-
43
- def test_version
44
- assert_equal('0.6.2', Process::WIN32_PROCESS_VERSION)
45
- end
46
-
47
- def test_kill
48
- assert_respond_to(Process, :kill)
49
- end
50
-
51
- def test_kill_expected_errors
52
- assert_raises(ArgumentError){ Process.kill }
53
- assert_raises(Process::Error){ Process.kill('SIGBOGUS') }
54
- assert_raises(Process::Error){ Process.kill(0, 9999999) }
55
- end
56
-
57
- def test_kill_signal_0
58
- pid = @@pids.first
59
- assert_nothing_raised{ Process.kill(0, pid) }
60
- end
61
-
62
- def test_kill_signal_1
63
- pid = @@pids.shift
64
- assert_nothing_raised{ Process.kill(1, pid) }
65
- end
66
-
67
- def test_kill_signal_9
68
- pid = @@pids.pop
69
- msg = "Could not find pid #{pid}"
70
- assert_nothing_raised(msg){ Process.kill(9, pid) }
71
- end
72
-
73
- def test_fork
74
- assert_respond_to(Process, :fork)
75
- end
76
-
77
- def test_create
78
- assert_respond_to(Process, :create)
79
-
80
- assert_nothing_raised{
81
- @pid = Process.create(
82
- :app_name => "notepad.exe",
83
- :creation_flags => Process::DETACHED_PROCESS,
84
- :process_inherit => false,
85
- :thread_inherit => true,
86
- :cwd => "C:\\"
87
- ).process_id
88
- }
89
-
90
- assert_nothing_raised{ Process.kill(1, @pid) }
91
- end
92
-
93
- def test_create_expected_errors
94
- assert_raises(TypeError){ Process.create("bogusapp.exe") }
95
- assert_raises(Process::Error){
96
- Process.create(:app_name => "bogusapp.exe")
97
- }
98
- end
99
-
100
- def test_wait
101
- assert_respond_to(Process, :wait)
102
- end
103
-
104
- def test_wait2
105
- assert_respond_to(Process, :wait2)
106
- end
107
-
108
- def test_waitpid
109
- assert_respond_to(Process, :waitpid)
110
- end
111
-
112
- def test_waitpid2
113
- assert_respond_to(Process, :waitpid2)
114
- end
115
-
116
- def test_ppid
117
- assert_respond_to(Process, :ppid)
118
- assert_equal(true, Process.ppid > 0)
119
- assert_equal(false, Process.pid == Process.ppid)
120
- end
121
-
122
- def test_uid
123
- assert_respond_to(Process, :uid)
124
- assert_kind_of(Fixnum, Process.uid)
125
- assert_kind_of(String, Process.uid(true))
126
- end
127
-
128
- def test_getpriority
129
- assert_respond_to(Process, :getpriority)
130
- assert_nothing_raised{ Process.getpriority(nil, Process.pid) }
131
- assert_kind_of(Fixnum, Process.getpriority(nil, Process.pid))
132
- end
133
-
134
- def test_getpriority_expected_errors
135
- assert_raise{ Process.getpriority }
136
- assert_raise{ Process.getpriority(nil) }
137
- end
138
-
139
- def test_setpriority
140
- assert_respond_to(Process, :setpriority)
141
- assert_nothing_raised{ Process.setpriority(nil, Process.pid, @pri_class) }
142
- assert_equal(0, Process.setpriority(nil, Process.pid, @pri_class))
143
- end
144
-
145
- def test_setpriority_expected_errors
146
- assert_raise{ Process.setpriority }
147
- assert_raise{ Process.setpriority(nil) }
148
- assert_raise{ Process.setpriority(nil, Process.pid) }
149
- end
150
-
151
- def test_creation_constants
152
- assert_not_nil(Process::CREATE_DEFAULT_ERROR_MODE)
153
- assert_not_nil(Process::CREATE_NEW_CONSOLE)
154
- assert_not_nil(Process::CREATE_NEW_PROCESS_GROUP)
155
- assert_not_nil(Process::CREATE_NO_WINDOW)
156
- assert_not_nil(Process::CREATE_SEPARATE_WOW_VDM)
157
- assert_not_nil(Process::CREATE_SHARED_WOW_VDM)
158
- assert_not_nil(Process::CREATE_SUSPENDED)
159
- assert_not_nil(Process::CREATE_UNICODE_ENVIRONMENT)
160
- assert_not_nil(Process::DEBUG_ONLY_THIS_PROCESS)
161
- assert_not_nil(Process::DEBUG_PROCESS)
162
- assert_not_nil(Process::DETACHED_PROCESS)
163
- end
164
-
165
- def test_getrlimit
166
- assert_respond_to(Process, :getrlimit)
167
- assert_nothing_raised{ Process.getrlimit(Process::RLIMIT_CPU) }
168
- assert_kind_of(Array, Process.getrlimit(Process::RLIMIT_CPU))
169
- assert_equal(2, Process.getrlimit(Process::RLIMIT_CPU).length)
170
- end
171
-
172
- def teardown
173
- @pid = nil
174
- end
175
-
176
- def self.shutdown
177
- @@pids = []
178
- end
179
- end
1
+ ###############################################################################
2
+ # test_win32_process.rb
3
+ #
4
+ # Test suite for the win32-process library. This test suite will start
5
+ # at least two instances of Notepad on your system, which will then
6
+ # be killed. Requires the sys-proctable library.
7
+ #
8
+ # I haven't added a lot of test cases for fork/wait because it's difficult
9
+ # to run such tests without causing havoc with Test::Unit itself. Ideas
10
+ # welcome.
11
+ #
12
+ # You should run this test case via the 'rake test' task.
13
+ ###############################################################################
14
+ require 'rubygems'
15
+ gem 'test-unit'
16
+
17
+ require 'test/unit'
18
+ require 'win32/process'
19
+ require 'sys/proctable'
20
+ include Sys
21
+
22
+ class TC_Win32Process < Test::Unit::TestCase
23
+
24
+ # Start two instances of notepad and give them a chance to fire up
25
+ def self.startup
26
+ IO.popen('notepad')
27
+ IO.popen('notepad')
28
+ sleep 1 # Give the notepad instances a second to startup
29
+
30
+ @@pids = []
31
+
32
+ ProcTable.ps{ |struct|
33
+ next unless struct.comm =~ /notepad/i
34
+ @@pids << struct.pid
35
+ }
36
+ end
37
+
38
+ def setup
39
+ @pid = nil
40
+ @pri_class = Process::NORMAL_PRIORITY_CLASS
41
+ end
42
+
43
+ def test_version
44
+ assert_equal('0.6.3', Process::WIN32_PROCESS_VERSION)
45
+ end
46
+
47
+ def test_kill
48
+ assert_respond_to(Process, :kill)
49
+ end
50
+
51
+ def test_kill_expected_errors
52
+ assert_raises(ArgumentError){ Process.kill }
53
+ assert_raises(Process::Error){ Process.kill('SIGBOGUS') }
54
+ assert_raises(Process::Error){ Process.kill(0, 9999999) }
55
+ end
56
+
57
+ def test_kill_signal_0
58
+ pid = @@pids.first
59
+ assert_nothing_raised{ Process.kill(0, pid) }
60
+ end
61
+
62
+ def test_kill_signal_1
63
+ pid = @@pids.shift
64
+ assert_nothing_raised{ Process.kill(1, pid) }
65
+ end
66
+
67
+ def test_kill_signal_9
68
+ pid = @@pids.pop
69
+ msg = "Could not find pid #{pid}"
70
+ assert_nothing_raised(msg){ Process.kill(9, pid) }
71
+ end
72
+
73
+ def test_fork
74
+ assert_respond_to(Process, :fork)
75
+ end
76
+
77
+ def test_create
78
+ assert_respond_to(Process, :create)
79
+ assert_nothing_raised{
80
+ @pid = Process.create(
81
+ :app_name => "notepad.exe",
82
+ :creation_flags => Process::DETACHED_PROCESS,
83
+ :process_inherit => false,
84
+ :thread_inherit => true,
85
+ :cwd => "C:\\"
86
+ ).process_id
87
+ }
88
+
89
+ assert_nothing_raised{ Process.kill(1, @pid) }
90
+ end
91
+
92
+ def test_create_expected_errors
93
+ assert_raises(TypeError){ Process.create("bogusapp.exe") }
94
+ assert_raises(Process::Error){ Process.create(:app_name => "bogusapp.exe") }
95
+ end
96
+
97
+ def test_wait
98
+ assert_respond_to(Process, :wait)
99
+ end
100
+
101
+ def test_wait2
102
+ assert_respond_to(Process, :wait2)
103
+ end
104
+
105
+ def test_waitpid
106
+ assert_respond_to(Process, :waitpid)
107
+ end
108
+
109
+ def test_waitpid2
110
+ assert_respond_to(Process, :waitpid2)
111
+ end
112
+
113
+ def test_ppid
114
+ assert_respond_to(Process, :ppid)
115
+ assert_equal(true, Process.ppid > 0)
116
+ assert_equal(false, Process.pid == Process.ppid)
117
+ end
118
+
119
+ def test_uid
120
+ assert_respond_to(Process, :uid)
121
+ assert_kind_of(Fixnum, Process.uid)
122
+ assert_kind_of(String, Process.uid(true))
123
+ end
124
+
125
+ def test_getpriority
126
+ assert_respond_to(Process, :getpriority)
127
+ assert_nothing_raised{ Process.getpriority(nil, Process.pid) }
128
+ assert_kind_of(Fixnum, Process.getpriority(nil, Process.pid))
129
+ end
130
+
131
+ def test_getpriority_expected_errors
132
+ assert_raise{ Process.getpriority }
133
+ assert_raise{ Process.getpriority(nil) }
134
+ end
135
+
136
+ def test_setpriority
137
+ assert_respond_to(Process, :setpriority)
138
+ assert_nothing_raised{ Process.setpriority(nil, Process.pid, @pri_class) }
139
+ assert_equal(0, Process.setpriority(nil, Process.pid, @pri_class))
140
+ end
141
+
142
+ def test_setpriority_expected_errors
143
+ assert_raise{ Process.setpriority }
144
+ assert_raise{ Process.setpriority(nil) }
145
+ assert_raise{ Process.setpriority(nil, Process.pid) }
146
+ end
147
+
148
+ def test_creation_constants
149
+ assert_not_nil(Process::CREATE_DEFAULT_ERROR_MODE)
150
+ assert_not_nil(Process::CREATE_NEW_CONSOLE)
151
+ assert_not_nil(Process::CREATE_NEW_PROCESS_GROUP)
152
+ assert_not_nil(Process::CREATE_NO_WINDOW)
153
+ assert_not_nil(Process::CREATE_SEPARATE_WOW_VDM)
154
+ assert_not_nil(Process::CREATE_SHARED_WOW_VDM)
155
+ assert_not_nil(Process::CREATE_SUSPENDED)
156
+ assert_not_nil(Process::CREATE_UNICODE_ENVIRONMENT)
157
+ assert_not_nil(Process::DEBUG_ONLY_THIS_PROCESS)
158
+ assert_not_nil(Process::DEBUG_PROCESS)
159
+ assert_not_nil(Process::DETACHED_PROCESS)
160
+ end
161
+
162
+ def test_getrlimit
163
+ assert_respond_to(Process, :getrlimit)
164
+ assert_nothing_raised{ Process.getrlimit(Process::RLIMIT_CPU) }
165
+ assert_kind_of(Array, Process.getrlimit(Process::RLIMIT_CPU))
166
+ assert_equal(2, Process.getrlimit(Process::RLIMIT_CPU).length)
167
+ end
168
+
169
+ def test_getrlimit_can_be_called_multiple_times
170
+ assert_nothing_raised{ Process.getrlimit(Process::RLIMIT_CPU) }
171
+ assert_nothing_raised{ Process.getrlimit(Process::RLIMIT_CPU) }
172
+ assert_nothing_raised{ Process.getrlimit(Process::RLIMIT_CPU) }
173
+ end
174
+
175
+ def test_getrlimit_raises_an_error_if_the_resource_is_invalid
176
+ assert_raise(Process::Error){ Process.getrlimit(9999) }
177
+ end
178
+
179
+ def test_setrlimit_basic
180
+ assert_respond_to(Process, :getrlimit)
181
+ assert_nothing_raised{ Process.setrlimit(Process::RLIMIT_VMEM, 1024 * 4) }
182
+ assert_nil(Process.setrlimit(Process::RLIMIT_VMEM, 1024 * 4))
183
+ end
184
+
185
+ def test_setrlimit_sets_the_resource_as_expected
186
+ assert_nothing_raised{ Process.setrlimit(Process::RLIMIT_VMEM, 1024 * 4) }
187
+ assert_equal([4096, 4096], Process.getrlimit(Process::RLIMIT_VMEM))
188
+ end
189
+
190
+ def test_setrlimit_raises_an_error_if_the_resource_is_invalid
191
+ assert_raise(Process::Error){ Process.setrlimit(9999, 100) }
192
+ end
193
+
194
+ def test_is_job
195
+ assert_respond_to(Process, :job?)
196
+ assert_nothing_raised{ Process.job? }
197
+ assert_boolean(Process.job?)
198
+ end
199
+
200
+ def teardown
201
+ @pid = nil
202
+ end
203
+
204
+ def self.shutdown
205
+ @@pids = []
206
+ end
207
+ end
@@ -1,29 +1,29 @@
1
- require 'rubygems'
2
-
3
- spec = Gem::Specification.new do |gem|
4
- gem.name = 'win32-process'
5
- gem.version = '0.6.2'
6
- gem.license = 'Artistic 2.0'
7
- gem.authors = ['Daniel Berger', 'Park Heesob']
8
- gem.email = 'djberg96@gmail.com'
9
- gem.homepage = 'http://www.rubyforge.org/projects/win32utils'
10
- gem.platform = Gem::Platform::RUBY
11
- gem.summary = 'Adds and redefines several Process methods for MS Windows'
12
- gem.test_files = Dir['test/*.rb']
13
- gem.has_rdoc = true
14
- gem.files = Dir['**/*'].reject{ |f| f.include?('CVS') }
15
-
16
- gem.rubyforge_project = 'win32utils'
17
- gem.extra_rdoc_files = ['README', 'CHANGES', 'MANIFEST']
18
-
19
- gem.add_dependency('windows-pr', '>= 1.0.5')
20
- gem.add_development_dependency('test-unit', '>= 2.0.3')
21
- gem.add_development_dependency('sys-proctable')
22
-
23
- gem.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.waitpid,
27
- Process.create and an experimental Process.fork method.
28
- EOF
29
- end
1
+ require 'rubygems'
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = 'win32-process'
5
+ spec.version = '0.6.3'
6
+ spec.license = 'Artistic 2.0'
7
+ spec.authors = ['Daniel Berger', 'Park Heesob']
8
+ spec.email = 'djberg96@gmail.com'
9
+ spec.homepage = 'http://www.rubyforge.org/projects/win32utils'
10
+ spec.platform = Gem::Platform::RUBY
11
+ spec.summary = 'Adds and redefines several Process methods for MS Windows'
12
+ spec.test_files = Dir['test/*.rb']
13
+ spec.has_rdoc = true
14
+ spec.files = Dir['**/*'].reject{ |f| f.include?('git') }
15
+
16
+ spec.rubyforge_project = 'win32utils'
17
+ spec.extra_rdoc_files = ['README', 'CHANGES', 'MANIFEST']
18
+
19
+ spec.add_dependency('windows-pr', '>= 1.1.0')
20
+ spec.add_development_dependency('test-unit', '>= 2.1.1')
21
+ spec.add_development_dependency('sys-proctable')
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.waitpid,
27
+ Process.create and an experimental Process.fork method.
28
+ EOF
29
+ end
metadata CHANGED
@@ -1,7 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: win32-process
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.2
4
+ hash: 1
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 6
9
+ - 3
10
+ version: 0.6.3
5
11
  platform: ruby
6
12
  authors:
7
13
  - Daniel Berger
@@ -10,39 +16,55 @@ autorequire:
10
16
  bindir: bin
11
17
  cert_chain: []
12
18
 
13
- date: 2009-12-19 00:00:00 -07:00
19
+ date: 2010-11-09 00:00:00 -07:00
14
20
  default_executable:
15
21
  dependencies:
16
22
  - !ruby/object:Gem::Dependency
17
23
  name: windows-pr
18
- type: :runtime
19
- version_requirement:
20
- version_requirements: !ruby/object:Gem::Requirement
24
+ prerelease: false
25
+ requirement: &id001 !ruby/object:Gem::Requirement
26
+ none: false
21
27
  requirements:
22
28
  - - ">="
23
29
  - !ruby/object:Gem::Version
24
- version: 1.0.5
25
- version:
30
+ hash: 19
31
+ segments:
32
+ - 1
33
+ - 1
34
+ - 0
35
+ version: 1.1.0
36
+ type: :runtime
37
+ version_requirements: *id001
26
38
  - !ruby/object:Gem::Dependency
27
39
  name: test-unit
28
- type: :development
29
- version_requirement:
30
- version_requirements: !ruby/object:Gem::Requirement
40
+ prerelease: false
41
+ requirement: &id002 !ruby/object:Gem::Requirement
42
+ none: false
31
43
  requirements:
32
44
  - - ">="
33
45
  - !ruby/object:Gem::Version
34
- version: 2.0.3
35
- version:
46
+ hash: 9
47
+ segments:
48
+ - 2
49
+ - 1
50
+ - 1
51
+ version: 2.1.1
52
+ type: :development
53
+ version_requirements: *id002
36
54
  - !ruby/object:Gem::Dependency
37
55
  name: sys-proctable
38
- type: :development
39
- version_requirement:
40
- version_requirements: !ruby/object:Gem::Requirement
56
+ prerelease: false
57
+ requirement: &id003 !ruby/object:Gem::Requirement
58
+ none: false
41
59
  requirements:
42
60
  - - ">="
43
61
  - !ruby/object:Gem::Version
62
+ hash: 3
63
+ segments:
64
+ - 0
44
65
  version: "0"
45
- version:
66
+ type: :development
67
+ version_requirements: *id003
46
68
  description: " The win32-process library implements several Process methods that are\n either unimplemented or dysfunctional in some way in the default Ruby\n implementation. Examples include Process.kill, Process.waitpid,\n Process.create and an experimental Process.fork method.\n"
47
69
  email: djberg96@gmail.com
48
70
  executables: []
@@ -75,21 +97,27 @@ rdoc_options: []
75
97
  require_paths:
76
98
  - lib
77
99
  required_ruby_version: !ruby/object:Gem::Requirement
100
+ none: false
78
101
  requirements:
79
102
  - - ">="
80
103
  - !ruby/object:Gem::Version
104
+ hash: 3
105
+ segments:
106
+ - 0
81
107
  version: "0"
82
- version:
83
108
  required_rubygems_version: !ruby/object:Gem::Requirement
109
+ none: false
84
110
  requirements:
85
111
  - - ">="
86
112
  - !ruby/object:Gem::Version
113
+ hash: 3
114
+ segments:
115
+ - 0
87
116
  version: "0"
88
- version:
89
117
  requirements: []
90
118
 
91
119
  rubyforge_project: win32utils
92
- rubygems_version: 1.3.5
120
+ rubygems_version: 1.3.7
93
121
  signing_key:
94
122
  specification_version: 3
95
123
  summary: Adds and redefines several Process methods for MS Windows