-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathtest_error_lifecycle.rb
119 lines (99 loc) · 3.22 KB
/
test_error_lifecycle.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
require 'test/unit'
require 'timeout'
require 'thread'
class TestTimeout < Test::Unit::TestCase
### Tests demonstrating problems with standard lib
# NOTE: this demonstration was done such that all of the assertions pass,
# The ones marked weird, bad, and very bad should not, and their
# passing is demonstrating the brokenness.
# ruby gem at 0f12a0ec11d4a860a56e74a2bb051a77fe70b006 also passes
require_relative 'lib/error_lifecycle.rb'
# when an exception to raise is not specified and the inner code does not catch Exception
def test_1
s = ErrorLifeCycleTester.new
s.subject(nil, StandardError)
# EXPECTED
assert s.inner_attempted
assert !s.inner_else
assert !s.inner_rescue
assert s.inner_ensure
assert s.outer_rescue
assert s.outer_ensure
assert s.inner_ensure_has_time_to_finish
assert s.outer_ensure_has_time_to_finish
end
# when an exception to raise is not specified and the inner code does catch Exception
def test_2
s = ErrorLifeCycleTester.new
s.subject(nil, Exception)
# EXPECTED
assert s.inner_attempted
assert !s.inner_else
assert s.inner_ensure
assert s.outer_ensure
assert s.inner_ensure_has_time_to_finish
assert s.outer_ensure_has_time_to_finish
assert s.inner_rescue # true in 1.9, false in gem 0.2.0, true in 0.4.0
# BAD?
assert !s.outer_rescue # false in 1.9 stdlib, true in gem 0.2.0, false in 0.4.0
end
# when an exception to raise is StandardError and the inner code does not catch Exception
def test_3
s = ErrorLifeCycleTester.new
s.subject(MyStandardError, StandardError)
# EXPECTED
assert s.inner_attempted
assert !s.inner_else
assert s.inner_rescue
assert s.inner_ensure
assert s.outer_ensure
assert s.inner_ensure_has_time_to_finish
assert s.outer_ensure_has_time_to_finish
# BAD?
assert !s.outer_rescue
end
# when an exception to raise is StandardError and the inner code does catch Exception
def test_4
s = ErrorLifeCycleTester.new
s.subject(MyStandardError, Exception)
# EXPECTED
assert s.inner_attempted
assert !s.inner_else
assert s.inner_rescue
assert s.inner_ensure
assert s.outer_ensure
assert s.inner_ensure_has_time_to_finish
assert s.outer_ensure_has_time_to_finish
# BAD?
assert !s.outer_rescue
end
# when an exception to raise is Exception and the inner code does not catch Exception
def test_5
s = ErrorLifeCycleTester.new
s.subject(MyException, StandardError)
# EXPECTED
assert s.inner_attempted
assert !s.inner_else
assert !s.inner_rescue
assert s.inner_ensure
assert s.outer_ensure
assert s.outer_rescue
assert s.inner_ensure_has_time_to_finish
assert s.outer_ensure_has_time_to_finish
end
# when an exception to raise is Exception and the inner code does catch Exception
def test_6
s = ErrorLifeCycleTester.new
s.subject(MyException, Exception)
# EXPECTED
assert s.inner_attempted
assert !s.inner_else
assert s.inner_rescue
assert s.inner_ensure
assert s.outer_ensure
assert s.inner_ensure_has_time_to_finish
assert s.outer_ensure_has_time_to_finish
# BAD?
assert !s.outer_rescue
end
end