Skip to content

Commit f234521

Browse files
authored
Merge pull request #131 from ViugiNick/test-fixes-clean
This branch enables travis configuration to test ruby-debug-ide and revives tests. Several minor fixes for tests to pass; the majority of behaviour changes are in `debase` and `ruby-debug-base19x` gems.
2 parents bf7f78e + b916561 commit f234521

File tree

11 files changed

+139
-27
lines changed

11 files changed

+139
-27
lines changed

.travis.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
language: ruby
2+
dist: trusty
3+
os:
4+
- linux
5+
- osx
6+
7+
rvm:
8+
- 1.9.3
9+
- 2.0.0
10+
- 2.1.10
11+
- 2.2.8
12+
- 2.3.5
13+
- 2.4.2
14+
- 2.5.0-preview1
15+
- ruby-head
16+
17+
matrix:
18+
fast_finish: true
19+
allow_failures:
20+
- rvm: ruby-head
21+
22+
exclude:
23+
- os: osx
24+
rvm: 1.9.3
25+
- os: osx
26+
rvm: 2.0.0
27+
- os: linux
28+
rvm: 2.5.0-preview1
29+
30+
# include:
31+
# - os: osx
32+
# rvm: 1.9.3
33+
# before_script: rvm install ruby-1.9.3 # not binary
34+
# - os: osx
35+
# rvm: 2.0.0
36+
# before_script: rvm install ruby-2.0.0 # not binary

Gemfile

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,20 @@
11
source "http://rubygems.org"
22

3-
gem "ruby-debug-base", :platforms => [:jruby, :ruby_18, :mingw_18]
4-
gem "ruby-debug-base19x", ">= 0.11.30.pre4", :platforms => [:ruby_19, :mingw_19]
3+
# @param [Array<String>] versions compatible ruby versions
4+
# @return [Array<String>] an array with mri platforms of given versions
5+
def mries(*versions)
6+
versions.flat_map do |v|
7+
%w(ruby mingw x64_mingw)
8+
.map { |platform| "#{platform}_#{v}".to_sym unless platform == "x64_mingw" && v < "2.0" }
9+
.delete_if &:nil?
10+
end
11+
end
12+
13+
gem "ruby-debug-base", :platforms => [:jruby, *mries('18')]
14+
gem "ruby-debug-base19x", ">= 0.11.32", :platforms => mries('19')
15+
if RUBY_VERSION && RUBY_VERSION >= "2.0"
16+
gem "debase", ">= 0.2.2.beta14", :platforms => mries('20', '21', '22', '23', '24', '25')
17+
end
518

619
gemspec
720

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ An interface which glues ruby-debug to IDEs like Eclipse (RDT), NetBeans and Rub
44

