-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_error_lifecycle.rb
86 lines (66 loc) · 2.52 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
require 'test/unit'
require_relative 'time_limit.rb'
class TestErrorLifecycle < Test::Unit::TestCase
# Behavior marked "UNDESIRED?" is done so as John's opinion, these can/should be removed before the PR is merged
require_relative 'error_lifecycle.rb'
def core_assertions(s)
assert s.inner_attempted
assert !s.inner_else
assert s.inner_ensure
assert s.outer_ensure
# This can result in user's expectation of total possible time
# being very wrong
# t = Time.now; Timeout.timeout(0.1){begin; sleep 1; ensure; sleep 2; end} rescue puts Time.now-t
# => 2.106306
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 not catch Exception
def test_1
s = ErrorLifeCycleTester.new
s.subject(nil, StandardError)
core_assertions(s)
assert !s.inner_rescue
assert s.outer_rescue
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)
core_assertions(s)
assert s.inner_rescue # true in ruby 1.9 stdlib, false in timeout gem 0.2.0, true in timeout gem 0.4.0
assert s.outer_rescue # false in ruby 1.9 stdlib, true in timeout gem 0.2.0, false in timeout gem 0.4.0, true in time_limit
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)
core_assertions(s)
assert s.inner_rescue
assert s.outer_rescue # false in timeout gem 0.4.0, true in time_limit
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)
core_assertions(s)
assert s.inner_rescue
assert s.outer_rescue # false in timeout gem 0.4.0, true in time_limit
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)
core_assertions(s)
assert !s.inner_rescue
assert s.outer_rescue
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)
core_assertions(s)
assert s.inner_rescue
assert s.outer_rescue # false in timeout gem 0.4.0, true in time_limit
end
end