def test_log_on_breakpoint(debugger_api: _DebuggerAPI):
    from robocorp_ls_core.debug_adapter_core.dap.dap_schema import TerminatedEvent
    from robocorp_ls_core.debug_adapter_core.dap.dap_schema import OutputEvent

    debugger_api.initialize()
    target = debugger_api.get_dap_case_file("case_condition.robot")
    debugger_api.target = target

    debugger_api.launch(target, debug=True)
    line = debugger_api.get_line_index_with_content("Log    ${counter}")
    debugger_api.set_breakpoints(
        target,
        line,
        line_to_kwargs={line: {
            "logMessage": "Counter is: ${counter}"
        }})
    debugger_api.configuration_done()
    debugger_api.read(TerminatedEvent)

    debugger_api.assert_message_found(
        OutputEvent,
        accept_msg=lambda output: output.body.output.strip() ==
        "Counter is: 1",
    )
    debugger_api.assert_message_found(
        OutputEvent,
        accept_msg=lambda output: output.body.output.strip() ==
        "Counter is: 2",
    )
def test_stop_on_hit_condition(debugger_api: _DebuggerAPI):
    from robocorp_ls_core.debug_adapter_core.dap.dap_schema import TerminatedEvent

    debugger_api.initialize()
    target = debugger_api.get_dap_case_file("case_condition.robot")
    debugger_api.target = target

    debugger_api.launch(target, debug=True)
    line = debugger_api.get_line_index_with_content("Log    ${counter}")
    debugger_api.set_breakpoints(target,
                                 line,
                                 line_to_kwargs={line: {
                                     "hitCondition": "2"
                                 }})
    debugger_api.configuration_done()

    json_hit = debugger_api.wait_for_thread_stopped(name="Log")

    name_to_scope = debugger_api.get_name_to_scope(json_hit.frame_id)
    assert sorted(
        name_to_scope.keys()) == ["Arguments", "Builtins", "Variables"]
    name_to_var = debugger_api.get_variables_name_to_var(json_hit.frame_id)
    assert name_to_var["'${counter}'"].value == "2"

    msg = debugger_api.continue_event(json_hit.thread_id,
                                      accept_terminated=True)
    if not isinstance(msg, TerminatedEvent):
        debugger_api.read(TerminatedEvent)
def test_simple_debug_launch_stop_on_robot_and_pydevd(
        debugger_api: _DebuggerAPI):
    from robocorp_ls_core.debug_adapter_core.dap.dap_schema import TerminatedEvent
    from robocorp_ls_core.debug_adapter_core.dap.dap_schema import ThreadsResponse

    debugger_api.initialize()
    target = debugger_api.get_dap_case_file("case_python.robot")
    debugger_api.target = target
    mypylib = debugger_api.get_dap_case_file("mypylib.py")

    debugger_api.launch(target, debug=True)
    threads_response: ThreadsResponse = (debugger_api.list_threads())
    assert len(threads_response.body.threads) == 1
    bp_robot = debugger_api.get_line_index_with_content("Some Call")
    bp_pydevd = debugger_api.get_line_index_with_content("break here",
                                                         filename=mypylib)
    debugger_api.set_breakpoints(target, bp_robot)
    debugger_api.set_breakpoints(mypylib, bp_pydevd)
    debugger_api.configuration_done()

    json_hit = debugger_api.wait_for_thread_stopped(file="case_python.robot")
    msg = debugger_api.continue_event(json_hit.thread_id)

    debugger_api.wait_for_thread_stopped(file="mypylib.py")
    msg = debugger_api.continue_event(json_hit.thread_id,
                                      accept_terminated=True)

    if not isinstance(msg, TerminatedEvent):
        debugger_api.read(TerminatedEvent)
Esempio n. 4
0
def test_evaluate(debugger_api: _DebuggerAPI):
    from robocorp_ls_core.debug_adapter_core.dap.dap_schema import TerminatedEvent

    debugger_api.initialize()
    target = debugger_api.get_dap_case_file("case_evaluate.robot")
    debugger_api.target = target

    debugger_api.launch(target, debug=True)
    debugger_api.set_breakpoints(
        target, debugger_api.get_line_index_with_content("Break 1"))
    debugger_api.configuration_done()

    json_hit = debugger_api.wait_for_thread_stopped(name="Should Be Equal")

    response = debugger_api.evaluate("${arg1}",
                                     frameId=json_hit.frame_id,
                                     context="watch")
    assert response.body.result == "2"

    response = debugger_api.evaluate("My Equal Redefined     2   2",
                                     frameId=json_hit.frame_id,
                                     context="repl")
    assert response.body.result == "None"

    assert json_hit.stack_trace_response.body.stackFrames[0][
        "id"] == json_hit.frame_id

    response = debugger_api.evaluate(
        "My Equal Redefined     2   1",
        frameId=json_hit.frame_id,
        context="repl",
        success=False,
    )
    assert "UserKeywordExecutionFailed: 2 != 1" in response.message

    # We can't evaluate keywords that are not in the top level.
    parent_frame_id = json_hit.stack_trace_response.body.stackFrames[1]["id"]
    response = debugger_api.evaluate(
        "My Equal Redefined     2   2",
        frameId=parent_frame_id,
        context="repl",
        success=False,
    )
    assert ("Keyword calls may only be evaluated at the topmost frame"
            in response.message)

    debugger_api.set_breakpoints(
        target, debugger_api.get_line_index_with_content("Break 2"))

    debugger_api.continue_event()

    json_hit = debugger_api.wait_for_thread_stopped(name="Should Be Equal")
    response = debugger_api.evaluate("${arg1}",
                                     frameId=json_hit.frame_id,
                                     context="watch")
    assert response.body.result in ("['2', '2']", "[u'2', u'2']")
    debugger_api.continue_event()

    debugger_api.read(TerminatedEvent)
