Skip to content

Commit 7f62889

Browse files
committed
Add some test cases
1 parent d676339 commit 7f62889

25 files changed

+430
-1
lines changed

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_continue
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_continue
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_continue
26+
end
27+
end
28+
end
29+
end

test/protocol/detach_test.rb

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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+
req_add_breakpoint 3
26+
req_continue
27+
assert_reattach
28+
req_terminate_debuggee
29+
end
30+
end
31+
end
32+
end

test/protocol/eval_test.rb

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# frozen_string_literal: true
2+
3+
require_relative '../support/test_case'
4+
5+
module DEBUGGER__
6+
7+
class EvalTest < TestCase
8+
PROGRAM = <<~RUBY
9+
1| a = 2
10+
2| b = 3
11+
3| c = 1
12+
4| d = 4
13+
5| e = 5
14+
6| f = 6
15+
RUBY
16+
17+
def test_eval1
18+
run_protocol_scenario PROGRAM do
19+
req_add_breakpoint 5
20+
req_continue
21+
assert_repl_result 2, expression: 'a'
22+
assert_repl_result 4, expression: 'd'
23+
assert_repl_result 3, expression: '1+2'
24+
req_continue
25+
end
26+
end
27+
end
28+
end

0 commit comments

Comments
 (0)