diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..40f8f23 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,36 @@ +language: ruby +dist: trusty +os: + - linux + - osx + +rvm: + - 1.9.3 + - 2.0.0 + - 2.1.10 + - 2.2.8 + - 2.3.5 + - 2.4.2 + - 2.5.0-preview1 + - ruby-head + +matrix: + fast_finish: true + allow_failures: + - rvm: ruby-head + + exclude: + - os: osx + rvm: 1.9.3 + - os: osx + rvm: 2.0.0 + - os: linux + rvm: 2.5.0-preview1 + +# include: +# - os: osx +# rvm: 1.9.3 +# before_script: rvm install ruby-1.9.3 # not binary +# - os: osx +# rvm: 2.0.0 +# before_script: rvm install ruby-2.0.0 # not binary \ No newline at end of file diff --git a/Gemfile b/Gemfile index 2ee4fb3..2f97c35 100644 --- a/Gemfile +++ b/Gemfile @@ -1,7 +1,20 @@ source "http://rubygems.org" -gem "ruby-debug-base", :platforms => [:jruby, :ruby_18, :mingw_18] -gem "ruby-debug-base19x", ">= 0.11.30.pre4", :platforms => [:ruby_19, :mingw_19] +# @param [Array] versions compatible ruby versions +# @return [Array] an array with mri platforms of given versions +def mries(*versions) + versions.flat_map do |v| + %w(ruby mingw x64_mingw) + .map { |platform| "#{platform}_#{v}".to_sym unless platform == "x64_mingw" && v < "2.0" } + .delete_if &:nil? + end +end + +gem "ruby-debug-base", :platforms => [:jruby, *mries('18')] +gem "ruby-debug-base19x", ">= 0.11.32", :platforms => mries('19') +if RUBY_VERSION && RUBY_VERSION >= "2.0" + gem "debase", ">= 0.2.2.beta14", :platforms => mries('20', '21', '22', '23', '24', '25') +end gemspec diff --git a/README.md b/README.md index 90df01e..d0522d6 100644 --- a/README.md +++ b/README.md @@ -4,3 +4,4 @@ An interface which glues ruby-debug to IDEs like Eclipse (RDT), NetBeans and Rub [![official JetBrains project](http://jb.gg/badges/official.svg)](https://confluence.jetbrains.com/display/ALL/JetBrains+on+GitHub) [![Gem Version](https://badge.fury.io/rb/ruby-debug-ide.svg)][gem] +[![Build Status](https://travis-ci.org/ruby-debug/ruby-debug-ide.svg?branch=master)](https://travis-ci.org/ruby-debug/ruby-debug-ide) diff --git a/lib/ruby-debug-ide.rb b/lib/ruby-debug-ide.rb index 7482da3..62c0671 100644 --- a/lib/ruby-debug-ide.rb +++ b/lib/ruby-debug-ide.rb @@ -112,7 +112,7 @@ def start_control(host, port, notify_dispatcher) # "localhost" and nil have problems on some systems. host ||= '127.0.0.1' server = TCPServer.new(host, port) - print_greeting_msg($stderr, host, port) + print_greeting_msg($stderr, host, port) if defined? IDE_VERSION notify_dispatcher(port) if notify_dispatcher while (session = server.accept) $stderr.puts "Connected from #{session.peeraddr[2]}" if Debugger.cli_debug diff --git a/lib/ruby-debug-ide/command.rb b/lib/ruby-debug-ide/command.rb index dffd1a2..e6ee3e1 100644 --- a/lib/ruby-debug-ide/command.rb +++ b/lib/ruby-debug-ide/command.rb @@ -1,3 +1,9 @@ +if RUBY_VERSION < '2.0' || defined?(JRUBY_VERSION) + require 'ruby-debug-base' +else + require 'debase' +end + require 'ruby-debug-ide/helper' require 'delegate' diff --git a/lib/ruby-debug-ide/commands/expression_info.rb b/lib/ruby-debug-ide/commands/expression_info.rb index a03bc83..3eccd52 100644 --- a/lib/ruby-debug-ide/commands/expression_info.rb +++ b/lib/ruby-debug-ide/commands/expression_info.rb @@ -9,7 +9,7 @@ def regexp end def execute - string_to_parse = Command.unescape_incoming(@match.post_match) + " \n\n\n" + string_to_parse = Command.unescape_incoming(@match.post_match) + " \n \n\n" total_lines = string_to_parse.count("\n") + 1 lexer = RubyLex.new diff --git a/test-base/test_base.rb b/test-base/test_base.rb index 3399c8b..01bd85d 100644 --- a/test-base/test_base.rb +++ b/test-base/test_base.rb @@ -57,7 +57,7 @@ def teardown send_ruby("cont") end debug "Waiting for the server process to finish..." - (config_load('server_start_up_timeout')*4).times do + (config_load('server_start_up_timeout')*5).times do unless @process_finished debug '.' sleep 0.25 @@ -86,7 +86,7 @@ def start_ruby_process(script) @port = TestBase.find_free_port cmd = debug_command(script, @port) debug "Starting: #{cmd}\n" - + Thread.new do if RUBY_VERSION < '1.9' (_, p_out, p_err) = Open3.popen3(cmd) @@ -132,7 +132,8 @@ def TestBase.find_free_port(port = 1098) end def create_file(script_name, lines) - script_path = File.join(TMP_DIR, script_name) + script_path = File.realdirpath(File.join(TMP_DIR, script_name)) + File.open(script_path, "w") do |script| script.printf(lines.join("\n")) end @@ -141,7 +142,7 @@ def create_file(script_name, lines) def create_test2(lines) @test2_name = "test2.rb" - @test2_path = create_file(@test2_name, lines) + @test2_path = create_file(@test2_name, lines).force_encoding(Encoding::UTF_8) end # 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) suspension = read_suspension assert_equal(exp_file, suspension.file) assert_equal(exp_line, suspension.line) + exp_frames += 2 if Debugger::FRONT_END == "debase" assert_equal(exp_frames, suspension.frames) + exp_thread_id += 1 if Debugger::FRONT_END == "debase" assert_equal(exp_thread_id, suspension.threadId) end @@ -271,6 +274,7 @@ def assert_exception(exp_file, exp_line, exp_type, exp_thread_id=1) assert_equal(exp_file, exception.file) assert_equal(exp_line, exception.line) assert_equal(exp_type, exception.type) + exp_thread_id += 1 if Debugger::FRONT_END == "debase" assert_equal(exp_thread_id, exception.threadId) assert_not_nil(exception.message) end diff --git a/test-base/threads_and_frames_test.rb b/test-base/threads_and_frames_test.rb index c96b19a..e04cc8f 100644 --- a/test-base/threads_and_frames_test.rb +++ b/test-base/threads_and_frames_test.rb @@ -14,7 +14,11 @@ def test_frames assert_breakpoint_added_no(2) send_ruby("w") frames = read_frames - assert_equal(2, frames.length) + + needed_frame_length = 2 + needed_frame_length += 2 if Debugger::FRONT_END == "debase" + assert_equal(needed_frame_length, frames.length) + frame1 = frames[0] assert_equal(@test2_path, frame1.file) assert_equal(1, frame1.no) @@ -27,7 +31,11 @@ def test_frames assert_test_breakpoint(4) send_ruby("w") frames = read_frames - assert_equal(1, frames.length) + + needed_frame_length = 1 + needed_frame_length += 2 if Debugger::FRONT_END == "debase" + + assert_equal(needed_frame_length, frames.length) send_cont # test:4 -> test2:3 assert_breakpoint("test2.rb", 3) send_cont # test2:3 -> finish @@ -42,7 +50,11 @@ def test_frames_when_thread_spawned "def calc", "5 + 5", "end", "start_thread()", "calc()"] run_to_line(5) send_ruby("w") - assert_equal(2, read_frames.length) + + needed_length = 2 + needed_length += 2 if Debugger::FRONT_END == "debase" + + assert_equal(needed_length, read_frames.length) send_cont end diff --git a/test-base/variables_test.rb b/test-base/variables_test.rb index e0d3140..67f9b48 100644 --- a/test-base/variables_test.rb +++ b/test-base/variables_test.rb @@ -1,4 +1,5 @@ #!/usr/bin/env ruby +# encoding: utf-8 $:.unshift File.join(File.dirname(__FILE__), "..", "lib") @@ -25,7 +26,7 @@ def test_variable_with_xml_content {:name => "stringA"}, {:name => "testHashValue"}) # will receive '' - assert_equal("", variables[0].value) + assert_equal(CGI.escapeHTML(""), variables[0].value) assert_local(variables[0]) # the testHashValue contains an example, where the name consists of special # characters @@ -46,7 +47,7 @@ def test_variable_in_object {:name => "self", :value => "test", :type => "Test", :hasChildren => true}) send_ruby("v i self") assert_variables(read_variables, 1, - {:name => "@y", :value => "5", :type => "Fixnum", :hasChildren => false, :kind => "instance"}) + {:name => "@y", :value => "5", :type => int_type_name, :hasChildren => false, :kind => "instance"}) send_cont end @@ -59,7 +60,7 @@ def test_class_variables {:name => "self", :hasChildren => true}) send_ruby("v i self") assert_variables(read_variables, 1, - {:name => "@@class_var", :value => "55", :type => "Fixnum", :kind => "class"}) + {:name => "@@class_var", :value => "55", :type => int_type_name, :kind => "class"}) send_cont end @@ -69,7 +70,7 @@ def test_singleton_class_variables run_to_line(3) send_ruby("v i self") assert_variables(read_variables, 1, - {:name => "@@class_var", :value => "55", :type => "Fixnum", :hasChildren => false, :kind => "class"}) + {:name => "@@class_var", :value => "55", :type => int_type_name, :hasChildren => false, :kind => "class"}) send_cont end @@ -94,17 +95,19 @@ def test_variable_local assert_not_nil variables[1].objectId send_ruby("v i " + variables[1].objectId) # 'user' variable assert_variables(read_variables, 1, - {:name => "@id", :value => "22", :type => "Fixnum", :hasChildren => false}) + {:name => "@id", :value => "22", :type => int_type_name, :hasChildren => false}) send_cont end def test_variable_instance - create_socket ["require 'test2.rb'", "custom_object=Test2.new", "puts custom_object"] + create_socket ["require_relative 'test2.rb'", "custom_object=Test2.new", "puts custom_object"] create_test2 ["class Test2", "def initialize", "@y=5", "end", "def to_s", "'test'", "end", "end"] run_to("test2.rb", 6) - send_ruby("frame 3; v i custom_object") + frame_number = 3 + frame_number -= 1 if Debugger::FRONT_END == "debase" + send_ruby("frame #{frame_number}; v i custom_object") assert_variables(read_variables, 1, - {:name => "@y", :value => "5", :type => "Fixnum", :hasChildren => false}) + {:name => "@y", :value => "5", :type => int_type_name, :hasChildren => false}) send_cont end @@ -116,7 +119,7 @@ def test_variable_array {:name => "array", :type => "Array", :hasChildren => true}) send_ruby("v i array") assert_variables(read_variables, 2, - {:name => "[0]", :value => "1", :type => "Fixnum"}) + {:name => "[0]", :value => "1", :type => int_type_name}) send_cont end @@ -128,7 +131,7 @@ def test_variable_hash_with_string_keys {:name => "hash", :hasChildren => true}) send_ruby("v i hash") assert_variables(read_variables, 2, - {:name => "'a'", :value => "z", :type => "String"}) + {:name => CGI.escape_html("'a'"), :value => "z", :type => "String"}) send_cont end @@ -149,7 +152,7 @@ def test_variable_hash_with_object_keys # get the value send_ruby("frame 1 ; v i " + elements[0].objectId) assert_variables(read_variables, 1, - {:name => "@a", :value => "66", :type => "Fixnum"}) + {:name => "@a", :value => "66", :type => int_type_name}) send_cont end @@ -176,7 +179,7 @@ def test_non_string_from_to_s create_socket ["class BugExample; def to_s; 1; end; end", "b = BugExample.new", "sleep 0.01"] run_to_line(3) send_ruby("v local") - assert_variables(read_variables, 1, {:value => "ERROR: BugExample.to_s method returns Fixnum. Should return String."}) + assert_variables(read_variables, 1, {:value => "ERROR: BugExample.to_s method returns #{int_type_name}. Should return String."}) send_cont end @@ -196,6 +199,34 @@ def test_to_s_raises_exception send_cont end + def test_to_s_timelimit + create_socket ['class A', + 'def to_s', + 'a = 1', + 'loop do', + 'a = a + 1', + 'sleep 1', + 'break if (a > 2)', + 'end', + 'a.to_s', + 'end', + 'end', + 'b = Hash.new', + 'b[A.new] = A.new', + 'b[1] = A.new', + 'puts b #bp here'] + run_to_line(15) + send_ruby('v l') + assert_variables(read_variables, 1, + {:name => "b", :value => "Hash (2 elements)", :type => "Hash"}) + + send_ruby("v i b") + assert_variables(read_variables, 2, + {:name => "Timeout: evaluation of to_s took longer than 100ms.", :value => "Timeout: evaluation of to_s took longer than 100ms.", :type => "A"}, + {:name => "1", :value => "Timeout: evaluation of to_s took longer than 100ms.", :type => "A"}) + send_cont + end + def assert_xml(expected_xml, actual_xml) # XXX is there a better way then html_escape in standard libs? assert_equal(ERB::Util.html_escape(expected_xml), actual_xml) @@ -230,5 +261,11 @@ def assert_variables(vars, count, *expected) end end + private + + def int_type_name + (Fixnum || Integer).name + end + end diff --git a/test/rd_test_base.rb b/test/rd_test_base.rb index d872f4e..7d29edc 100644 --- a/test/rd_test_base.rb +++ b/test/rd_test_base.rb @@ -24,7 +24,7 @@ def debug_command(script, port) cmd << " -J-Xdebug -J-Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=y" if jruby? and debug_jruby? cmd << " -I 'lib:#{File.dirname(script)}' #{@rdebug_ide}" + (@verbose_server ? " -d" : "") + - " -p #{port} -- '#{script}'" + " -p #{port} --evaluation-control --time-limit 100 --memory-limit 0 -- '#{script}'" end def start_debugger diff --git a/test/ruby-debug/xml_printer_test.rb b/test/ruby-debug/xml_printer_test.rb index 08eb537..ab58014 100644 --- a/test/ruby-debug/xml_printer_test.rb +++ b/test/ruby-debug/xml_printer_test.rb @@ -48,8 +48,8 @@ def test_print_frames test_path = File.join(Dir.pwd, 'test.rb') expected = [ "", - "", - "", + "", + "", ""] assert_equal(expected, interface.data) end @@ -64,7 +64,10 @@ def test_print_at_line Debugger.stop end test_path = File.join(Dir.pwd, 'test.rb') - expected = [""] + + #TODO investigate + expected = [""] + assert_equal(expected, interface.data) end