Esempio n. 5
0
def test_variables(debugger_api: _DebuggerAPI):
    from robocorp_ls_core.debug_adapter_core.dap.dap_schema import TerminatedEvent

    debugger_api.initialize()
    target = debugger_api.get_dap_case_file("case4/case4.robot")
    debugger_api.target = target

    debugger_api.launch(target, debug=True, args=["--variable", "my_var:22"])
    debugger_api.set_breakpoints(
        target,
        debugger_api.get_line_index_with_content("My Equal Redefined   2   2"))
    debugger_api.configuration_done()

    json_hit = debugger_api.wait_for_thread_stopped(name="My Equal Redefined")

    name_to_scope = debugger_api.get_name_to_scope(json_hit.frame_id)
    assert sorted(
        name_to_scope.keys()) == ["Arguments", "Builtins", "Variables"]
    name_to_var = debugger_api.get_arguments_name_to_var(json_hit.frame_id)
    assert sorted(name_to_var.keys()) == ["Arg 0", "Arg 1"]
    name_to_var = debugger_api.get_variables_name_to_var(json_hit.frame_id)
    assert "'${TEST_NAME}'" not in name_to_var
    assert "'${arg1}'" not in name_to_var
    assert "'${my_var}'" in name_to_var

    name_to_var = debugger_api.get_builtins_name_to_var(json_hit.frame_id)
    assert "'${TEST_NAME}'" in name_to_var
    assert "'${arg1}'" not in name_to_var
    assert "'${my_var}'" not in name_to_var

    debugger_api.step_in(json_hit.thread_id)

    # Check that the 'arg1' var is in the current namespace but not in the parent
    # namespace.
    json_hit = debugger_api.wait_for_thread_stopped("step",
                                                    name="Should Be Equal")
    name_to_var = debugger_api.get_variables_name_to_var(json_hit.frame_id)
    assert "'${arg1}'" in name_to_var or "u'${arg1}'" in name_to_var
    name_to_var = debugger_api.get_variables_name_to_var(
        json_hit.stack_trace_response.body.stackFrames[1]["id"])
    assert "'${arg1}'" not in name_to_var and "u'${arg1}'" not in name_to_var

    debugger_api.continue_event()

    debugger_api.read(TerminatedEvent)
Esempio n. 6
0
def test_step_out(debugger_api: _DebuggerAPI):
    from robocorp_ls_core.debug_adapter_core.dap.dap_schema import TerminatedEvent

    debugger_api.initialize()
    target = debugger_api.get_dap_case_file("case_step_out.robot")
    debugger_api.target = target

    debugger_api.launch(target, debug=True)
    debugger_api.set_breakpoints(
        target, debugger_api.get_line_index_with_content("Break 1"))
    debugger_api.configuration_done()

    json_hit = debugger_api.wait_for_thread_stopped(name="Should Be Equal")

    debugger_api.step_out(json_hit.thread_id)

    json_hit = debugger_api.wait_for_thread_stopped(
        "step", name="Yet Another Equal Redefined")

    debugger_api.continue_event()

    debugger_api.read(TerminatedEvent)
def test_init_auto_loaded(debugger_api: _DebuggerAPI):
    from robocorp_ls_core.debug_adapter_core.dap.dap_schema import TerminatedEvent

    debugger_api.initialize()
    target = debugger_api.get_dap_case_file("check_init/lsp_test.robot")
    target_init = debugger_api.get_dap_case_file("check_init/__init__.robot")
    debugger_api.target = target

    debugger_api.launch(target, debug=True)
    bp_setup = debugger_api.get_line_index_with_content("Suite Setup",
                                                        filename=target_init)
    bp_teardown = debugger_api.get_line_index_with_content(
        "Suite Teardown", filename=target_init)
    debugger_api.set_breakpoints(target_init, (bp_setup, bp_teardown))
    debugger_api.configuration_done()

    json_hit = debugger_api.wait_for_thread_stopped(file="__init__.robot")
    debugger_api.continue_event(json_hit.thread_id)

    json_hit = debugger_api.wait_for_thread_stopped(file="__init__.robot")
    debugger_api.continue_event(json_hit.thread_id)

    debugger_api.read(TerminatedEvent)