Skip to content

Commit 2ff87e3

Browse files
committed
Readded long lost tests happened in 56e27dc
1 parent dbb271d commit 2ff87e3

2 files changed

Lines changed: 148 additions & 0 deletions

File tree

test/signal.rb

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# MIT License
2+
#
3+
# Permission is hereby granted, free of charge, to any person obtaining a copy
4+
# of this software and associated documentation files (the "Software"), to deal
5+
# in the Software without restriction, including without limitation the rights
6+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
# copies of the Software, and to permit persons to whom the Software is
8+
# furnished to do so, subject to the following conditions:
9+
10+
# The above copyright notice and this permission notice shall be included in all
11+
# copies or substantial portions of the Software.
12+
13+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19+
# SOFTWARE.
20+
21+
assert('Signal') do
22+
assert_kind_of Module, Signal
23+
end
24+
25+
assert('Signal.signame') do
26+
assert_equal Signal.signame(2), 'INT'
27+
assert_equal Signal.signame(9), 'KILL'
28+
assert_equal Signal.signame(0), 'EXIT'
29+
assert_nil Signal.signame(-1)
30+
end
31+
32+
assert('Signal.list') do
33+
assert_kind_of Hash, Signal.list
34+
assert_true Signal.list.any?, 'no signals found'
35+
end

test/status.rb

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
# MIT License
2+
#
3+
# Permission is hereby granted, free of charge, to any person obtaining a copy
4+
# of this software and associated documentation files (the "Software"), to deal
5+
# in the Software without restriction, including without limitation the rights
6+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
# copies of the Software, and to permit persons to whom the Software is
8+
# furnished to do so, subject to the following conditions:
9+
10+
# The above copyright notice and this permission notice shall be included in all
11+
# copies or substantial portions of the Software.
12+
13+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19+
# SOFTWARE.
20+
21+
def assert_not_windows(*args, &block)
22+
assert(*args, &block) if OS.posix?
23+
end
24+
25+
def spawn_and_wait(cmd = 'exit 0')
26+
Process.waitpid2(spawn(cmd))
27+
end
28+
29+
assert('$?') do
30+
_, st = spawn_and_wait
31+
32+
assert_kind_of Process::Status, $?
33+
assert_equal st, $?
34+
end
35+
36+
assert('$CHILD_STATUS') do
37+
spawn_and_wait
38+
39+
assert_kind_of Process::Status, $CHILD_STATUS
40+
assert_equal $?, $CHILD_STATUS
41+
end
42+
43+
assert('Process::Status#pid') do
44+
pid, st = spawn_and_wait
45+
46+
assert_equal pid, st.pid
47+
end
48+
49+
assert('Process::Status#==') do
50+
_, st1 = spawn_and_wait
51+
_, st2 = spawn_and_wait
52+
53+
assert_equal st1, st2
54+
end
55+
56+
assert('Process::Status#>>') do
57+
spawn_and_wait 'exit 99'
58+
59+
assert_equal 99, $? >> 8
60+
end
61+
62+
# assert('Process::Status#coredump?')
63+
64+
assert('Process::Status#exited?') do
65+
spawn_and_wait
66+
67+
assert_true $?.exited?
68+
end
69+
70+
assert('Process::Status#exitstatus') do
71+
spawn_and_wait 'exit 42'
72+
73+
assert_equal 42, $?.exitstatus
74+
end
75+
76+
assert_not_windows('Process::Status#signaled? and #termsig') do
77+
pid = fork
78+
79+
sleep 10 unless pid
80+
Process.kill 15, pid
81+
82+
_, st = Process.waitpid2(pid)
83+
84+
assert_true st.signaled?
85+
assert_equal 15, st.termsig
86+
end
87+
88+
# assert('Process::Status#stopped and #stopsig')
89+
90+
assert('Process::Status#success?') do
91+
spawn_and_wait 'exit 42'
92+
93+
assert_true $?.exited?
94+
assert_equal 42, $?.exitstatus
95+
end
96+
97+
assert('Process::Status#to_i') do
98+
assert_kind_of Integer, $?.to_i
99+
assert_kind_of Integer, $?.to_int
100+
assert_equal $?.to_i, $?.to_int
101+
end
102+
103+
assert('Process::Status#to_s') do
104+
pid, = spawn_and_wait
105+
106+
assert_equal "pid #{pid} exit 0", $?.to_s
107+
end
108+
109+
assert('Process::Status#inspect') do
110+
pid, = spawn_and_wait
111+
112+
assert_equal "#<Process::Status: pid #{pid} exit 0>", $?.inspect
113+
end

0 commit comments

Comments
 (0)