-
Notifications
You must be signed in to change notification settings - Fork 146
Expand file tree
/
Copy pathdebugger_local_test.rb
More file actions
177 lines (159 loc) · 4.23 KB
/
debugger_local_test.rb
File metadata and controls
177 lines (159 loc) · 4.23 KB
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
# frozen_string_literal: true
require_relative '../support/console_test_case'
module DEBUGGER__
class DebuggerLocalsTest < ConsoleTestCase
class REPLLocalsTest < ConsoleTestCase
def program
<<~RUBY
1| a = 1
RUBY
end
def test_locals_added_in_locals_are_accessible_between_evaluations
debug_code(program) do
type "y = 50"
type "y"
assert_line_text(/50/)
type "c"
end
end
def test_evaluated_result_is_set_as_underscore_local
debug_code(program) do
type "_"
assert_line_text(/nil/)
type "3 * 3"
type "foo = _"
type "9 == foo"
assert_line_text(/true/)
type "c"
end
end
end
class RaisedTest < ConsoleTestCase
class RubyMethodTest < ConsoleTestCase
def program
<<~RUBY
1| foo rescue nil
RUBY
end
def test_raised_is_accessible_from_repl
debug_code(program) do
type "catch Exception"
type "c"
type "_raised"
assert_line_text(/undefined local variable or method [`']foo' for main/)
type "c"
end
end
def test_raised_is_accessible_from_command
debug_code(program) do
type "catch Exception pre: p _raised"
type "c"
assert_line_text(/undefined local variable or method [`']foo' for main/)
type "c"
end
end
end
class CMethodTest < ConsoleTestCase
def program
<<~RUBY
1| 1/0 rescue nil
RUBY
end
def test_raised_is_accessible_from_repl
debug_code(program) do
type "catch Exception"
type "c"
type "_raised"
assert_line_text(/ZeroDivisionError/)
type "c"
end
end
def test_raised_is_accessible_from_command
debug_code(program) do
type "catch Exception pre: p _raised"
type "c"
assert_line_text(/ZeroDivisionError/)
type "c"
end
end
end
class EncapsulationTest < ConsoleTestCase
def program
<<~RUBY
1| 1/0 rescue nil
2| a = _raised
RUBY
end
def test_raised_doesnt_leak_to_program_binding
debug_code(program) do
type "catch StandardError"
type "c"
# stops for ZeroDivisionError
type "info"
type "_raised"
assert_line_text(/ZeroDivisionError/)
type "c"
# stops for NoMethodError because _raised is not defined in the program
type "_raised"
assert_line_text(/undefined local variable or method [`']_raised' for main/)
type "c"
end
end
end
end
class ReturnedTest < ConsoleTestCase
def program
<<~RUBY
1| def foo
2| "foo"
3| end
4|
5| foo
RUBY
end
def test_returned_is_accessible_from_repl
debug_code(program) do
type "b 3"
type "c"
type "_return + 'bar'"
assert_line_text(/"foobar"/)
type "c"
end
end
def test_returned_is_accessible_from_command
debug_code(program) do
type "b 3 pre: p _return + 'bar'"
type "c"
assert_line_text(/"foobar"/)
type "c"
end
end
class EncapsulationTest < ConsoleTestCase
def program
<<~RUBY
1| def foo
2| "foo"
3| end
4|
5| foo
6| puts _return
RUBY
end
def test_raised_doesnt_leak_to_program_binding
debug_code(program) do
type "catch StandardError"
type "b 3"
type "c"
type "_return + 'bar'"
assert_line_text(/"foobar"/)
type "c"
# stops for NoMethodError because _return is not defined in the program
type "_raised"
assert_line_text(/undefined local variable or method [`']_return' for main/)
type "c"
end
end
end
end
end
end