# Path: tests/conftest.py
# class AsyncState(object):
#     def __init__(self):
#         self.state = 0
# 
#     def inc(self):
#         self.state += 1
# 
# def setup_debugger(debugger, binary, lines, on_state_change=None,
#                    startup_info=None, cont=True, wait=True):
#     assert debugger.load_binary("src/{}".format(binary))
# 
#     test_exception = []
# 
#     if not isinstance(lines, Iterable):
#         lines = [lines]
# 
#     for line in lines:
#         assert debugger.breakpoint_manager.add_breakpoint(
#             "src/{}.cpp".format(binary), line)
# 
#     if on_state_change:
#         def on_stop(state, data):
#             if state == ProcessState.Stopped:
#                 try:
#                     on_state_change()
#                     if cont:
#                         debugger.exec_continue()
#                 except Exception as exc:
#                     test_exception.append(traceback.format_exc(exc))
#                     debugger.quit_program()
# 
#         debugger.on_process_state_changed.subscribe(on_stop)
# 
#     assert debugger.launch(startup_info)
# 
#     if wait:
#         debugger.wait_for_exit()
# 
#     if len(test_exception) > 0:
#         pytest.fail(test_exception[0], pytrace=False)


import os
import time
from tests.conftest import AsyncState, setup_debugger
# -*- coding: utf-8 -*-



TEST_FILE = "test_execution"


def make_location(line):
    return (os.path.abspath("src/{}.cpp".format(TEST_FILE)), line)


def test_step_over(debugger):
    state = AsyncState()

    def test_step_over_cb():
        if state.state == 0:
            state.inc()
            debugger.exec_step_over()
        else:
            assert debugger.file_manager.get_current_location() ==\
                make_location(12)
            debugger.quit_program()


# Path: tests/conftest.py
# class AsyncState(object):
#     def __init__(self):
#         self.state = 0
# 
#     def inc(self):
#         self.state += 1
# 
# def setup_debugger(debugger, binary, lines, on_state_change=None,
#                    startup_info=None, cont=True, wait=True):
#     assert debugger.load_binary("src/{}".format(binary))
# 
#     test_exception = []
# 
#     if not isinstance(lines, Iterable):
#         lines = [lines]
# 
#     for line in lines:
#         assert debugger.breakpoint_manager.add_breakpoint(
#             "src/{}.cpp".format(binary), line)
# 
#     if on_state_change:
#         def on_stop(state, data):
#             if state == ProcessState.Stopped:
#                 try:
#                     on_state_change()
#                     if cont:
#                         debugger.exec_continue()
#                 except Exception as exc:
#                     test_exception.append(traceback.format_exc(exc))
#                     debugger.quit_program()
# 
#         debugger.on_process_state_changed.subscribe(on_stop)
# 
#     assert debugger.launch(startup_info)
# 
#     if wait:
#         debugger.wait_for_exit()
# 
#     if len(test_exception) > 0:
#         pytest.fail(test_exception[0], pytrace=False)


# Path: tests/test_mi_execution.py
import os
import time
from tests.conftest import AsyncState, setup_debugger

# -*- coding: utf-8 -*-



TEST_FILE = "test_execution"


def make_location(line):
    return (os.path.abspath("src/{}.cpp".format(TEST_FILE)), line)


def test_step_over(debugger):
    state = AsyncState()

    def test_step_over_cb():
        if state.state == 0:
            state.inc()
            debugger.exec_step_over()
        else:
            assert debugger.file_manager.get_current_location() ==\
                make_location(12)
            debugger.quit_program()


    setup_debugger(debugger, TEST_FILE, 11, test_step_over_cb, cont=False)