Skip to content

Commit 2875447

Browse files
committed
Update CONTRIBUTING.md
1 parent 66fb88c commit 2875447

File tree

1 file changed

+107
-7
lines changed

1 file changed

+107
-7
lines changed

CONTRIBUTING.md

Lines changed: 107 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -216,13 +216,6 @@ module DEBUGGER__
216216
end
217217
```
218218

219-
### Tests for DAP
220-
221-
If you want to write tests for DAP, you should use the test generator.
222-
After running `$ bin/gentest target.rb --open=vscode` in the terminal, VSCode will be executed.
223-
If you need to modify existing tests, it is basically a good idea to regenerate them by the test generator instead of rewriting them directly.
224-
Please refer to [the Microsoft "Debug Adapter Protocol" article](https://microsoft.github.io/debug-adapter-protocol/specification) to learn more about DAP formats.
225-
226219
#### gentest options
227220

228221
You can get more information about `gentest` here.
@@ -256,6 +249,113 @@ Passes if `text` is not included in the last debugger log.
256249

257250
Passes if `text` is included in the debuggee log.
258251

252+
### Tests for DAP
253+
254+
Currently, there are 2 kinds of test frameworks for DAP.
255+
256+
1. Protocol-based tests
257+
258+
If you want to write protocol-based tests, you should use the test generator.
259+
After running `$ bin/gentest target.rb --open=vscode` in the terminal, VSCode will be executed.
260+
If you need to modify existing tests, it is basically a good idea to regenerate them by the test generator instead of rewriting them directly.
261+
Please refer to [the Microsoft "Debug Adapter Protocol" article](https://microsoft.github.io/debug-adapter-protocol/specification) to learn more about DAP formats.
262+
263+
2. High-level tests
264+
265+
High-level tests are designed to test both DAP and CDP for a single method. (Currently, only DAP is supported.)
266+
You can write tests as follows:
267+
268+
```ruby
269+
require_relative '../support/test_case'
270+
module DEBUGGER__
271+
class BreakTest < TestCase
272+
# PROGRAM is the target script.
273+
PROGRAM = <<~RUBY
274+
1| module Foo
275+
2| class Bar
276+
3| def self.a
277+
4| "hello"
278+
5| end
279+
6| end
280+
7| Bar.a
281+
8| bar = Bar.new
282+
9| end
283+
RUBY
284+
285+
def test_break1
286+
run_protocol_scenario PROGRAM do # Start debugger
287+
req_add_breakpoint 5 # Set a breakpoint on line 5.
288+
req_add_breakpoint 8 # Set a breakpoint on line 8.
289+
req_continue # Resume the program.
290+
assert_line_num 5 # Check if debugger stops at line 5.
291+
req_continue # Resume the program.
292+
assert_line_num 8 # Check if debugger stops at line 8.
293+
req_continue # Resume the program.
294+
end
295+
end
296+
end
297+
end
298+
```
299+
300+
#### API
301+
302+
- req_add_breakpoint(lineno, path: temp_file_path, cond: nil)
303+
304+
Sends request to rdbg to add a breakpoint.
305+
306+
- req_delete_breakpoint bpnum
307+
308+
Sends request to rdbg to delete a breakpoint.
309+
310+
- req_set_exception_breakpoints
311+
312+
Sends request to rdbg to set exception breakpoints.
313+
314+
- req_continue
315+
316+
Sends request to rdbg to resume the program.
317+
318+
- req_step
319+
320+
Sends request to rdbg to step into next method.
321+
322+
- req_next
323+
324+
Sends request to rdbg to step over next method.
325+
326+
- req_finish
327+
328+
Sends request to rdbg to step out of current method.
329+
330+
- req_step_back
331+
332+
Sends request to rdbg to step back from current method.
333+
334+
- req_terminate_debuggee
335+
336+
Sends request to rdbg to terminate the debuggee.
337+
338+
- assert_reattach
339+
340+
Passes if reattaching to rdbg is successful.
341+
342+
- assert_hover_result(expected, expression: nil)
343+
344+
Passes if result of `expression` is equal to `expected`.
345+
346+
- assert_repl_result(expected, expression: nil)
347+
348+
Passes if result of `expression` is equal to `expected`.
349+
350+
- assert_watch_result(expected, expression: nil)
351+
352+
Passes if result of `expression` is equal to `expected`.
353+
354+
- assert_line_num(expected)
355+
356+
Passes if `expected` is equal to the location where debugger stops.
357+
358+
259359
## To Update README
260360

261361
This project generates `README.md` from the template `misc/README.md.erb`

0 commit comments

Comments
 (0)