55
[![official JetBrains project](http://jb.gg/badges/official.svg)](https://confluence.jetbrains.com/display/ALL/JetBrains+on+GitHub)
66
[![Gem Version](https://badge.fury.io/rb/ruby-debug-ide.svg)][gem]
7+
[![Build Status](https://travis-ci.org/ruby-debug/ruby-debug-ide.svg?branch=master)](https://travis-ci.org/ruby-debug/ruby-debug-ide)

lib/ruby-debug-ide.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ def start_control(host, port, notify_dispatcher)
112112
# "localhost" and nil have problems on some systems.
113113
host ||= '127.0.0.1'
114114
server = TCPServer.new(host, port)
115-
print_greeting_msg($stderr, host, port)
115+
print_greeting_msg($stderr, host, port) if defined? IDE_VERSION
116116
notify_dispatcher(port) if notify_dispatcher
117117
while (session = server.accept)
118118
$stderr.puts "Connected from #{session.peeraddr[2]}" if Debugger.cli_debug

lib/ruby-debug-ide/command.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
if RUBY_VERSION < '2.0' || defined?(JRUBY_VERSION)
2+
require 'ruby-debug-base'
3+
else
4+
require 'debase'
5+
end
6+
17
require 'ruby-debug-ide/helper'
28
require 'delegate'
39

lib/ruby-debug-ide/commands/expression_info.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ def regexp
99
end
1010

1111
def execute
12-
string_to_parse = Command.unescape_incoming(@match.post_match) + " \n\n\n"
12+
string_to_parse = Command.unescape_incoming(@match.post_match) + " \n \n\n"
1313
total_lines = string_to_parse.count("\n") + 1
1414

1515
lexer = RubyLex.new

test-base/test_base.rb

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def teardown
5757
send_ruby("cont")
5858
end
5959
debug "Waiting for the server process to finish..."
60-
(config_load('server_start_up_timeout')*4).times do
60+
(config_load('server_start_up_timeout')*5).times do
6161
unless @process_finished
6262
debug '.'
6363
sleep 0.25
@@ -86,7 +86,7 @@ def start_ruby_process(script)
8686
@port = TestBase.find_free_port
8787
cmd = debug_command(script, @port)
8888
debug "Starting: #{cmd}\n"
89-
89+
9090
Thread.new do
9191
if RUBY_VERSION < '1.9'
9292
(_, p_out, p_err) = Open3.popen3(cmd)
@@ -132,7 +132,8 @@ def TestBase.find_free_port(port = 1098)
132132
end
133133

134134
def create_file(script_name, lines)
135-
script_path = File.join(TMP_DIR, script_name)
135+
script_path = File.realdirpath(File.join(TMP_DIR, script_name))
136+
136137
File.open(script_path, "w") do |script|
137138
script.printf(lines.join("\n"))
138139
end
@@ -141,7 +142,7 @@ def create_file(script_name, lines)
141142

142143
def create_test2(lines)
143144
@test2_name = "test2.rb"
144-
@test2_path = create_file(@test2_name, lines)
145+
@test2_path = create_file(@test2_name, lines).force_encoding(Encoding::UTF_8)
145146
end
146147

147148
# Creates test.rb with the given lines, set up @test_name and @test_path
@@ -222,7 +223,9 @@ def assert_suspension(exp_file, exp_line, exp_frames, exp_thread_id=1)
222223
suspension = read_suspension
223224
assert_equal(exp_file, suspension.file)
224225
assert_equal(exp_line, suspension.line)
226+
exp_frames += 2 if Debugger::FRONT_END == "debase"
225227
assert_equal(exp_frames, suspension.frames)
228+
exp_thread_id += 1 if Debugger::FRONT_END == "debase"
226229
assert_equal(exp_thread_id, suspension.threadId)
227230
end
228231

@@ -271,6 +274,7 @@ def assert_exception(exp_file, exp_line, exp_type, exp_thread_id=1)
271274
assert_equal(exp_file, exception.file)
272275
assert_equal(exp_line, exception.line)
273276
assert_equal(exp_type, exception.type)
277+
exp_thread_id += 1 if Debugger::FRONT_END == "debase"
274278
assert_equal(exp_thread_id, exception.threadId)
275279
assert_not_nil(exception.message)
276280
end

test-base/threads_and_frames_test.rb

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,11 @@ def test_frames
1414
assert_breakpoint_added_no(2)
1515
send_ruby("w")
1616
frames = read_frames
17-
assert_equal(2, frames.length)
17+
18+
needed_frame_length = 2
19+
needed_frame_length += 2 if Debugger::FRONT_END == "debase"
20+
assert_equal(needed_frame_length, frames.length)
21+
1822
frame1 = frames[0]
1923
assert_equal(@test2_path, frame1.file)
2024
assert_equal(1, frame1.no)
@@ -27,7 +31,11 @@ def test_frames
2731
assert_test_breakpoint(4)
2832
send_ruby("w")
2933
frames = read_frames
30-
assert_equal(1, frames.length)
34+
35+
needed_frame_length = 1
36+
needed_frame_length += 2 if Debugger::FRONT_END == "debase"
37+
38+
assert_equal(needed_frame_length, frames.length)
3139
send_cont # test:4 -> test2:3
3240
assert_breakpoint("test2.rb", 3)
3341
send_cont # test2:3 -> finish
@@ -42,7 +50,11 @@ def test_frames_when_thread_spawned
4250
"def calc", "5 + 5", "end", "start_thread()", "calc()"]
4351
run_to_line(5)
4452
send_ruby("w")
45-
assert_equal(2, read_frames.length)
53+
54+
needed_length = 2
55+
needed_length += 2 if Debugger::FRONT_END == "debase"
56+
57+
assert_equal(needed_length, read_frames.length)
4658
send_cont
4759
end
4860

test-base/variables_test.rb

Lines changed: 49 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
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+
233270
end
234271

test/rd_test_base.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def debug_command(script, port)
2424
cmd << " -J-Xdebug -J-Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=y" if jruby? and debug_jruby?
2525
cmd << " -I 'lib:#{File.dirname(script)}' #{@rdebug_ide}" +
2626
(@verbose_server ? " -d" : "") +
27-
" -p #{port} -- '#{script}'"
27+
" -p #{port} --evaluation-control --time-limit 100 --memory-limit 0 -- '#{script}'"
2828
end
2929

3030
def start_debugger

0 commit comments

Comments
 (0)