def expect_cpp_code_success(tmppy_source, module_ir2, module_ir1, cxx_source):
    '\n    Tests that the given source compiles and runs successfully.\n\n    :param source_code: The C++ source code. This will be dedented.\n    '
    if ('main(' not in cxx_source):
        cxx_source += textwrap.dedent('\n            int main() {\n            }\n            ')
    source_file_name = _create_temporary_file(cxx_source, file_name_suffix='.cpp')
    executable_suffix = {'posix': '', 'nt': '.exe'}[os.name]
    output_file_name = _create_temporary_file('', executable_suffix)
    e = None
    try:
        compiler.compile_and_link(source=source_file_name, include_dirs=[config.MPYL_INCLUDE_DIR], output_file_name=output_file_name, args=[])
    except CommandFailedException as e1:
        e = e1
    if e:
        pytest.fail(textwrap.dedent('                The generated C++ source did not compile.\n                Compiler command line: {compiler_command}\n                Error message was:\n                {error_message}\n                \n                TMPPy source:\n                {tmppy_source}\n                \n                TMPPy IR2:\n                {tmppy_ir2}\n                \n                TMPPy IR1:\n                {tmppy_ir1}\n                \n                C++ source:\n                {cxx_source}\n                ').format(compiler_command=e.command, tmppy_source=add_line_numbers(tmppy_source), tmppy_ir2=str(module_ir2), tmppy_ir1=str(module_ir1), cxx_source=add_line_numbers(cxx_source), error_message=_cap_to_lines(e.stderr, 40)), pytrace=False)
    try:
        run_compiled_executable(output_file_name)
    except CommandFailedException as e1:
        e = e1
    if e:
        pytest.fail(textwrap.dedent('                The generated C++ executable did not run successfully.\n                stderr was:\n                {error_message}\n\n                TMPPy source:\n                {tmppy_source}\n                \n                C++ source:\n                {cxx_source}\n                ').format(tmppy_source=add_line_numbers(tmppy_source), cxx_source=add_line_numbers(cxx_source), error_message=_cap_to_lines(e.stderr, 40)), pytrace=False)
    try_remove_temporary_file(source_file_name)
    try_remove_temporary_file(output_file_name)
Tests that the given source compiles and runs successfully.

:param source_code: The C++ source code. This will be dedented.
def expect_cpp_code_success(tmppy_source, module_ir2, module_ir1, cxx_source):
    '\n    Tests that the given source compiles and runs successfully.\n\n    :param source_code: The C++ source code. This will be dedented.\n    '
    if ('main(' not in cxx_source):
        cxx_source += textwrap.dedent('\n            int main() {\n            }\n            ')
    source_file_name = _create_temporary_file(cxx_source, file_name_suffix='.cpp')
    executable_suffix = {'posix': , 'nt': '.exe'}[os.name]
    output_file_name = _create_temporary_file(, executable_suffix)
    e = None
    try:
        compiler.compile_and_link(source=source_file_name, include_dirs=[config.MPYL_INCLUDE_DIR], output_file_name=output_file_name, args=[])
    except CommandFailedException as e1:
        e = e1
    if e:
        pytest.fail(textwrap.dedent('                The generated C++ source did not compile.\n                Compiler command line: {compiler_command}\n                Error message was:\n                {error_message}\n                \n                TMPPy source:\n                {tmppy_source}\n                \n                TMPPy IR2:\n                {tmppy_ir2}\n                \n                TMPPy IR1:\n                {tmppy_ir1}\n                \n                C++ source:\n                {cxx_source}\n                ').format(compiler_command=e.command, tmppy_source=add_line_numbers(tmppy_source), tmppy_ir2=str(module_ir2), tmppy_ir1=str(module_ir1), cxx_source=add_line_numbers(cxx_source), error_message=_cap_to_lines(e.stderr, 40)), pytrace=False)
    try:
        run_compiled_executable(output_file_name)
    except CommandFailedException as e1:
        e = e1
    if e:
        pytest.fail(textwrap.dedent('                The generated C++ executable did not run successfully.\n                stderr was:\n                {error_message}\n\n                TMPPy source:\n                {tmppy_source}\n                \n                C++ source:\n                {cxx_source}\n                ').format(tmppy_source=add_line_numbers(tmppy_source), cxx_source=add_line_numbers(cxx_source), error_message=_cap_to_lines(e.stderr, 40)), pytrace=False)
    try_remove_temporary_file(source_file_name)
    try_remove_temporary_file(output_file_name)