11#!/usr/bin/env ruby
2+ # encoding: utf-8
23
34$:.unshift File.join(File.dirname(__FILE__), "..", "lib")
45
@@ -25,7 +26,7 @@ def test_variable_with_xml_content
2526 {:name => "stringA"},
2627 {:name => "testHashValue"})
2728 # will receive ''
28- assert_equal("<start test=\"&\"/>", variables[0].value)
29+ assert_equal(CGI.escapeHTML( "<start test=\"&\"/>") , variables[0].value)
2930 assert_local(variables[0])
3031 # the testHashValue contains an example, where the name consists of special
3132 # characters
@@ -46,7 +47,7 @@ def test_variable_in_object
4647 {:name => "self", :value => "test", :type => "Test", :hasChildren => true})
4748 send_ruby("v i self")
4849 assert_variables(read_variables, 1,
49- {:name => "@y", :value => "5", :type => "Fixnum" , :hasChildren => false, :kind => "instance"})
50+ {:name => "@y", :value => "5", :type => int_type_name , :hasChildren => false, :kind => "instance"})
5051 send_cont
5152 end
5253
@@ -59,7 +60,7 @@ def test_class_variables
5960 {:name => "self", :hasChildren => true})
6061 send_ruby("v i self")
6162 assert_variables(read_variables, 1,
62- {:name => "@@class_var", :value => "55", :type => "Fixnum" , :kind => "class"})
63+ {:name => "@@class_var", :value => "55", :type => int_type_name , :kind => "class"})
6364 send_cont
6465 end
6566
@@ -69,7 +70,7 @@ def test_singleton_class_variables
6970 run_to_line(3)
7071 send_ruby("v i self")
7172 assert_variables(read_variables, 1,
72- {:name => "@@class_var", :value => "55", :type => "Fixnum" , :hasChildren => false, :kind => "class"})
73+ {:name => "@@class_var", :value => "55", :type => int_type_name , :hasChildren => false, :kind => "class"})
7374 send_cont
7475 end
7576
@@ -94,17 +95,19 @@ def test_variable_local
9495 assert_not_nil variables[1].objectId
9596 send_ruby("v i " + variables[1].objectId) # 'user' variable
9697 assert_variables(read_variables, 1,
97- {:name => "@id", :value => "22", :type => "Fixnum" , :hasChildren => false})
98+ {:name => "@id", :value => "22", :type => int_type_name , :hasChildren => false})
9899 send_cont
99100 end
100101
101102 def test_variable_instance
102- create_socket ["require 'test2.rb'", "custom_object=Test2.new", "puts custom_object"]
103+ create_socket ["require_relative 'test2.rb'", "custom_object=Test2.new", "puts custom_object"]
103104 create_test2 ["class Test2", "def initialize", "@y=5", "end", "def to_s", "'test'", "end", "end"]
104105 run_to("test2.rb", 6)
105- send_ruby("frame 3; v i custom_object")
106+ frame_number = 3
107+ frame_number -= 1 if Debugger::FRONT_END == "debase"
108+ send_ruby("frame #{frame_number}; v i custom_object")
106109 assert_variables(read_variables, 1,
107- {:name => "@y", :value => "5", :type => "Fixnum" , :hasChildren => false})
110+ {:name => "@y", :value => "5", :type => int_type_name , :hasChildren => false})
108111 send_cont
109112 end
110113
@@ -116,7 +119,7 @@ def test_variable_array
116119 {:name => "array", :type => "Array", :hasChildren => true})
117120 send_ruby("v i array")
118121 assert_variables(read_variables, 2,
119- {:name => "[0]", :value => "1", :type => "Fixnum" })
122+ {:name => "[0]", :value => "1", :type => int_type_name })
120123 send_cont
121124 end
122125
@@ -128,7 +131,7 @@ def test_variable_hash_with_string_keys
128131 {:name => "hash", :hasChildren => true})
129132 send_ruby("v i hash")
130133 assert_variables(read_variables, 2,
131- {:name => "'a'", :value => "z", :type => "String"})
134+ {:name => CGI.escape_html( "'a'") , :value => "z", :type => "String"})
132135 send_cont
133136 end
134137
@@ -149,7 +152,7 @@ def test_variable_hash_with_object_keys
149152 # get the value
150153 send_ruby("frame 1 ; v i " + elements[0].objectId)
151154 assert_variables(read_variables, 1,
152- {:name => "@a", :value => "66", :type => "Fixnum" })
155+ {:name => "@a", :value => "66", :type => int_type_name })
153156 send_cont
154157 end
155158
@@ -176,7 +179,7 @@ def test_non_string_from_to_s
176179 create_socket ["class BugExample; def to_s; 1; end; end", "b = BugExample.new", "sleep 0.01"]
177180 run_to_line(3)
178181 send_ruby("v local")
179- assert_variables(read_variables, 1, {:value => "ERROR: BugExample.to_s method returns Fixnum . Should return String."})
182+ assert_variables(read_variables, 1, {:value => "ERROR: BugExample.to_s method returns #{int_type_name} . Should return String."})
180183 send_cont
181184 end
182185
@@ -196,6 +199,34 @@ def test_to_s_raises_exception
196199 send_cont
197200 end
198201
202+ def test_to_s_timelimit
203+ create_socket ['class A',
204+ 'def to_s',
205+ 'a = 1',
206+ 'loop do',
207+ 'a = a + 1',
208+ 'sleep 1',
209+ 'break if (a > 2)',
210+ 'end',
211+ 'a.to_s',
212+ 'end',
213+ 'end',
214+ 'b = Hash.new',
215+ 'b[A.new] = A.new',
216+ 'b[1] = A.new',
217+ 'puts b #bp here']
218+ run_to_line(15)
219+ send_ruby('v l')
220+ assert_variables(read_variables, 1,
221+ {:name => "b", :value => "Hash (2 elements)", :type => "Hash"})
222+
223+ send_ruby("v i b")
224+ assert_variables(read_variables, 2,
225+ {:name => "Timeout: evaluation of to_s took longer than 100ms.", :value => "Timeout: evaluation of to_s took longer than 100ms.", :type => "A"},
226+ {:name => "1", :value => "Timeout: evaluation of to_s took longer than 100ms.", :type => "A"})
227+ send_cont
228+ end
229+
199230 def assert_xml(expected_xml, actual_xml)
200231 # XXX is there a better way then html_escape in standard libs?
201232 assert_equal(ERB::Util.html_escape(expected_xml), actual_xml)
@@ -230,5 +261,11 @@ def assert_variables(vars, count, *expected)
230261 end
231262 end
232263
264+ private
265+
266+ def int_type_name
267+ (Fixnum || Integer).name
268+ end
269+
233270end
234271
0 commit comments