Skip to content

Commit 1ab1bee

Browse files
committed
Add some test cases
1 parent f30ebfc commit 1ab1bee

27 files changed

+432
-5
lines changed

.github/workflows/protocol.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,4 @@ jobs:
3434
run: |
3535
bundle exec rake clobber
3636
bundle exec rake compile
37-
bundle exec rake test_dap
37+
bundle exec rake test_protocol

Rakefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ file 'README.md' => ['lib/debug/session.rb', 'lib/debug/config.rb',
2525
puts 'README.md is updated.'
2626
end
2727

28-
task :test_dap do
28+
task :test_protocol do
2929
ENV['RUBY_DEBUG_DAP_TEST'] = '1'
3030
end
3131

32-
Rake::TestTask.new(:test_dap) do |t|
33-
t.test_files = FileList["test/dap/*_test.rb"]
32+
Rake::TestTask.new(:test_protocol) do |t|
33+
t.test_files = FileList["test/protocol/*_test.rb"]
3434
end

test/protocol/break_test.rb

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# frozen_string_literal: true
2+
3+
require_relative '../support/test_case'
4+
5+
module DEBUGGER__
6+
class BreakTest1 < TestCase
7+
PROGRAM = <<~RUBY
8+
1| module Foo
9+
2| class Bar
10+
3| def self.a
11+
4| "hello"
12+
5| end
13+
6| end
14+
7| Bar.a
15+
8| bar = Bar.new
16+
9| end
17+
RUBY
18+
19+
def test_break
20+
run_protocol_scenario PROGRAM do
21+
req_add_breakpoint 5
22+
req_continue
23+
assert_line_num 5
24+
req_add_breakpoint 8
25+
req_continue
26+
assert_line_num 8
27+
req_disconnect
28+
end
29+
end
30+
end
31+
32+
class BreakTest2 < TestCase
33+
def program path
34+
<<~RUBY
35+
1| require_relative "#{path}"
36+
2| Foo.new.bar
37+
RUBY
38+
end
39+
40+
def extra_file
41+
<<~RUBY
42+
class Foo
43+
def bar
44+
puts :hoge
45+
end
46+
end
47+
RUBY
48+
end
49+
50+
def test_break
51+
with_extra_tempfile do |extra_file|
52+
run_protocol_scenario(program(extra_file.path)) do
53+
req_add_breakpoint 3, path: extra_file.path
54+
req_continue
55+
assert_line_num 3
56+
req_disconnect
57+
end
58+
end
59+
end
60+
end
61+
end

test/protocol/catch_test.rb

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# frozen_string_literal: true
2+
3+
require_relative '../support/test_case'
4+
5+
module DEBUGGER__
6+
7+
class CatchTest < TestCase
8+
PROGRAM = <<~RUBY
9+
1| module Foo
10+
2| class Bar
11+
3| def self.a
12+
4| raise 'foo'
13+
5| end
14+
6| end
15+
7| Bar.a
16+
8| bar = Bar.new
17+
9| end
18+
RUBY
19+
20+
def test_catch
21+
run_protocol_scenario PROGRAM do
22+
req_set_exception_breakpoints
23+
req_continue
24+
assert_line_num 4
25+
req_disconnect
26+
end
27+
end
28+
end
29+
end

test/protocol/detach_test.rb

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# frozen_string_literal: true
2+
3+
require_relative '../support/test_case'
4+
5+
module DEBUGGER__
6+
7+
class DetachTest < TestCase
8+
PROGRAM = <<~RUBY
9+
1| module Foo
10+
2| class Bar
11+
3| def self.a
12+
4| "hello"
13+
5| end
14+
6| end
15+
7| loop do
16+
8| b = 1
17+
9| end
18+
10| Bar.a
19+
11| bar = Bar.new
20+
12| end
21+
RUBY
22+
23+
def test_detach
24+
run_protocol_scenario PROGRAM do
25+
assert_reattach
26+
req_terminate_debuggee
27+
end
28+
end
29+
end
30+
end

0 commit comments

Comments
 (0)