|
4 | 4 |
|
5 | 5 | module DEBUGGER__ |
6 | 6 | class DebuggerLocalsTest < TestCase |
7 | | - class RaisedTest < TestCase |
| 7 | + class REPLLocalsTest < TestCase |
8 | 8 | def program |
9 | 9 | <<~RUBY |
10 | | - 1| _rescued_ = 1111 |
11 | | - 2| foo rescue nil |
12 | | - 3| |
13 | | - 4| # check repl variable doesn't leak to the program |
14 | | - 5| result = _rescued_ * 2 |
15 | | - 6| binding.b |
| 10 | + 1| a = 1 |
16 | 11 | RUBY |
17 | 12 | end |
18 | 13 |
|
19 | | - def test_raised_is_accessible_from_repl |
| 14 | + def test_locals_added_in_locals_are_accessible_between_evaluations |
20 | 15 | debug_code(program) do |
21 | | - type "catch Exception" |
22 | | - type "c" |
23 | | - type "_raised" |
24 | | - assert_line_text(/#<NameError: undefined local variable or method `foo' for main:Object/) |
25 | | - type "c" |
26 | | - type "result" |
27 | | - assert_line_text(/2222/) |
| 16 | + type "y = 50" |
| 17 | + type "y" |
| 18 | + assert_line_text(/50/) |
28 | 19 | type "c" |
29 | 20 | end |
30 | 21 | end |
| 22 | + end |
31 | 23 |
|
32 | | - def test_raised_is_accessible_from_command |
33 | | - debug_code(program) do |
34 | | - type "catch Exception pre: p _raised" |
35 | | - type "c" |
36 | | - assert_line_text(/#<NameError: undefined local variable or method `foo' for main:Object/) |
37 | | - type "c" |
38 | | - type "result" |
39 | | - assert_line_text(/2222/) |
40 | | - type "c" |
| 24 | + class RaisedTest < TestCase |
| 25 | + class RubyMethodTest < TestCase |
| 26 | + def program |
| 27 | + <<~RUBY |
| 28 | + 1| foo rescue nil |
| 29 | + RUBY |
| 30 | + end |
| 31 | + |
| 32 | + def test_raised_is_accessible_from_repl |
| 33 | + debug_code(program) do |
| 34 | + type "catch Exception" |
| 35 | + type "c" |
| 36 | + type "_raised" |
| 37 | + assert_line_text(/#<NameError: undefined local variable or method `foo' for main:Object/) |
| 38 | + type "c" |
| 39 | + end |
| 40 | + end |
| 41 | + |
| 42 | + def test_raised_is_accessible_from_command |
| 43 | + debug_code(program) do |
| 44 | + type "catch Exception pre: p _raised" |
| 45 | + type "c" |
| 46 | + assert_line_text(/#<NameError: undefined local variable or method `foo' for main:Object/) |
| 47 | + type "c" |
| 48 | + end |
| 49 | + end |
| 50 | + end |
| 51 | + |
| 52 | + class CMethodTest < TestCase |
| 53 | + def program |
| 54 | + <<~RUBY |
| 55 | + 1| 1/0 rescue nil |
| 56 | + RUBY |
| 57 | + end |
| 58 | + |
| 59 | + def test_raised_is_accessible_from_repl |
| 60 | + debug_code(program) do |
| 61 | + type "catch Exception" |
| 62 | + type "c" |
| 63 | + type "_raised" |
| 64 | + assert_line_text(/ZeroDivisionError/) |
| 65 | + type "c" |
| 66 | + end |
| 67 | + end |
| 68 | + |
| 69 | + def test_raised_is_accessible_from_command |
| 70 | + debug_code(program) do |
| 71 | + type "catch Exception pre: p _raised" |
| 72 | + type "c" |
| 73 | + assert_line_text(/ZeroDivisionError/) |
| 74 | + type "c" |
| 75 | + end |
| 76 | + end |
| 77 | + end |
| 78 | + |
| 79 | + class EncapsulationTest < TestCase |
| 80 | + def program |
| 81 | + <<~RUBY |
| 82 | + 1| 1/0 rescue nil |
| 83 | + 2| a = _raised |
| 84 | + RUBY |
| 85 | + end |
| 86 | + |
| 87 | + def test_raised_doesnt_leak_to_program_binding |
| 88 | + debug_code(program) do |
| 89 | + type "catch StandardError" |
| 90 | + type "c" |
| 91 | + # stops for ZeroDivisionError |
| 92 | + type "info" |
| 93 | + type "_raised" |
| 94 | + assert_line_text(/ZeroDivisionError/) |
| 95 | + type "c" |
| 96 | + |
| 97 | + # stops for NoMethodError because _raised is not defiend in the program |
| 98 | + type "_raised" |
| 99 | + assert_line_text(/NameError: undefined local variable or method `_raised' for main:Object/) |
| 100 | + type "c" |
| 101 | + end |
41 | 102 | end |
42 | 103 | end |
43 | 104 | end |
44 | 105 |
|
45 | 106 | class ReturnedTest < TestCase |
46 | 107 | def program |
47 | 108 | <<~RUBY |
48 | | - 1| _return = 1111 |
49 | | - 2| |
50 | | - 3| def foo |
51 | | - 4| "foo" |
52 | | - 5| end |
53 | | - 6| |
54 | | - 7| foo |
55 | | - 8| |
56 | | - 9| # check repl variable doesn't leak to the program |
57 | | - 10| result = _return * 2 |
58 | | - 11| |
59 | | - 12| binding.b |
| 109 | + 1| def foo |
| 110 | + 2| "foo" |
| 111 | + 3| end |
| 112 | + 4| |
| 113 | + 5| foo |
60 | 114 | RUBY |
61 | 115 | end |
62 | 116 |
|
63 | 117 | def test_returned_is_accessible_from_repl |
64 | 118 | debug_code(program) do |
65 | | - type "b 5" |
| 119 | + type "b 3" |
66 | 120 | type "c" |
67 | 121 | type "_return + 'bar'" |
68 | 122 | assert_line_text(/"foobar"/) |
69 | 123 | type "c" |
70 | | - type "result" |
71 | | - assert_line_text(/2222/) |
72 | | - type "q!" |
73 | 124 | end |
74 | 125 | end |
75 | 126 |
|
76 | 127 | def test_returned_is_accessible_from_command |
77 | 128 | debug_code(program) do |
78 | | - type "b 5 pre: p _return + 'bar'" |
| 129 | + type "b 3 pre: p _return + 'bar'" |
79 | 130 | type "c" |
80 | 131 | assert_line_text(/"foobar"/) |
81 | 132 | type "c" |
82 | | - type "result" |
83 | | - assert_line_text(/2222/) |
84 | | - type "q!" |
| 133 | + end |
| 134 | + end |
| 135 | + |
| 136 | + class EncapsulationTest < TestCase |
| 137 | + def program |
| 138 | + <<~RUBY |
| 139 | + 1| def foo |
| 140 | + 2| "foo" |
| 141 | + 3| end |
| 142 | + 4| |
| 143 | + 5| foo |
| 144 | + 6| puts _return |
| 145 | + RUBY |
| 146 | + end |
| 147 | + |
| 148 | + def test_raised_doesnt_leak_to_program_binding |
| 149 | + debug_code(program) do |
| 150 | + type "catch StandardError" |
| 151 | + type "b 3" |
| 152 | + type "c" |
| 153 | + type "_return + 'bar'" |
| 154 | + assert_line_text(/"foobar"/) |
| 155 | + type "c" |
| 156 | + # stops for NoMethodError because _return is not defiend in the program |
| 157 | + type "_raised" |
| 158 | + assert_line_text(/NameError: undefined local variable or method `_return' for main:Object/) |
| 159 | + type "c" |
| 160 | + end |
85 | 161 | end |
86 | 162 | end |
87 | 163 | end |
|
0 commit comments